Website Save Point

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Website Save Point
// @namespace    http://tampermonkey.net/
// @version      1
// @author       longkidkoolstar
// @icon         https://cdn2.iconfinder.com/data/icons/web-design-development-ui-vol-4/96/166-512.png
// @license      MIT
// @description  Saves and loads website Point in time. Kind of like that one Rick and Morty episode but more nerdy.
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    // Register the "Save" menu command
    GM_registerMenuCommand("Save Data", function() {
        // Get the current website URL
        var url = window.location.href;
        // Get the current website data
        var data = {
            html: JSON.stringify(document.getElementsByTagName("html")[0].innerHTML),
            localStorage: JSON.stringify(localStorage),
            sessionStorage: JSON.stringify(sessionStorage)
        };

        // Save the data to the Tampermonkey storage
        GM_setValue(url, JSON.stringify(data));

        // Alert the user that the data has been saved
        alert("Data saved for " + url);
    });

    // Register the "Load" menu command
    GM_registerMenuCommand("Load Data", function() {
        // Get the current website URL
        var url = window.location.href;

        // Get the saved data from the Tampermonkey storage
        var savedData = JSON.parse(GM_getValue(url, null));

        // If there is saved data, replace the current page content and storage data with it
        if (savedData) {
            var newData = JSON.parse(savedData.html);
            document.getElementsByTagName("html")[0].innerHTML = newData;

            // Restore local storage data
            var newLocalStorageData = JSON.parse(savedData.localStorage);
            for (var key in newLocalStorageData) {
                localStorage.setItem(key, newLocalStorageData[key]);
            }

            // Restore session storage data
            var newSessionStorageData = JSON.parse(savedData.sessionStorage);
            for (var key in newSessionStorageData) {
                sessionStorage.setItem(key, newSessionStorageData[key]);
            }

            // Alert the user that the data has been loaded
            alert("Data loaded for " + url);
        } else {
            // Alert the user that there is no saved data for this website
            alert("No saved data for " + url);
        }
    });
})();