Created
October 14, 2012 04:59
-
-
Save haochi/3887409 to your computer and use it in GitHub Desktop.
Reddit Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
function reddit_search(needle, subreddit, next){ | |
$.ajax({ | |
url: 'http://www.reddit.com/r/'+subreddit+'.json', | |
dataType: 'json', | |
data: {after: next}, | |
success: function(r){ | |
$.each(r.data.children, function(i, thread){ | |
var t = thread.data; | |
if(t.title.match(needle) || t.selftext.match(needle)){ | |
console.log(t.title, "http://reddit.com"+t.permalink); | |
} | |
}); | |
if(r.data.after !== null){ | |
setTimeout(function(){ | |
reddit_search(needle, subreddit, r.data.after); | |
}, 2000); | |
}else{ | |
console.log('Reached the end of the Internet!'); | |
} | |
} | |
}); | |
}; | |
reddit_search(new RegExp(prompt("Enter RegExp search term:"), "im"), prompt("Enter subreddit to search in:")); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment