-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed.js
182 lines (140 loc) · 4.41 KB
/
feed.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
feed.js
Post all the new messages and status updates.
*/
var recent_id = -1;
var running = true;
var dispID;
var spam = false;
var spamID;
var usedNames = [];
// This code will be executed when the page finishes loading
window.addEventListener('load', function(){
//display one tweet every 3000 milliseconds or so
dispID = window.setInterval(disp, 4000);
//do it initially so it doesn't wait
disp();
//i don't actually know why this is here
var ul = document.getElementById('franklr_feed');
var li = document.createElement('li');
li.innerHTML = '<strong>' + "ahhhhhhh~" + '</strong> ';
ul.appendChild(li);
}, false);
function toggleFeed() {
var button = document.getElementById('toggle');
if (running) {
clearInterval(dispID);
button.textContent = "Play";
} else {
dispID = window.setInterval(disp, 4000);
button.textContent = "Pause";
}
running = !running;
}
function spamFeed() {
if (spam !== null) {
spamID = window.setInterval(spamFunction, 1000);
clearInterval(dispID);
} else {
var button = document.getElementById('toggle');
clearInterval(spamID);
button.textContent = "Pause";
dispID = window.setInterval(disp, 4000);
}
}
function disp(){
if (matched_profiles.length === 0 && feed_updates.length === 0) {
return;
}
var ul = document.getElementById('franklr_feed');
var rand_index = Math.floor(Math.random() * matched_profiles.length);
if (rand_index >= 0) {
if (recent_id === rand_index) {
var doublepost = Math.random();
if (doublepost < 0.5) {
rand_index = Math.floor(Math.random() * matched_profiles.length);
}
}
recent_id = rand_index;
//THIRTY IS ENOUGH
while(ul.childNodes.length > 30){
ul.removeChild(ul.lastChild);
}
var timestamp = Date();
var profile = matched_profiles[recent_id];
var header_text = "";
var message_chance = Math.random();
var message_idx = "";
var li = document.createElement('li');
//hack for now because i need to sleep
if (profile.name === 'Brian' && usedNames.indexOf(profile.name) < 0) {
message_chance = 1;
}
if (message_chance < 0.5) {
header_text = "STATUS UPDATE:";
message_idx = "statuses";
li.className = "status";
} else {
header_text = "NEW MESSAGE:";
message_idx = "messages";
li.className = "message";
}
var specify = (profile.name in feed_updates[message_idx] && usedNames.indexOf(profile.name) < 0) ?
profile.name :
"everyone";
if (specify == profile.name) {
usedNames.push(profile.name);
}
var choices = feed_updates[message_idx][specify];
var message = choices[Math.floor(Math.random() * choices.length)];
li.innerHTML = '<img src=img/' + profile.img + '>'
+ '<div id ="right-hold">'
+ '<strong>' + header_text + '</strong> '
+ '<br />'
+ '<strong>' + profile.name + '</strong> '
+ '<br />'
+ message
+ '<br />' + timestamp + '</div>';
ul.insertBefore(li, ul.firstChild);
}
}
function spamFunction() {
if (spam === null) {
return;
}
if (matched_profiles.length === 0 && feed_updates.length === 0) {
return;
}
var ul = document.getElementById('franklr_feed');
//THIRTY IS ENOUGH
while(ul.childNodes.length > 30){
ul.removeChild(ul.lastChild);
}
var timestamp = Date();
var profile = spam;
var header_text = "";
var message_chance = Math.random();
var message_idx = "";
var li = document.createElement('li');
if (message_chance < 0.5) {
header_text = "STATUS UPDATE:";
message_idx = "statuses";
li.className = "status";
} else {
header_text = "NEW MESSAGE:";
message_idx = "messages";
li.className = "message";
}
var specify = "spam";
var choices = feed_updates[message_idx][specify];
var message = choices[Math.floor(Math.random() * choices.length)];
li.innerHTML = '<img src=img/' + profile.img + '>'
+ '<div id ="right-hold">'
+ '<strong>' + header_text + '</strong> '
+ '<br />'
+ '<strong>' + profile.name + '</strong> '
+ '<br />'
+ message
+ '<br />' + timestamp + '</div>';
ul.insertBefore(li, ul.firstChild);
}