复制 Cookie

添加一个按钮点击后复制当前页面的 Cookie 信息到剪切板(兼容写法)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         复制 Cookie
// @namespace    http://tampermonkey.net/
// @match        https://www.kuafuzys.com/*
// @match        https://bbs.52huahua.cc/*
// @match        https://www.kuafuzy.com/*
// @version      1.0.1
// @description  添加一个按钮点击后复制当前页面的 Cookie 信息到剪切板(兼容写法)
// @author       PYY
// @grant        none
// ==/UserScript==

    (function () {
        'use strict';

        // 创建按钮
        const button = document.createElement('button');
        button.textContent = '📋 复制 Cookie';
        button.style.position = 'fixed';
        button.style.bottom = '20px';
        button.style.right = '20px';
        button.style.zIndex = '9999';
        button.style.padding = '10px 14px';
        button.style.backgroundColor = '#4CAF50';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '6px';
        button.style.cursor = 'pointer';
        button.style.boxShadow = '0 2px 6px rgba(0,0,0,0.3)';
        button.style.fontSize = '14px';

        document.body.appendChild(button);

        button.addEventListener('click', () => {
            const cookie = document.cookie;
            if (!cookie) {
                alert('⚠️ 当前页面没有 Cookie 可复制');
                return;
            }

            if (navigator.clipboard && window.isSecureContext) {
                navigator.clipboard.writeText(cookie).then(() => {
                    alert('✅ Cookie 已复制到剪切板!');
                    console.log('[Cookie]', cookie);
                }).catch(err => {
                    console.error('❌ 复制失败:', err);
                    alert('❌ 无法复制 Cookie(权限问题)');
                });
            } else {
                // fallback 写法
                const textarea = document.createElement('textarea');
                textarea.value = cookie;
                document.body.appendChild(textarea);
                textarea.select();
                try {
                    const success = document.execCommand('copy');
                    alert(success ? '✅ Cookie 已复制(兼容方式)' : '❌ 复制失败');
                } catch (err) {
                    console.error('复制异常:', err);
                    alert('❌ 复制失败(异常)');
                }
                document.body.removeChild(textarea);
            }
        });
    })();