OoCites Missing Resource Fixer

Attempts to fix missing resources on OoCities by drawing from Wayback Machine

目前为 2016-05-06 提交的版本。查看 最新版本

// ==UserScript==
// @name          OoCites Missing Resource Fixer
// @namespace     DoomTay
// @description   Attempts to fix missing resources on OoCities by drawing from Wayback Machine
// @include       http://www.oocities.org/*
// @version       1.0.0
// @grant         GM_xmlhttpRequest

// ==/UserScript==

var pics = document.images;
var timestamp;
var toGeocities = window.location.href.replace("oocities.org","geocities.com");

GM_xmlhttpRequest({
	url: "http://web.archive.org/web/20091026194848/" + toGeocities.substring(0,toGeocities.indexOf("?")),
	method: "GET",
	onload: function(response) {
		if(response.status == 200 && response.responseHeaders.contains("X-Archive-Orig-last-modified"))
		{
			function zeroPad(str,len) {
				return "0".repeat(len - str.toString().length) + str.toString();
			}

			function dateToTimestamp(date) {
				return date.getFullYear() +
					zeroPad(date.getMonth()+1,2) +
					zeroPad(date.getDay()+1,2) +
					zeroPad(date.getHours(),2) +
					zeroPad(date.getMinutes(),2) +
					zeroPad(date.getSeconds(),2);
			}

			var headers = response.responseHeaders;
			var lastModified = new Date(headers.substring(headers.indexOf("X-Archive-Orig-last-modified: ") + 30,headers.indexOf("\n",headers.indexOf("X-Archive-Orig-last-modified: "))));
			timestamp = dateToTimestamp(lastModified);
		}
		else timestamp = "20091026194848";
		
		console.log(timestamp);
							
		for(var i = 0; i < pics.length; i++)
		{
			evaluateImage(pics[i]);
		}
	}
});

function evaluateImage(pic)
{
	GM_xmlhttpRequest({
		url: pic.src,
		method: "GET",
		onload: function(response) {
			if(response.status == 404)
			{
				GM_xmlhttpRequest({
					url: "http://web.archive.org/web/" + timestamp + "/" + pic.src.replace(/oocities.(?:org|com)/,"geocities.com"),
					method: "HEAD",
					onload: function(response) {
						if(response.status == 200) pic.src = this.url;
					}
				});
			}
			else if(response.responseText.contains("The document has moved"))
			{
				GM_xmlhttpRequest({
					url: "http://web.archive.org/web/" + timestamp + "/" + new DOMParser().parseFromString(response.responseText, "text/html").links[0].href,
					method: "HEAD",
					onload: function(response) {
						if(response.status == 200) pic.src = this.url;
					}
				});
			}
		}
	});
}

QingJ © 2025

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