Website Save Point

Saves and loads website Point in time. Kind of like that one Rick and Morty episode but more nerdy.

  1. // ==UserScript==
  2. // @name Website Save Point
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @author longkidkoolstar
  6. // @icon https://cdn2.iconfinder.com/data/icons/web-design-development-ui-vol-4/96/166-512.png
  7. // @license MIT
  8. // @description Saves and loads website Point in time. Kind of like that one Rick and Morty episode but more nerdy.
  9. // @match *://*/*
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Register the "Save" menu command
  19. GM_registerMenuCommand("Save Data", function() {
  20. // Get the current website URL
  21. var url = window.location.href;
  22. // Get the current website data
  23. var data = {
  24. html: JSON.stringify(document.getElementsByTagName("html")[0].innerHTML),
  25. localStorage: JSON.stringify(localStorage),
  26. sessionStorage: JSON.stringify(sessionStorage)
  27. };
  28.  
  29. // Save the data to the Tampermonkey storage
  30. GM_setValue(url, JSON.stringify(data));
  31.  
  32. // Alert the user that the data has been saved
  33. alert("Data saved for " + url);
  34. });
  35.  
  36. // Register the "Load" menu command
  37. GM_registerMenuCommand("Load Data", function() {
  38. // Get the current website URL
  39. var url = window.location.href;
  40.  
  41. // Get the saved data from the Tampermonkey storage
  42. var savedData = JSON.parse(GM_getValue(url, null));
  43.  
  44. // If there is saved data, replace the current page content and storage data with it
  45. if (savedData) {
  46. var newData = JSON.parse(savedData.html);
  47. document.getElementsByTagName("html")[0].innerHTML = newData;
  48.  
  49. // Restore local storage data
  50. var newLocalStorageData = JSON.parse(savedData.localStorage);
  51. for (var key in newLocalStorageData) {
  52. localStorage.setItem(key, newLocalStorageData[key]);
  53. }
  54.  
  55. // Restore session storage data
  56. var newSessionStorageData = JSON.parse(savedData.sessionStorage);
  57. for (var key in newSessionStorageData) {
  58. sessionStorage.setItem(key, newSessionStorageData[key]);
  59. }
  60.  
  61. // Alert the user that the data has been loaded
  62. alert("Data loaded for " + url);
  63. } else {
  64. // Alert the user that there is no saved data for this website
  65. alert("No saved data for " + url);
  66. }
  67. });
  68. })();

QingJ © 2025

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