Skip to content

Instantly share code, notes, and snippets.

@chadlavi
Created February 12, 2018 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadlavi/d4e0cf8af2d4f40bd0704fa61138acf0 to your computer and use it in GitHub Desktop.
Save chadlavi/d4e0cf8af2d4f40bd0704fa61138acf0 to your computer and use it in GitHub Desktop.
// ==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