Skip to content

Instantly share code, notes, and snippets.

@haochi
Created October 14, 2012 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haochi/3887409 to your computer and use it in GitHub Desktop.
Save haochi/3887409 to your computer and use it in GitHub Desktop.
Reddit Search
(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