Cookie Editor

Edit cookies, use in script menu

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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