Created
July 28, 2015 08:01
-
-
Save BrynM/74a47fa72e832ebfb44a to your computer and use it in GitHub Desktop.
Get total links on a reddit search page (may need to load multiple pages with something like RES)
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
// get the links on the search page for "author:username" limited to the sub | |
var $links = $('.search-result-header > a'); | |
// a place to store some text | |
var mark = '\n'; | |
// loop through the links | |
for(var i = 0; i < $links.length; i++) { | |
// jquery-ify | |
var $link = $($links[i]); | |
// get the URL for the link | |
var url = $link.attr('href'); | |
// get the title for the link | |
var title = $link.text(); | |
// append a line of markdown with a number, the title and a cleaned up link | |
mark += parseInt(i+1, 10)+'. ['+title+']('+url.replace(/(^[^:]+:\/\/[^/]+|\?.*$)/g, '')+')\n'; | |
} | |
// append an extra newline | |
mark += '\n'; | |
// spit out the result | |
console.log(mark); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment