Wayback Machine Small Bug Fixes

Fixes encoded ampersands on Wayback Machine's captures graph and problems that arise when trailing slashes are missing in an URL

Από την 03/01/2016. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name          Wayback Machine Small Bug Fixes
// @namespace     DoomTay
// @description   Fixes encoded ampersands on Wayback Machine's captures graph and problems that arise when trailing slashes are missing in an URL
// @version       1.1.1
// @include       http://web.archive.org/web/*
// @include       https://web.archive.org/web/*
// @grant         none

// ==/UserScript==

var toolbarNav = document.getElementById("wm-graph-anchor");
var shouldHaveTrailingSlash = window.location.href.lastIndexOf("/") > -1 && window.location.href.lastIndexOf(".") < window.location.href.lastIndexOf("/");
var hasTrailingSlash = window.location.href.lastIndexOf("/") == window.location.href.length - 1;
var pics = document.images;
var links = document.links;
var lastFolder = window.location.href.substring(window.location.href.lastIndexOf("/") + 1);

function fixLink()
{
	while(toolbarNav.href.indexOf("&amp;") > -1) toolbarNav.href = toolbarNav.href.replace("&amp;","&");
}

if(toolbarNav) fixLink();

if(shouldHaveTrailingSlash && !hasTrailingSlash)
{
	for(var l = 0; l < links.length; l++)
	{
		//Skip over stuff related to the Wayback Machine toolbar and data URIs
		if((document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(links[l]))) continue;
		if(links[l].hash) continue;
		if(links[l].href.indexOf(window.location.href) == -1) continue;
		links[l].href = lastFolder + "/" + relativeToAbsolute(links[l].href);
	}
	for(var i = 0; i < pics.length; i++)
	{
		//Skip over stuff related to the Wayback Machine toolbar and data URIs
		if((document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(pics[i])) || pics[i].src.indexOf("data:") > -1) continue;
		pics[i].src = lastFolder + "/" + relativeToAbsolute(pics[i].src);
	}
}

function relativeToAbsolute(url)
{
	return url.substring(url.indexOf(window.location.href) + window.location.href.length - (lastFolder.length - 1));
}

var observer = new MutationObserver(function(mutations) {
	mutations.forEach(function(mutation) {
		if(mutation.type == "attributes") fixLink();
	});    
});

var config = { attributes: true, childList: true, characterData: true, subtree: true, attributeFilter: ["href"] };
observer.observe(toolbarNav, config);