Wayback Machine Favicon Fixer

Attempts to add a favicon to a site crawled by the Wayback Machine in the event one does not come up normally

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          Wayback Machine Favicon Fixer
// @namespace     DoomTay
// @description   Attempts to add a favicon to a site crawled by the Wayback Machine in the event one does not come up normally
// @version       1.3.0
// @include       http://web.archive.org/web/*
// @include       http://wayback.archive.org/web/*
// @include       https://web.archive.org/web/*
// @include       https://wayback.archive.org/web/*
// @exclude       /\*/
// @grant         GM_addElement
// @noframes

// ==/UserScript==

var timestamp = /web\/(\d{1,14})/.exec(window.location.href)[1];

var originalDomain = /.+web\/\d+(?:[a-z][a-z]_)?\/((?:https?:\/\/)?[^\/]+)/.exec(window.location.href)[1];

if(!originalDomain.endsWith("/")) originalDomain = originalDomain + "/";

if(!document.querySelector("link[rel~='icon']") && document.contentType == "text/html") retrieveFavicon();

function retrieveFavicon()
{
	fetch("https://archive.org/wayback/available?url=" + encodeURIComponent(originalDomain + "favicon.ico") + "&timestamp=" + timestamp).then(result => result.json()).then(function(data)
	{
		if(data.archived_snapshots && data.archived_snapshots.closest && data.archived_snapshots.closest.available)
		{
			GM_addElement("link",
						  {type: "image/x-icon",
						  rel: "shortcut icon",
						  href: data.archived_snapshots.closest.url.replace("http:","https:").replace("/ht","mp_/ht")
			});
		}
	})
}