Web Archive Helper

Add options to search or save pages on web.archive.org and archive.today

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Web Archive Helper
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Add options to search or save pages on web.archive.org and archive.today
// @author       maanimis
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_openInTab
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  function showWebArchive(url) {
    GM_openInTab("https://web.archive.org/web/*/" + url, { active: true });
  }

  function saveWebArchive(url) {
    if (confirm("Do you want to save this page to Web Archive?")) {
      let form = document.createElement("form");
      form.method = "POST";
      form.action = "https://web.archive.org/save/";
      form.target = "_blank";

      let inputs = [
        { name: "url", value: url },
        { name: "capture_outlinks", value: "1" },
        { name: "capture_all", value: "on" },
        { name: "capture_screenshot", value: "on" },
      ];

      inputs.forEach((data) => {
        let input = document.createElement("input");
        input.type = "hidden";
        input.name = data.name;
        input.value = data.value;
        form.appendChild(input);
      });

      document.body.appendChild(form);
      form.submit();
      document.body.removeChild(form);
    }
  }

  function showArchiveToday(url) {
    GM_openInTab("https://archive.today/search/?q=" + encodeURIComponent(url), {
      active: true,
    });
  }

  function saveArchiveToday(url) {
    GM_openInTab(
      "https://archive.today/?run=1&url=" + encodeURIComponent(url),
      { active: true }
    );
  }

  function saveInBoth(url) {
    saveWebArchive(url);
    saveArchiveToday(url);
  }

  function searchInBoth(url) {
    showWebArchive(url);
    showArchiveToday(url);
  }

  // Web Archive Commands
  GM_registerMenuCommand("Web Archive: Show this page", function () {
    showWebArchive(window.location.href);
  });

  GM_registerMenuCommand("Web Archive: Save this page", function () {
    saveWebArchive(window.location.href);
  });

  // Archive.today Commands
  GM_registerMenuCommand("Archive.today: Search this page", function () {
    showArchiveToday(window.location.href);
  });

  GM_registerMenuCommand("Archive.today: Save this page", function () {
    saveArchiveToday(window.location.href);
  });

  GM_registerMenuCommand("===============", () => {});

  GM_registerMenuCommand("Save on Both Archives", function () {
    saveInBoth(window.location.href);
  });

  GM_registerMenuCommand("Search on Both Archives", function () {
    searchInBoth(window.location.href);
  });
})();