一键导出Cookies

获取当前网页的Cookies,并提供一键导出和复制到剪贴板的功能,按钮更小更隐蔽

目前為 2025-05-27 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         一键导出Cookies
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  获取当前网页的Cookies,并提供一键导出和复制到剪贴板的功能,按钮更小更隐蔽
// @author       zskfree
// @match        http://*/*
// @match        https://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function getCookies() {
        return document.cookie;
    }

    function copyToClipboard(text) {
        if (typeof GM_setClipboard === 'function') {
            GM_setClipboard(text);
            alert('Cookies已复制到剪贴板!');
        } else {
            // Fallback for browsers/environments where GM_setClipboard is not available
            const textarea = document.createElement('textarea');
            textarea.value = text;
            textarea.style.position = 'fixed';
            textarea.style.top = '0';
            textarea.style.left = '0';
            textarea.style.width = '1px';
            textarea.style.height = '1px';
            textarea.style.opacity = '0';
            document.body.appendChild(textarea);
            textarea.focus();
            textarea.select();
            try {
                const successful = document.execCommand('copy');
                if (successful) {
                    alert('Cookies已复制到剪贴板!');
                } else {
                    alert('复制失败,请手动复制:\n' + text);
                }
            } catch (err) {
                alert('复制失败,请手动复制:\n' + text);
            }
            document.body.removeChild(textarea);
        }
    }

    // 创建一个更小、更隐蔽的圆形按钮
    const exportButton = document.createElement('button');
    exportButton.textContent = '🍪'; // 使用一个饼干图标,更不易察觉
    exportButton.title = '导出并复制Cookies'; // 鼠标悬停时显示提示
    exportButton.style.position = 'fixed';
    exportButton.style.bottom = '15px'; // 离底部稍近
    exportButton.style.right = '15px'; // 离右侧稍近
    exportButton.style.zIndex = '10000';
    exportButton.style.width = '35px'; // 宽度
    exportButton.style.height = '35px'; // 高度
    exportButton.style.borderRadius = '50%'; // 圆形
    exportButton.style.backgroundColor = 'rgba(0, 0, 0, 0.4)'; // 半透明黑色
    exportButton.style.color = 'white';
    exportButton.style.border = 'none';
    exportButton.style.fontSize = '20px'; // 字体大小
    exportButton.style.display = 'flex'; // 启用flexbox
    exportButton.style.justifyContent = 'center'; // 水平居中
    exportButton.style.alignItems = 'center'; // 垂直居中
    exportButton.style.cursor = 'pointer';
    exportButton.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
    exportButton.style.transition = 'background-color 0.3s ease'; // 添加过渡效果

    // 鼠标悬停效果
    exportButton.addEventListener('mouseenter', () => {
        exportButton.style.backgroundColor = 'rgba(0, 0, 0, 0.6)'; // 悬停时颜色变深
    });

    exportButton.addEventListener('mouseleave', () => {
        exportButton.style.backgroundColor = 'rgba(0, 0, 0, 0.4)'; // 鼠标移开时恢复
    });

    exportButton.addEventListener('click', () => {
        const cookies = getCookies();
        if (cookies) {
            copyToClipboard(cookies);
        } else {
            alert('当前页面没有Cookies。');
        }
    });

    document.body.appendChild(exportButton);
})();