Cookie Editor

Edit cookies, use in script menu

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Cookie Editor
// @version      1.1
// @description  Edit cookies, use in script menu
// @author       DeepSeek
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @run-at       document-end
// @namespace https://greatest.deepsurf.us/users/452911
// ==/UserScript==

(function() {
    'use strict';

    // Register menu command
    GM_registerMenuCommand('Edit Cookies', editCookiesPrecisely, 'e');

    function editCookiesPrecisely() {
        // Get all current cookies and convert to object
        const currentCookies = document.cookie.split(';').reduce((obj, cookie) => {
            const [name, value] = cookie.trim().split('=');
            if (name) obj[name] = value || '';
            return obj;
        }, {});

        // Convert to edit string (semicolon separated)
        const editText = Object.entries(currentCookies)
            .map(([name, value]) => `${name}=${value}`)
            .join('; ');

        // Use prompt dialog to edit
        const newText = prompt('Edit Cookies (semicolon separated format):\n\nNote: Any cookie not in the edit box will be deleted', editText);
        if (newText === null) return; // User cancelled

        try {
            // Parse new cookies
            const newCookies = newText.split(';').reduce((obj, cookie) => {
                const [name, value] = cookie.trim().split('=');
                if (name) obj[name] = value || '';
                return obj;
            }, {});

            // Find cookies to delete (existing but not in new list)
            Object.keys(currentCookies).forEach(name => {
                if (!(name in newCookies)) {
                    document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
                }
            });

            // Set new or modified cookies
            Object.entries(newCookies).forEach(([name, value]) => {
                document.cookie = `${name}=${value}; path=/`;
            });

            // Show result and refresh
            const changedCount = Object.keys(newCookies).length;
            const deletedCount = Object.keys(currentCookies).length - changedCount;
            alert(`Cookie update complete:\nAdded/Modified: ${changedCount}\nDeleted: ${deletedCount}\nThe page will refresh...`);
            setTimeout(() => location.reload(), 500);

        } catch (e) {
            alert('Error: ' + e.message);
        }
    }
})();