-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscreen.js
More file actions
executable file
·96 lines (83 loc) · 2.66 KB
/
screen.js
File metadata and controls
executable file
·96 lines (83 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function () {
var screenWidth = function () { return Math.max(document.documentElement.clientWidth, document.body.clientWidth); },
screenHeight = function () { return Math.max(document.documentElement.clientHeight, document.body.clientHeight); },
settings = {
prefix : '$ ',
max : 50
}, lines = [], sp = $('<span class="sp" />');
function rand(l, u) {
return Math.floor((Math.random() * (u-l+1))+l);
}
function resizeBody() {
$(document.body).css({
width : screenWidth(),
height : screenHeight()
});
}
function println(str) {
lines.push(str);
}
function getWeibo() {
$.getJSON('./proxy.php', function (comments) {
if (comments && comments.length > 0) {
for (var i = 0; i < comments.length; i ++) {
var c = comments[i];
println(c);
}
}
});
}
setInterval(function () {
sp.toggleClass('hide');
}, 500);
function strWalk() {
var str, state = 0, el, i, j;
var interval = setInterval(function () {
switch (state) {
case 0:
// stand by
str = lines.shift();
if (!!str) {
if ($('.str').length > settings.max) {
$('.str:first').remove();
}
el = $('<div class="str" />').appendTo(document.body);
state = 1;
i = 0;
}
break;
case 1:
// print
el.html('<span class="head">' + settings.prefix + '</span>' + str.text.substring(0, i)).append(sp);
document.body.scrollTop = document.body.scrollHeight;
if (i >= str.text.length) {
state = 2;
j = 0;
}
i ++;
break;
case 2:
if (j >= 150) {
state = 0;
}
j ++;
break;
default:
break;
}
i ++;
}, 10);
}
$(document).ready(function () {
resizeBody();
strWalk();
$(window).resize(resizeBody);
getWeibo();
setInterval(function () {
if (lines.length > 50) {
return;
}
getWeibo();
}, 30000);
});
})();