-
-
Save ishan-marikar/5e30d9aa1fe8ea6f2e36d1897b9b370b to your computer and use it in GitHub Desktop.
Show an random image from a subreddit
This file contains hidden or 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
| // Place in your body: | |
| // <div id="image"></div> | |
| $(document).ready( function() { | |
| var subreddit = 'VillagePorn'; // Your Subreddit without /r/ | |
| var aRandomNum = Math.floor((Math.random() * 25) + 1); // A random number - range 25 | |
| $.getJSON('http://www.reddit.com/r/'+subreddit+'.json?jsonp=?&show=all&limit=25', function(data) { | |
| $.each(data.data.children, function(i,item){ | |
| if (i == aRandomNum) { | |
| $("<img/>").attr("src", item.data.url).appendTo("#image"); | |
| return false; | |
| } | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment