forked from CooperUnion/cooper-union-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrap001.html
112 lines (78 loc) · 2.56 KB
/
scrap001.html
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
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="scrap001.css">
<script>
var tweets;
var rpp = 1;
var lastTweetID;
var temp = "";
$(document).ready(function(){
var scheduledQuery = setInterval(function () {
var searchTerm = document.getElementById("form").searchTerm.value;
console.log(searchTerm);
if(temp !== "" && temp !== searchTerm) {
$("<div id='searchbreak'><img src='titlestar.jpg' id='imgbreak'><img src='titlestar02.jpg' id='imgbreak'></div>").prependTo("#tweets");
};
temp=searchTerm;
getTweets(searchTerm, rpp, function() {
console.log(lastTweetID, tweets[0].id_str);
if(lastTweetID !== tweets[0].id_str) {
displayTweets(tweets);
}
lastTweetID = tweets[0].id_str;
console.log("the fancy callback happened", tweets);
});
}, 5000);
var displayTweets = function(input){
$.each(input, function(index, tweet) {
console.log("in each loop function: " + tweet);
var tweetHTML = "<div class='tweet'"+index+" id='" + tweet.id_str + "'>" + tweet.text + "</div>";
$(tweetHTML).prependTo("#tweets");
});
};
var getTweets = function(searchTerm, rpp, callback) {
//$('.numbering').append('<img class="return" src="Right_Arrow_Icon.jpg"/><img class="bird" src="bird_blue_32.png"/><br><br>');
var searchUrl = "http://search.twitter.com/search.json?q=" + searchTerm + "&rpp=" + rpp;
console.log("Search url: "+searchUrl);
$.ajax({
url: searchUrl,
dataType:'jsonp',
success:function(response) {
console.log('# of responses: ' + response.results.length);
tweets = response.results;
console.log('Tweet= ' + tweets);
if(typeof(callback) === "function") {
callback(response);
console.log("callback occuring");
}
},
error:function() {
alert('Error: does not compute.');
}
});
};
$('#button').on("click",function () {
scheduledQuery();
});
});
</script>
</head>
<body>
<h1>Heading<br></h1>
<p id="searchBar">
<form id="form">Search: <input type="text" name="searchTerm"></form>
<button id="button">Search</button>
</p>
<div id="container">
Container
<div id="tweets">
This is the first line.<br>
</div>
<div id="popularwords">
pop
</div>
</div>
</body>
</html>