From e8ef799cf5293aa19bebd7315596014e77037a57 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 6 Dec 2010 13:59:33 -0700 Subject: add per-site-settings example configuration with pipermail navigation userscript --- examples/data/scripts/pipermail.js | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 examples/data/scripts/pipermail.js (limited to 'examples/data/scripts/pipermail.js') diff --git a/examples/data/scripts/pipermail.js b/examples/data/scripts/pipermail.js new file mode 100644 index 0000000..5ec4aa4 --- /dev/null +++ b/examples/data/scripts/pipermail.js @@ -0,0 +1,71 @@ +// this is a userscript inspired by "Pipermail Navigation Links" by Michael +// Stone . + +// it adds previous month/next month navigation links in pipermail mailing +// list archives. + +// we wrap the whole thing in a function (that gets called immediately) so +// that this script doesn't interfere with any javascript in the page. +(function() { + +// figure out what page we're looking at right now +var urlparts = document.location.toString().split("/"); +var currView = urlparts[urlparts.length-1].split("#")[0]; +var currDate = urlparts[urlparts.length-2].split("-"); + +// figure out the URLs to the next month and previous month +var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', + 'August', 'September', 'October', 'November', 'December' ]; + +var thisMonth = currDate[1]; +var prevMonth; +var nextMonth; + +var thisYear = currDate[0]; +var prevYear = thisYear; +var nextYear = thisYear; + +if(thisMonth == 'January') { + prevMonth = "December"; + nextMonth = "February"; + prevYear = parseInt(thisYear) - 1; +} else if(thisMonth == 'December') { + prevMonth = "November"; + nextMonth = "January"; + nextYear = parseInt(thisYear) + 1; +} else { + var monthNum = months.indexOf(thisMonth); + prevMonth = months[monthNum - 1]; + nextMonth = months[monthNum + 1]; +} + +var prevHref = "../" + prevYear + "-" + prevMonth + "/" + currView; +var nextHref = "../" + nextYear + "-" + nextMonth + "/" + currView; + +// find the navigation header and footer +var selector = "a[href='date.html#start']"; + +// if we're on a "date" page then the date link isn't displayed +if(currView == "date.html") + selector = "a[href='author.html#start']"; + +var navLinks = document.querySelectorAll(selector); + +// append the prev/next links to the navigation header and footer +for(var i = 0; i < navLinks.length; i++) { + var victim = navLinks[i].parentNode; + + var prevEl = document.createElement("a"); + prevEl.textContent = "[ prev month ]"; + prevEl.href = prevHref; + + var nextEl = document.createElement("a"); + nextEl.textContent = "[ next month ]"; + nextEl.href = nextHref; + + victim.appendChild(prevEl); + victim.appendChild(document.createTextNode(" ")); + victim.appendChild(nextEl); +} + +})(); -- cgit v1.2.3