Writing.com's Archive Navigation Enhancement

A script that I create to better navigate writing archived

Per 20-03-2020. Zie de nieuwste versie.

	// ==UserScript==
// @name     Writing.com's Archive Navigation Enhancement
// @version         11
// @description A script that I create to better navigate writing archived
// @include  http*://web.archive.org/web/*writing.com*
// @include  http*://web.archive.org/web/*writingbackupproject*
// @include  http*://web.archive.org/web/*writingbackup.000webhostapp*

// @namespace https://greasyfork.org/users/218817
// ==/UserScript==


//Prevents Adblock Redirect and annoyances

window.onload = function() {
	var d = document;	// shorthand
	var scripts = d.getElementsByTagName('script');
	for(var i = 0; i < scripts.count; i++) {
		if(scripts[i].src.indexOf('dataStore.js') != -1) {
			scripts[i].src = '';
		}
	}
}


window.onload = function() {
	var d = document;	// shorthand
	var scripts = d.getElementsByTagName('script');
	for(var i = 0; i < scripts.count; i++) {
		if(scripts[i].src.indexOf('is.js') != -1) {
			scripts[i].src = '';
		}
	}
}


window.onload = function() {
	var d = document;	// shorthand
	var scripts = d.getElementsByTagName('script');
	for(var i = 0; i < scripts.count; i++) {
		if(scripts[i].src.indexOf('optionsadvert.js') != -1) {
			scripts[i].src = '';
		}
	}
}


// Block Images and Bullshit
var tags = document.getElementsByTagName('img');

// This loops over all of the <img> tags.
for (var i = 0; i < tags.length; i++) {

  // This replaces the src attribute of the tag with the modified one
  tags[i].src = tags[i].src.replace('https://cdn.000webhost.com/000webhost/logo/footer-powered-by-000webhost-white2.png', 'https://i.imgur.com/S3jkJhG.gif');
}


var images = document.getElementsByTagName ("img");
var x=0;
while(x<images.length)
{
if(images[x].src == "http://web.archive.org/web/20190713212940im_/https://i.imgur.com/MY7IEW1.gif")
{
images[x].src = "https://web.archive.org/web/20190714031110/https://i.imgur.com/S3jkJhG.gif";
}
x=x+1;
}

// Fix link redirection problem

var links,thisLink;
links = document.evaluate("//a[@href]",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

for (var i=0;i<links.snapshotLength;i++) {
    var thisLink = links.snapshotItem(i);

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/(.*)https://www.writing.com/main/redirect(.*)&redirect_url=(.*?)'),
                                      'http://web.archive.org/web/$4');

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/200(.*)/item_id/(.*?)-(.*)\/action\/outline'),
                                      'https://archive.org/download/stories_files/stories.zip/$3.html');

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/201[0-7](.*)/item_id/(.*?)-(.*)\/action\/outline'),
                                      'https://archive.org/download/stories_files/stories.zip/$3.html');

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/200(.*)/item_id/(.*?)\/action\/outline'),
                                      'https://archive.org/download/stories_files/stories.zip/$3.html');

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/201[0-7](.*)/item_id/(.*?)\/action\/outline'),
                                      'https://archive.org/download/stories_files/stories.zip/$3.html');

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/201[8-9](.*)/item_id/(.*?)\/action\/outline'),
                                      'https://web.archive.org/web/https://writingbackup.000webhostapp.com/$3.html');

thisLink.href = thisLink.href.replace(RegExp('http(.*)://web.archive.org/web/20[2-9](.*)/item_id/(.*?)\/action\/outline'),
                                      'https://web.archive.org/web/https://writingbackup.000webhostapp.com/$3.html');
}

if (/\/chapter_edit\/view\/chapter_map/.test (location.pathname) ) {
var qLinks  = document.querySelectorAll ("a[href*='map']");

for (var J = qLinks.length - 1;  J >= 0;  --J) {
    var oldHref = qLinks[J].getAttribute ('href');
    var newHref = oldHref.replace (/\map/, "chapter_edit/view/chapter_map");

    //console.log (oldHref + "\n" + newHref);
    qLinks[J].setAttribute ('href', newHref);
}
}

else if (/\/action\/view\/chapter_map/.test (location.pathname) ) {
var qLinks  = document.querySelectorAll ("a[href*='map']");

for (var J = qLinks.length - 1;  J >= 0;  --J) {
    var oldHref = qLinks[J].getAttribute ('href');
    var newHref = oldHref.replace (/\map/, "action/view/chapter_map");

    //console.log (oldHref + "\n" + newHref);
    qLinks[J].setAttribute ('href', newHref);
}
}

if (/\/edit\/view\/chapter_map/.test (location.pathname) ) {
var qLinks  = document.querySelectorAll ("a[href*='map']");

for (var J = qLinks.length - 1;  J >= 0;  --J) {
    var oldHref = qLinks[J].getAttribute ('href');
    var newHref = oldHref.replace (/\map/, "edit/view/chapter_map");

    //console.log (oldHref + "\n" + newHref);
    qLinks[J].setAttribute ('href', newHref);
}
}


//redirect "/action/view/" not found pages to "/edit/view/" found pages and vice-versa

if (/The Wayback Machine has not archived that URL/i.test (document.body.innerHTML) )
{
    if (/\/action\/view\/chapter_map/.test (location.pathname) ) {
    //alert ("This page is being redirect, please wait!");
        window.location = document.URL.replace("/action/view/","/edit/view/")
    }
}

if (/The Wayback Machine has not archived that URL/i.test (document.body.innerHTML) )
{
    if (/\/edit\/view\/chapter_map/.test (location.pathname) ) {
    //alert ("This page is being redirect, please wait!");
        window.location = document.URL.replace("/edit/view/","/action/view/")
    }
}

// Fix font problems that happens during archive


(function() {var css = [
	"#Top_Half_Page_Wrapper_Inner {",
	"    font-size: 13px!important;",
	"}",
	"",
	".norm {",
	"    font-size: 13px!important;",
	"}",
	"",
	"",
	".sblueroll {",
	"    font-size: 13px!important;",
	"}",
	"",
	".skinLinks {",
	"    font-size: 13px!important;",
	"}"
].join("\n");
if (typeof GM_addStyle != "undefined") {
	GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
	PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
	addStyle(css);
} else {
	var node = document.createElement("style");
	node.type = "text/css";
	node.appendChild(document.createTextNode(css));
	var heads = document.getElementsByTagName("head");
	if (heads.length > 0) {
		heads[0].appendChild(node);
	} else {
		// no head yet, stick it whereever
		document.documentElement.appendChild(node);
	}
}
})();