|
// 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")+"]("+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); |
|
} |