-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
253 lines (213 loc) · 8.82 KB
/
index.html
File metadata and controls
253 lines (213 loc) · 8.82 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tweet Playback</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<link href="http://d3nu01el40zolk.cloudfront.net/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"/>
</head>
<style>
.content { background-color: #fff; }
.tweet { padding: 5px; margin-top: 10px; }
.tweet img { padding-left: 10px; }
.tweet h4, .tweet h5 { margin: 0; display: inline; }
.tweet h5 { padding-left: 10px; }
.tweet .tweet-footer { display: block; margin-top: 2px; color: #d3d3d3; }
.hidden { display: none; }
.search-query { margin-right: 5px; }
#loading { margin-left: 2px; }
#ads { margin-top: 20px; }
#ads iframe { margin-bottom: 10px; }
.form-search p#help-text { margin: 2px 0 0 15px; font-style:italic; font-size: 100%; }
.form-search { margin-bottom: 15px;}
</style>
<script id="tweetTemplate" type="text/x-jquery-tmpl">
<div class="tweet row">
<div class="span1"><img src="${profile_image_url}"></div>
<div class="span5">
<h4>${from_user_name}</h4><h5>{{html from_user}}</h5>
<p>{{html text}}
<span class="tweet-footer">${created_at}</span></p>
</div>
</div>
</script>
<script type="text/javascript">
var baseURL = 'http://search.twitter.com/search.json';
var rawTweets = new Array();
var timedTweets = new Array();
var displayInterval;
var displayIntervalWait = 1000;
var timerMultiplier = 1;
var displaySeconds = 0;
var displayTimeMoment;
var displayTimeMomentDuration;
var isPaused = false;
var lastTime = 0;
String.prototype.parseURL = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
return '<a href="' + url + '" target="_blank">' + url + '</a>';
});
};
String.prototype.parseUsername = function() {
return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
var username = u.replace("@","")
return '<a href="https://twitter.com/' + username + '" target="_blank">' + u + '</a>';
});
};
String.prototype.parseHashtag = function() {
return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {
var tag = t.replace("#","%23")
return '<a href="http://search.twitter.com/search?q=' + tag + '" target="_blank">' + t + '</a>';
});
};
$(document).ready(function() {
processQueryString();
displayTimeMomentDuration = moment.duration(1000, 'milliseconds');
$('#search-form').submit(function() {
searchInitiated();
return false;
});
$('#play-pause').click(function() {
$(this).children(":first").removeClass('icon-' + (isPaused ? 'play' : 'pause'));
$(this).children(":first").addClass('icon-' + (isPaused ? 'pause' : 'play'));
if(isPaused) {
displayInterval = setInterval(showTweets, displayIntervalWait);
} else {
clearInterval(displayInterval);
}
isPaused = !isPaused;
});
$('#normal-speed').click(function() {
if(isPaused) { return; }
displayIntervalWait = 1000;
timerMultiplier = 1;
clearInterval(displayInterval);
displayInterval = setInterval(showTweets, displayIntervalWait);
});
$('#faster-speed').click(function() {
if(isPaused) { return; }
displayIntervalWait = displayIntervalWait / 10;
if(displayIntervalWait < 1) {
timerMultiplier *= 2;
}
clearInterval(displayInterval);
displayInterval = setInterval(showTweets, displayIntervalWait);
});
});
function searchInitiated() {
window.location = '/?q=' + encodeURIComponent($('#query').val());
}
function processQueryString() {
var q = getParameterByName('q');
if(q) {
$('#loading').show();
$('#query').val(decodeURIComponent(q));
getData(baseURL + '?q=' + q + '&rpp=100&lang=en');
}
}
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null) {
return "";
} else {
return results[1].replace(/\+/g, " ");
}
}
function showTweets() {
if(lastTime > timedTweets.length) {
return;
}
$('#clock').text(displayTimeMoment.format('MMMM Do YYYY, h:mm:ss a'));
var tweets = timedTweets.slice(lastTime, displaySeconds);
tweets = tweets.filter(function(value) { return value !== undefined });
lastTime = displaySeconds;
if(tweets.length > 0) {
$.each(tweets, function(key, val) {
$('#tweetTemplate').tmpl(val).prependTo('#tweets');
});
}
displaySeconds += timerMultiplier;
displayTimeMoment.add('s', timerMultiplier);
}
function getData(q) {
$('#loading').append('.');
fetchData(q, function() {
rawTweets.sort(function(a,b) { return a.id - b.id });
var startTime = new Date(rawTweets[0].created_at);
displayTimeMoment = moment(startTime);
$.each(rawTweets, function(key, val) {
var currentTime = new Date(val.created_at);
val.created_at = moment(currentTime).format('MMMM Do YYYY, h:mm:ss a');
val.text = val.text.parseURL().parseUsername().parseHashtag();
val.from_user = '<a href="https://twitter.com/' + val.from_user + '" target="_blank">@' + val.from_user + '</a>';
timedTweets[((currentTime - startTime) / 1000)] = val;
});
rawTweets = new Array();
$('#loading').hide();
displayInterval = setInterval(showTweets, displayIntervalWait);
setTimeout(function() { $('.btn-group').show(); $('#ads').show(); }, displayIntervalWait);
});
}
function fetchData(q, callback) {
$.ajax({
url: q,
dataType: 'jsonp',
}).done(function(data) {
$.each(data.results, function(key, val) {
rawTweets.push(val);
});
// Max API limit: 1500 tweets. Boo.
if(data.next_page && rawTweets.length < 1400) {
getData(baseURL + data.next_page, callback);
}
else {
callback();
}
});
}
</script>
<body>
<div class="container">
<div class="page-header">
<h1>Tweet Playback <small>DVR for Twitter</small></h1>
</div>
<div class="span11">
<form class="form-search" id="search-form">
<input type="text" id="query" style="width:80%" class="search-query" /><button class="btn" type="submit" id="query-submit">Search</button>
<p id="help-text">Enter a search phrase using <a href="https://support.twitter.com/articles/71577-how-to-use-advanced-twitter-search" target="_blank">Twitter's search syntax</a>.<br />For example, <a href="/?q=from%3Aaimeemann+OR+from%3Apattonoswalt+OR+from%3Acampsucks+OR+from%3AMPenn+%23lizanddick">from:aimeemann OR from:pattonoswalt OR from:campsucks OR from:MPenn #lizanddick</a></p>
</form>
</div>
<div class="span7 content">
<h4 id="loading" class="hidden">Loading</h4>
<div id="tweets"></div>
</div>
<div class="span4">
<h4 id="clock"></h4>
<div class="btn-group hidden">
<a class="btn" title="Play/Pause" id="play-pause"><i class="icon-pause"></i></a>
<a class="btn" title="Normal Speed" id="normal-speed"><i class="icon-minus"></i></a>
<a class="btn" title="Speed Up!" id="faster-speed"><i class="icon-plus"></i></a>
</div>
<div id="ads" class="hidden">
<iframe src="http://rcm.amazon.com/e/cm?t=tplayback-20&o=1&p=20&l=ur1&category=cybermonday&banner=1AJJX0P8WRXFPFDSBFG2&f=ifr" width="120" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
</div>
</div>
</div>
<script src="http://d3nu01el40zolk.cloudfront.net/js/moment.min.js"></script>
<script src="http://d3nu01el40zolk.cloudfront.net/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3244073-10']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>