-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
54 lines (49 loc) · 1.35 KB
/
index.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
<html>
<head>
<title>Try to say something new</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
<body>
<textarea id="tweet" rows="4" cols="60"></textarea>
<button onclick="didISaidComethingNew()">Did I said something new?</button>
<script type="text/javascript">
function didISaidComethingNew(nextPageUrl){
var phrase = $("#tweet").val();
if(nextPageUrl == null){
nextPageUrl = "http://search.twitter.com/search.json?rpp=100&q=" + encodeURIComponent('"' + phrase + '"')
}
jQuery.ajax({
dataType: "jsonp",
url: nextPageUrl,
success: function(json) {
console.log("success", json)
var re = new RegExp("^" + phrase.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') + "$");
var found = false;
for(var ii = 0; ii < json.results.length; ii++){
var tweet = json.results[ii];
if(re.test(tweet.text)){
displayTweet(tweet);
found = true;
break;
}
}
if(!found){
if(json.next_page != null){
didISaidComethingNew("http://search.twitter.com/search.json" + json.next_page)
} else {
alert("hurray! you are not stupid!");
}
}
},
error: function(xhr, textStatus, errorThrown){
console.log(xhr, textStatus, errorThrown)
}
});
}
function displayTweet(tweet){
console.log("found", tweet);
alert("!!!")
}
</script>
</body>
</html>