Created
August 30, 2016 04:22
-
-
Save mavc/74fae5441e7a1f83048ed2314192b488 to your computer and use it in GitHub Desktop.
Add < Prev and Next > Navigation for RAFO threads.
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
// ==UserScript== | |
// @name Thread.And.Find.Out | |
// @namespace mavc | |
// @description Add < Prev and Next > Navigation for RAFO threads. | |
// @match http://*.readandfindout.com/* | |
// @version 1.0.0 | |
// ==/UserScript== | |
function getNext(t) { | |
// get first child, next sibling, or getNext() of parent. | |
var n; | |
if (!t.classList.contains("thread")) { | |
return null; | |
} | |
else if (n = t.querySelector("div.thread")) { | |
return n; | |
} | |
else if (n = t.nextElementSibling) { | |
return n; | |
} | |
else { | |
return getNext(t.parentNode); | |
} | |
} | |
function rightMost(t) { | |
var n; | |
if ((n = t.lastElementChild) && n.classList.contains("thread")) { | |
return rightMost(n); | |
} | |
return t; | |
} | |
function getPrev(t) { | |
// get rightmost of previous sibling, or parent. | |
var n; | |
if ((n = t.previousElementSibling) && n.classList.contains("thread")) { | |
return rightMost(n); | |
} | |
else { | |
return (n = t.parentNode).classList.contains("thread") ? n : null; | |
} | |
} | |
(function() { | |
var t = document.querySelector("div.thread.current"); | |
if (!t) return; | |
var next = getNext(t), | |
prev = getPrev(t); | |
var footer = document.getElementById("post_footer"); | |
if (prev) { | |
var prevLink = prev.querySelector("a").cloneNode(); | |
prevLink.className = "last"; | |
prevLink.innerHTML = "< Previous post"; | |
footer.insertBefore(prevLink, footer.querySelector("img")); | |
} | |
if (next) { | |
var nextLink = next.querySelector("a").cloneNode(); | |
nextLink.className = "last"; | |
nextLink.innerHTML = "Next post >" | |
footer.appendChild(nextLink); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment