Created
February 12, 2018 14:37
-
-
Save chadlavi/d4e0cf8af2d4f40bd0704fa61138acf0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 show titles | |
// @namespace https://gist.github.com/chadlavi/d4e0cf8af2d4f40bd0704fa61138acf0/raw/show-titles.user.js | |
// @downloadURL https://gist.github.com/chadlavi/d4e0cf8af2d4f40bd0704fa61138acf0/raw/show-titles.user.js | |
// @updateURL | |
// @version 1.1 | |
// @description show the titles of older and newer entries | |
// @author Chad Lavimoniere | |
// @include http://6.f*.org/file/view/* | |
// @grant none | |
// ==/UserScript== | |
function oldTitle () { | |
titleOld=strip(this.responseText.match(/.*<h1>.*/g)+''); | |
//console.log(titleOld); | |
x=document.getElementsByClassName("older"); | |
for(var i = 0; i < x.length; i++){ | |
x[i].innerText="‹ older ("+titleOld+")"; | |
}; | |
} | |
function newTitle () { | |
titleNew=strip(this.responseText.match(/.*<h1>.*/g)+''); | |
//console.log(titleNew); | |
y=document.getElementsByClassName("newer"); | |
for(var i = 0; i < y.length; i++){ | |
y[i].innerText="| ("+titleNew+") newer ›"; | |
}; | |
}function strip(html) | |
{ | |
var tmp = document.createElement("DIV"); | |
tmp.innerHTML = html; | |
return tmp.textContent || tmp.innerText; | |
} | |
var oReq = new XMLHttpRequest(); | |
oReq.addEventListener("load", oldTitle); | |
var oReq2 = new XMLHttpRequest(); | |
oReq2.addEventListener("load", newTitle); | |
var thisUrl=document.location+''; | |
thisUrl=thisUrl.substring(0,thisUrl.lastIndexOf("/")).split('#')[0]; | |
var page=parseInt(thisUrl.substring(thisUrl.lastIndexOf("/") +1),10); | |
var oldPage=page-1; | |
var newPage=page+1; | |
var preUrl=thisUrl.substring(0,thisUrl.lastIndexOf("/")+1).split('#')[0]; | |
var oldUrl=preUrl+oldPage; | |
var newUrl=preUrl+newPage; | |
oReq.open("GET", oldUrl); | |
oReq.send(); | |
oReq2.open("GET", newUrl); | |
oReq2.send(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment