Cookie Editor

Edit cookies, use in script menu

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
        }
    }
})();