🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Douyu-giver 礼物赠送 Cookie 同步助手 (高级版)

自动/手动同步 Cookie 到 GitHub 文件。每天自动检查一次。UI 更轻量。

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!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

Author
yqqxy
Daily installs
0
Total installs
0
Ratings
0 0 0
Version
4.3
Created
2025-12-03
Updated
2025-12-03
Size
6.7 KB
License
N/A
Applies to

Douyu-giver 礼物赠送 Cookie 同步助手(高级版)说明

一、脚本功能概述

Douyu-giver 礼物赠送 Cookie 同步助手 是一个运行在斗鱼网页端的油猴脚本,用于自动 / 手动将当前账号的斗鱼 Cookie 同步到 GitHub 仓库中的一个文件,方便在其他环境(如脚本、程序、服务器)中复用登录态。主要是为了配合GitHub action实现自动无需周日登录的礼物赠送,详情查看https://github.com/yqqxybm/douyu-giver

主要特性:

  • 支持「自动同步」:每 24 小时检查一次,满足条件则自动把 Cookie 写入指定仓库文件
  • 支持「手动同步」:一键从当前页面读取 Cookie 写入 GitHub
  • 支持「粘贴同步」:可以从别处复制 Cookie,直接手动粘贴后同步
  • 界面提示轻量化:右下角小 Toast 卡片,减少对直播间观看的干扰
  • 支持 GM_cookie:在支持该 API 的环境下,能拿到更完整的 Cookie 列表

二、工作原理简述

  1. Cookie 获取
  • 优先通过 GM_cookie.list({ url: 'https://www.douyu.com/' }) 获取浏览器中与斗鱼域名相关的所有 Cookie;
  • GM_cookie 不可用,则退回到 document.cookie
  1. 有效性校验
  • 若最终得到的 Cookie 字符串中不包含 acf_uidacf_auth,脚本认为当前未登录斗鱼,会直接报错「未检测到登录」,避免同步无效 Cookie。
  1. 编码与存储
  • 使用 utf8_to_b64 将 Cookie 字符串转成 base64 文本;
  • 通过 GitHub Contents API,将其写入指定仓库路径: COOKIE_FILE_PATH = ".github/douyu_cookie.txt"
  • 若文件已存在,会先通过 API 获取 sha,再执行覆盖更新。
  1. 自动同步策略
  • 启动后延迟约 5 秒执行一次 runSync(null, true)
  • 自动模式下,会读取上次同步时间 last_sync_time
  • 若距离上次同步不足 AUTO_SYNC_INTERVAL_HOURS = 24 小时,则跳过本次自动同步,仅在控制台输出日志,不打扰用户。

三、菜单与使用方法

安装脚本并在斗鱼页面启用后,点击浏览器右上角 Tampermonkey 图标,在脚本菜单中可以看到:

  1. 🚀 立即同步
  • 从当前页面读取 Cookie(或通过 GM_cookie),立刻尝试同步到 GitHub;
  • 会在右下角弹出「正在同步」/「同步成功」/「同步失败」的 Toast 提示。
  1. 📋 手动粘贴 Cookie
  • 弹出一个输入框,你可以将从浏览器 / 抓包工具中复制的 Cookie 粘贴进去;
  • 脚本会使用这份粘贴的 Cookie 进行同步,而不是读取当前页面。
  1. ⚙️ 设置
  • 配置 GitHub 相关信息:

    • GitHub Token(需要有访问目标仓库的权限,通常需要 repo 权限)
    • 仓库路径(例如:yourname/douyu_helper
  • 设置完成后,会自动触发一次同步以验证配置是否可用。


四、GitHub 端行为说明

  • 文件路径固定为:.github/douyu_cookie.txt
  • 文件内容为 base64 编码后的 Cookie 字符串(不是纯明文,但解码很容易)
  • 每次同步会提交一条 commit,commit message 为: chore: auto update cookie [skip ci]

五、风险与注意事项

  • 仓库务必设置为私有仓库

    • 任意拥有仓库读取权限的人,都可以解码 .github/douyu_cookie.txt,进而复用你的斗鱼登录态,带来账号安全风险。
  • Token 权限建议最小化

    • 建议为这个用途单独创建一个 GitHub Token,只勾选需要的 repo 权限,且只用于该仓库。
  • 若你在公共 / 公司环境使用,请谨慎评估安全风险,不要把此脚本用于任何不受完全控制的账号。