Greasy Fork镜像 还支持 简体中文。

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

目前為 2016-01-03 提交的版本,檢視 最新版本

// ==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.5
// @include       http://web.archive.org/web/*
// @include       https://web.archive.org/web/*
// @grant         none

// ==/UserScript==

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

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

//Fix cases of &amp; in the capture graph
if(toolbarNav) fixToolbar();

if(shouldHaveTrailingSlash && !hasTrailingSlash)
{
	if(!document.getElementsByTagName("base")[0])
	{
		var base = document.createElement("base");
		base.href = window.location.href + "/";
		document.head.appendChild(base);
	}
	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;
		//It might be an offsite or absolute reference, which means we don't need to do anything
		//Weird hack to make sure the "revised" images will actually display
		pics[i].src = pics[i].src;
	}
}

var observer = new MutationObserver(function(mutations) {
	mutations.forEach(function(mutation) {
		if(mutation.type == "attributes" && mutation.target == toolbarNav) fixToolbar();
	});    
});

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址