There are 2 previous versions of this script.
// ==UserScript==
// @name Savage Love Next/Previous
// @namespace http://userscripts.org/users/7405
// @description Adds links to the previous and next articles from Savage Love
// @include http://www.thestranger.com/seattle/SavageLove?oid=*
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==
var thisPage = window.location;
function showLinks(archive) {
function getPage(link) {
return link.href;
}
function getTitle(link) {
return $(link).html();
}
var allDates =
$('ul.savageArchives > li > a[href*=/seattle/SavageLove?oid=]',
archive);
var prevPage = "none", nextPage = "none";
var prevTitle, nextTitle;
for (var i=0; i<allDates.length; i++) {
var thatPage = getPage(allDates[i]);
if (thisPage == thatPage) {
if (i > 0) {
nextPage = getPage(allDates[i-1]);
nextTitle = getTitle(allDates[i-1]);
}
if (i+1 < allDates.length) {
prevPage = getPage(allDates[i+1]);
prevTitle = getTitle(allDates[i+1]);
}
}
}
var prevLink = "", nextLink = "";
if (prevPage != "none") {
prevLink = "<a href=\"" + prevPage + "\">« " + prevTitle + "</a>";
}
if (nextPage != "none") {
nextLink = "<a href=\"" + nextPage + "\">" + nextTitle + " »</a>";
}
$('#savageTextWrap', document).append(
'<div>'
+ ' <div align=left width=50% style=float:left>' + prevLink + '</div>'
+ ' <div align=right width=50%>' + nextLink + '</div>'
+ '</div>');
}
$(document).ready(function(){
$(document.body).append('<iframe id="SLNPArchive" style="display:none;"/>');
$('iframe#SLNPArchive').attr('src',
'http://www.thestranger.com/seattle/SavageLove?archives=all');
$('iframe#SLNPArchive').load(function(){
showLinks($('iframe#SLNPArchive')[0].contentDocument);
});
});
