Cookie/Localstorage Manager

Import or export localstorage and cookies of any site

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);