404toArchive

Redirects from a 404 page to an archive backup when possible

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);
})();