-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathindex.html
More file actions
105 lines (97 loc) · 2.82 KB
/
index.html
File metadata and controls
105 lines (97 loc) · 2.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
<html>
<head>
<title>Total tweets</title>
<style type="text/css">
/*
input {
float: left;
clear: both;
}
*/
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var getPage = new RegExp( /page=([^&]+)/ );
var url = "http://search.twitter.com/search.json?q=";
var search, page, pageTotal, tweets, loading;
var beforeCounter = "<b>";
var afterCounter = "</b>";
var totalTweets = 0;
function getTweets(search, page, pageTotal) {
$.getJSON( url + search + '&page=' + page + '&callback=?',
function(data) {
if( data.results.length != 0 && page != pageTotal ) {
$('#pagesDone span').html(page);
getData(data);
}
else {
showTotal();
}
}
);
}
function showTotal() {
$('#totalTweets span').html(beforeCounter + totalTweets + afterCounter);
$('#pagesDone span').html('0');
totalTweets = 0;
loading = false;
}
function getData(data) {
tweets = data.results;
totalTweets += tweets.length;
nextPage = getPage.exec(data.next_page);
if( nextPage == null ) {
showTotal();
return;
}
nextPage = nextPage[1];
getTweets(search, nextPage, pageTotal);
}
function submitTerms() {
$('#totalTweets span').html('');
$('#pagesDone span').html('0');
search = encodeURIComponent($('#query').prop('value'));
page = $('#startPage').prop('value');
pageTotal = $('#pageTotal').prop('value');
if( search == '' ) {
alert('Please enter search query');
return;
}
if( page == 0 ) {
alert('0 not allowed as start page');
return;
}
loading = true;
getTweets(search, page, pageTotal);
}
function status() {
if( loading ) $('#loading,#pagesDone').show();
else $('#loading,#pagesDone').hide();
}
$(function() {
loading = false;
setInterval(status, 10);
});
</script>
</head>
<body>
<h1>Get your twitter counts here!</h1>
<form action="" method="get" onsubmit="submitTerms(); return false;">
<label for="query">Search for: </label>
<input id="query" name="query" type="text" />
<br />
<label for="startPage">Start on what page (must be greater than 1) </label>
<input id="startPage" name="startPage" type="text" value="1" />
<br />
<label for="pageTotal">How many pages (0 to search until no more results) </label>
<input id="pageTotal" name="pageTotal" type="text" value="0" />
<input id="submit" name="submit" type="submit" value="Go" />
<span>or press enter</span>
</form>
<div id="totalTweets">Total tweets: <span></span></div>
<br />
<div id="loading" style="display:none;">Loading!</div>
<div id="pagesDone" style="display:none;">Pages done: <span></span></div>
<span style="display:none;">Do Electric Cars Pollute More Than Their Gasoline Counterparts</span>
</body>
</html>