您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Redirects from a 404 page to an archive backup when possible
// ==UserScript== // @name 404toArchive // @namespace https://github.com/aslkeaxn/404toArchive // @version 0.2 // @description Redirects from a 404 page to an archive backup when possible // @author aslkeaxn // @match *://*/* // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net // @grant none // @license MIT // ==/UserScript== /* jshint esversion:8 */ (function () { "use strict"; async function main() { const url = location.href; const res1 = await fetch(url, { method: "HEAD" }); if (res1.status !== 404) return; const encodedUrl = encodeURI(url); const archiveUrl = `https://archive.org/wayback/available?url=${encodedUrl}`; const res2 = await fetch(archiveUrl); const json = await res2.json(); const closestSnapshot = json.archived_snapshots.closest; if (!closestSnapshot || !closestSnapshot.available) return; window.location.replace(closestSnapshot.url); } main().catch(console.error); })();