Web Archive Helper

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

  1. // ==UserScript==
  2. // @name Web Archive Helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description Add options to search or save pages on web.archive.org and archive.today
  6. // @author maanimis
  7. // @match *://*/*
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_openInTab
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. function showWebArchive(url) {
  17. GM_openInTab("https://web.archive.org/web/*/" + url, { active: true });
  18. }
  19.  
  20. function saveWebArchive(url) {
  21. if (confirm("Do you want to save this page to Web Archive?")) {
  22. let form = document.createElement("form");
  23. form.method = "POST";
  24. form.action = "https://web.archive.org/save/";
  25. form.target = "_blank";
  26.  
  27. let inputs = [
  28. { name: "url", value: url },
  29. { name: "capture_outlinks", value: "1" },
  30. { name: "capture_all", value: "on" },
  31. { name: "capture_screenshot", value: "on" },
  32. ];
  33.  
  34. inputs.forEach((data) => {
  35. let input = document.createElement("input");
  36. input.type = "hidden";
  37. input.name = data.name;
  38. input.value = data.value;
  39. form.appendChild(input);
  40. });
  41.  
  42. document.body.appendChild(form);
  43. form.submit();
  44. document.body.removeChild(form);
  45. }
  46. }
  47.  
  48. function showArchiveToday(url) {
  49. GM_openInTab("https://archive.today/search/?q=" + encodeURIComponent(url), {
  50. active: true,
  51. });
  52. }
  53.  
  54. function saveArchiveToday(url) {
  55. GM_openInTab(
  56. "https://archive.today/?run=1&url=" + encodeURIComponent(url),
  57. { active: true }
  58. );
  59. }
  60.  
  61. function saveInBoth(url) {
  62. saveWebArchive(url);
  63. saveArchiveToday(url);
  64. }
  65.  
  66. function searchInBoth(url) {
  67. showWebArchive(url);
  68. showArchiveToday(url);
  69. }
  70.  
  71. // Web Archive Commands
  72. GM_registerMenuCommand("Web Archive: Show this page", function () {
  73. showWebArchive(window.location.href);
  74. });
  75.  
  76. GM_registerMenuCommand("Web Archive: Save this page", function () {
  77. saveWebArchive(window.location.href);
  78. });
  79.  
  80. // Archive.today Commands
  81. GM_registerMenuCommand("Archive.today: Search this page", function () {
  82. showArchiveToday(window.location.href);
  83. });
  84.  
  85. GM_registerMenuCommand("Archive.today: Save this page", function () {
  86. saveArchiveToday(window.location.href);
  87. });
  88.  
  89. GM_registerMenuCommand("===============", () => {});
  90.  
  91. GM_registerMenuCommand("Save on Both Archives", function () {
  92. saveInBoth(window.location.href);
  93. });
  94.  
  95. GM_registerMenuCommand("Search on Both Archives", function () {
  96. searchInBoth(window.location.href);
  97. });
  98. })();