吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2828|回复: 15
收起左侧

[学习记录] 网页插件获取cookies

[复制链接]
baicj 发表于 2025-7-31 15:44

最近在获取登录用户cookies,每次按F12比较麻烦,就整了个tampermonkey插件,一键获取复制cookies

在tampermonkey安装并启用脚本后,网页右下角 显示:获取Cookies
image.png


[JavaScript] 纯文本查看 复制代码
// ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url]         获取并复制当前页面 Cookies
// [url=home.php?mod=space&uid=467642]@namespace[/url]    http://tampermonkey.net/
// [url=home.php?mod=space&uid=1248337]@version[/url]      1.2
// @description  点击按钮获取当前页面的 cookies
// [url=home.php?mod=space&uid=686208]@AuThor[/url]       52pojie
// [url=home.php?mod=space&uid=195849]@match[/url]        *://*/*
// [url=home.php?mod=space&uid=609072]@grant[/url]        none
// ==/UserScript==

(function () {
    'use strict';

    // 创建主按钮
    const button = document.createElement('button');
    button.innerText = '获取 Cookies';
    button.style.position = 'fixed';
    button.style.bottom = '20px';
    button.style.right = '20px';
    button.style.zIndex = '9999';
    button.style.padding = '10px 15px';
    button.style.backgroundColor = '#4CAF50';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.fontFamily = 'Arial, sans-serif';
    button.style.fontSize = '14px';

    // 主按钮点击事件
    button.addEventListener('click', () => {
        const cookies = document.cookie;

        // 创建显示框
        const output = document.createElement('pre');
        output.id = 'cookie-output';
        output.style.position = 'fixed';
        output.style.bottom = '100px';
        output.style.right = '20px';
        output.style.zIndex = '9999';
        output.style.backgroundColor = '#fff';
        output.style.border = '1px solid #ccc';
        output.style.padding = '10px';
        output.style.maxWidth = '400px';
        output.style.maxHeight = '200px';
        output.style.overflow = 'auto';
        output.style.fontFamily = 'monospace';
        output.style.fontSize = '12px';
        output.style.whiteSpace = 'pre-wrap';
        output.innerText = cookies || '(无 cookies)';

        // 创建复制按钮
        const copyButton = document.createElement('button');
        copyButton.innerText = '📋 复制到剪贴板';
        copyButton.disabled = !cookies;
        copyButton.style.position = 'fixed';
        copyButton.style.bottom = '60px';
        copyButton.style.right = '20px';
        copyButton.style.zIndex = '9999';
        copyButton.style.padding = '8px 12px';
        copyButton.style.backgroundColor = cookies ? '#2196F3' : '#ccc';
        copyButton.style.color = 'white';
        copyButton.style.border = 'none';
        copyButton.style.borderRadius = '4px';
        copyButton.style.cursor = cookies ? 'pointer' : 'not-allowed';
        copyButton.style.fontFamily = 'Arial, sans-serif';
        copyButton.style.fontSize = '12px';

        // 复制功能
        copyButton.addEventListener('click', () => {
            if (!cookies) return;

            navigator.clipboard.writeText(cookies).then(() => {
                // 显示提示信息
                const tip = document.createElement('div');
                tip.innerText = '✅ 已复制到剪贴板';
                tip.style.position = 'fixed';
                tip.style.bottom = '240px';
                tip.style.right = '20px';
                tip.style.zIndex = '9999';
                tip.style.backgroundColor = '#333';
                tip.style.color = '#fff';
                tip.style.padding = '8px 12px';
                tip.style.borderRadius = '4px';
                tip.style.fontSize = '12px';
                tip.style.fontFamily = 'Arial, sans-serif';
                tip.style.transition = 'opacity 0.5s';
                document.body.appendChild(tip);

                // 2秒后淡出提示
                setTimeout(() => {
                    tip.style.opacity = '0';
                    setTimeout(() => {
                        if (document.body.contains(tip)) {
                            document.body.removeChild(tip);
                        }
                    }, 500);
                }, 2000);
            }).catch(err => {
                console.error('复制失败:', err);
                alert('复制 cookies 失败,请重试');
            });
        });

        document.body.appendChild(output);
        document.body.appendChild(copyButton);

        // 5秒后自动移除元素
        setTimeout(() => {
            if (document.body.contains(output)) document.body.removeChild(output);
            if (document.body.contains(copyButton)) document.body.removeChild(copyButton);
        }, 5000);
    });

    // 添加主按钮到页面
    document.body.appendChild(button);
})();





免费评分

参与人数 2吾爱币 +3 热心值 +2 收起 理由
DANHUANGJIANGYO + 1 + 1 谢谢@Thanks!
OmJJWang + 2 + 1 我很赞同!

查看全部评分

发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

MuLinShang 发表于 2025-7-31 15:56
为什么会提示用户脚本无效的?没懂
天空の幻像 发表于 2025-7-31 15:58
MuLinShang 发表于 2025-7-31 16:00
MuLinShang 发表于 2025-7-31 15:56
为什么会提示用户脚本无效的?没懂

哦 删除了空行里的空格就能用了
咿呀咿呀呦 发表于 2025-7-31 16:21
MuLinShang 发表于 2025-7-31 15:56
为什么会提示用户脚本无效的?没懂

我复制了也一样提示脚本无效
MuLinShang 发表于 2025-7-31 16:37
咿呀咿呀呦 发表于 2025-7-31 16:21
我复制了也一样提示脚本无效

还要改题头,改成这样
// ==UserScript==
// @name         找cookies
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  点击按钮获取当前页面的 cookies
// @AuThor       52pojie
// @match        *://*/*
// @Icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
mr88fang 发表于 2025-7-31 16:43
可以试试这个插件 EditThisCookie ,不仅能导出还能导入(完整Cookie信息,作用域,过期时间等等)
头像被屏蔽
yuupuu 发表于 2025-7-31 16:46
提示: 作者被禁止或删除 内容自动屏蔽
Niklaus 发表于 2025-7-31 18:45
本帖最后由 Niklaus 于 2025-7-31 18:46 编辑

放一个书签不是更方便
[JavaScript] 纯文本查看 复制代码
javascript:prompt("cookie",document.cookie)


99586874 发表于 2025-7-31 18:56
用了6楼的题头导入成功了,但尝试获取天翼网盘的Cookie,获取的结果不是Cookie。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-10-22 13:31

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表