Created
October 26, 2017 20:40
-
-
Save ttscoff/39981f14d4b8329cd6fb9a08bba0471b to your computer and use it in GitHub Desktop.
Bookmarklet to scrape links from a 5by5 episode page
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
// generates a Markdown list of all the show links on a 5by5 episode page, | |
// autoselects the result for copying and provides next/prev navigation | |
// only designed for 5by5, which already has jQuery loaded and matches | |
// the regex. Customize as needed for other uses. | |
// Brett Terpstra 2013 | |
var output = "\n\n### Episode "+window.location.href.replace(/.*\/(\d)/,"$1")+"\n\n"; | |
output += "[Show Link]("+window.location.href+")\n\n"; | |
$('#episode_links').find('a').each(function(){ output += "* ["+$(this).text()+"]("+$(this).attr('href')+")\n"; }); | |
// create next/prev links (no boundry checking) | |
var ep = parseInt(window.location.href.match(/(\d+)$/)[0],10); | |
var nextLink = $('<a>').attr('href',window.location.href.replace(/\d+$/,ep + 1)) | |
.text('Next Episode') | |
.css({display:'block',padding:'10px',textAlign:'center',backgroundColor:'#ddd','float':'right'}); | |
var prevLink = $('<a>').attr('href',window.location.href.replace(/\d+$/,ep - 1)) | |
.text('Previous Episode') | |
.css({display:'block',padding:'10px',textAlign:'center',backgroundColor:'#ddd','float':'left'}); | |
// generate the overlay element and add text and links | |
$('<div>').css({ | |
position:'fixed', | |
top: '0',left:'0',right:'0',bottom:'0', | |
overflow:'auto', | |
backgroundColor:'#efefef', | |
color:'#333', | |
zIndex:'99999' | |
}).append($('<pre id="eplinkoutput">').css('padding','20px').text(output)).append($('<div>').append(prevLink).append(nextLink)).appendTo('body'); | |
// select the text in the pre element | |
var doc = document, | |
text = doc.getElementById('eplinkoutput'), | |
range, selection; | |
if (doc.body.createTextRange) { | |
range = doc.body.createTextRange(); | |
range.moveToElementText(text); | |
range.select(); | |
} else if (window.getSelection) { | |
selection = window.getSelection(); | |
range = doc.createRange(); | |
range.selectNodeContents(text); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can yu show me how this script work