Cookie/Localstorage Manager

Import or export localstorage and cookies of any site

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

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

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

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

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

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

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

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

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

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

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

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

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

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

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Cookie/Localstorage Manager
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Import or export localstorage and cookies of any site
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// @include      *
// @license      MIT
// ==/UserScript==
function exportAll() {
    let data = {
        localStorage: {},
        cookies: {}
    };

    for (let i = 0; i < localStorage.length; i++) {
        const key = localStorage.key(i);
        data.localStorage[key] = localStorage.getItem(key);
    }

    const cookies = document.cookie.split('; ');
    cookies.forEach(cookie => {
        const [name, value] = cookie.split('=');
        const cookieName = name.trim();
        const cookieValue = value.trim();

        const cookieAttributes = document.cookie.split('; ').find(c => c.startsWith(cookieName));
        const attributes = cookieAttributes ? cookieAttributes.split('; ').slice(1) : [];

        let expires = attributes.find(attr => attr.trim().toLowerCase().startsWith('expires='));

        data.cookies[cookieName] = {
            value: cookieValue,
            expires: expires ? expires.split('=')[1] : null
        };
    });

    const dataString = JSON.stringify(data);
    GM_setClipboard(dataString);
    alert('localStorage and cookies copied to clipboard!');
}

function importAll() {
    const dataString = prompt('Paste the stringified JSON data to import into localStorage and cookies:');
    if (dataString) {
        try {
            const data = JSON.parse(dataString);

            if (data.localStorage) {
                Object.entries(data.localStorage).forEach(([k, v]) => {
                    localStorage.setItem(k, v);
                });
            }

            if (data.cookies) {
                Object.entries(data.cookies).forEach(([k, { value, expires }]) => {
                    let cookieString = `${k}=${value}; path=/`;
                    if (expires) {
                        const expirationDate = new Date(expires);
                        cookieString += `; expires=${expirationDate.toUTCString()}`;
                    }
                    document.cookie = cookieString;
                });
            }

            alert('localStorage and cookies imported successfully!');
        } catch (e) {
            alert('Failed to import data. Please make sure the input is valid JSON. Error: ' + e.message);
            console.error(e);
        }
    } else {
        alert('No data was entered.');
    }
}

GM_registerMenuCommand("Copy localStorage and Cookies to Clipboard", exportAll);
GM_registerMenuCommand("Import localStorage and Cookies from Clipboard", importAll);