跳至主要內容

桔子自动签到

黄曦原创大约 5 分钟桔子自动签到

🎯 方案概览

组件作用
油猴脚本打开 https://juzi52.net/user 时自动点击签到
Windows 定时任务每天 7:51 自动打开浏览器执行签到
订阅流量查询脚本查询桔子云订阅的流量使用情况和到期时间

🖥️ 油猴脚本

代码

// ==UserScript==
// @name         桔子网每日签到
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动点击"每日签到"按钮,支持状态检测
// @author       You
// @match        https://juzi52.net/user
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  "use strict";

  // 等待按钮出现(最长20秒)
  function waitForElement(selector, timeout = 20000) {
    return new Promise((resolve) => {
      const start = Date.now();
      const check = () => {
        const el = document.querySelector(selector);
        if (el) {
          resolve(el);
        } else if (Date.now() - start > timeout) {
          resolve(null);
        } else {
          setTimeout(check, 300);
        }
      };
      check();
    });
  }

  async function main() {
    // 定位签到链接(通过父级 ID 精准定位)
    const btn = await waitForElement("#checkin-div a");
    if (!btn) {
      console.warn("⚠️ 未找到签到按钮,请检查页面结构");
      return;
    }

    const text = btn.textContent.trim();

    // 检测是否已签到(根据按钮文字判断)
    if (text.includes("已签到") || text.includes("已签")) {
      console.log("✅ 今日已签到,无需操作");
      return;
    }

    // 如果文字是"每日签到",执行签到
    if (text.includes("每日签到")) {
      console.log("🔍 准备签到...");

      // 优先调用全局函数 checkin()(最可靠)
      if (typeof checkin === "function") {
        checkin();
        console.log("✅ 已调用 checkin() 函数签到成功");
      } else {
        // 兜底方案:模拟点击
        btn.click();
        console.log("✅ 已模拟点击按钮");
      }
    } else {
      console.log("ℹ️ 按钮文本为:" + text + ',未匹配到"每日签到",请检查');
    }
  }

  // 等待页面完全加载后执行
  if (document.readyState === "complete") {
    main();
  } else {
    window.addEventListener("load", main);
  }
})();

脚本逻辑说明

步骤说明
① 定位按钮通过 #checkin-div a 精准定位签到链接
② 状态检测若按钮文字含"已签到"则直接退出,避免重复
③ 执行签到优先调用全局 checkin() 函数,失败则回退到模拟点击

⏰ Windows 定时任务

创建命令(管理员CMD执行)

schtasks /create /tn "桔子网签到" /tr "\"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe\" https://juzi52.net/user" /sc daily /st 07:51:00 /ru "hx\18421"

参数说明

参数含义
/tn任务名称:桔子网签到
/tr执行命令:打开 Edge 并访问签到页
/sc daily每天重复
/st 07:51:00开始时间(24小时制)
/ru "hx\18421"以该用户身份运行

常用管理命令

# 查看任务详情
schtasks /query /tn "桔子网签到" /fo LIST /v

# 手动运行一次
schtasks /run /tn "桔子网签到"

# 修改时间(如改为 08:00)
schtasks /change /tn "桔子网签到" /st 08:00

# 删除任务
schtasks /delete /tn "桔子网签到" /f

📊 订阅流量查询脚本

功能说明

这是一个 Node.js 脚本,用于查询桔子云订阅的流量使用情况和到期时间。

功能说明
获取流量信息从响应头 subscription-userinfo 提取上传、下载、总量等数据
流量统计将字节转换为 GB,计算已用、剩余、使用占比
到期计算计算套餐剩余天数,以及每天需使用的流量配额
状态检测检测套餐是否已过期

代码

const axios = require("axios")

// 你的订阅链接
const SUB_URL = "xxxxxxxx"

// 设置 User-Agent,模仿 Clash Verge
const USER_AGENT = "clash-verge/v1.3.7"

async function fetchSubscription() {
  try {
    // 发起 GET 请求,允许自动跟随重定向(最多 5 次)
    const response = await axios({
      method: "get",
      url: SUB_URL,
      headers: {
        "User-Agent": USER_AGENT,
        Accept: "application/yaml, application/octet-stream",
      },
      maxRedirects: 5,
    })

    // 打印最终响应的状态码(应为 200)
    console.log("最终响应状态码:", response.status)

    // 从响应头提取流量信息
    const userInfo = response.headers["subscription-userinfo"]
    if (userInfo) {
      console.log("✅ 获取到流量信息 (原始):", userInfo)

      // 解析流量字段
      const parts = userInfo.split(";").reduce((acc, item) => {
        const [key, val] = item.trim().split("=")
        if (key && val) acc[key.trim()] = parseInt(val, 10)
        return acc
      }, {})

      console.log("\n📊 解析结果:")
      console.log("上传 (bytes):", parts.upload)
      console.log("下载 (bytes):", parts.download)
      console.log("总量 (bytes):", parts.total)
      console.log("过期时间戳:", parts.expire)

      // 转换为 GB(按 1 GB = 1024^3 bytes)
      const uploadGB = parts.upload / 1024 ** 3
      const downloadGB = parts.download / 1024 ** 3
      const totalGB = parts.total / 1024 ** 3
      const usedGB = (parts.upload + parts.download) / 1024 ** 3
      const remainGB = (parts.total - parts.upload - parts.download) / 1024 ** 3

      console.log("\n📦 流量统计 (GB):")
      console.log("上传:    ", uploadGB.toFixed(2), "GB")
      console.log("下载:    ", downloadGB.toFixed(2), "GB")
      console.log("已用总计:", usedGB.toFixed(2), "GB")
      console.log("套餐总量:", totalGB.toFixed(2), "GB")
      console.log("剩余:    ", remainGB.toFixed(2), "GB")
      console.log("使用占比:", ((usedGB / totalGB) * 100).toFixed(2), "%")

      // 计算到期前每天流量分配
      const now = Math.floor(Date.now() / 1000)
      const remainSeconds = parts.expire - now
      const remainDays = Math.max(0, Math.ceil(remainSeconds / (24 * 60 * 60)))

      console.log("\n📅 到期计算:")
      console.log("过期时间:", new Date(parts.expire * 1000).toLocaleString("zh-CN"))
      console.log("剩余天数:", remainDays, "天")

      if (remainDays > 0) {
        const dailyUsageGB = remainGB / remainDays
        console.log("\n📊 每日流量分配:")
        console.log("每天需用:", dailyUsageGB.toFixed(2), "GB 才能刚好用完")
      } else {
        console.log("\n⚠️  套餐已过期或今天到期")
      }
    } else {
      console.warn("⚠️ 响应头中没有 subscription-userinfo,可能该机场不支持此标准。")
    }
  } catch (error) {
    console.error("❌ 请求失败:", error.message)
  }
}

// 执行
fetchSubscription()

使用方法

# 安装依赖
npm install axios

# 运行脚本
node fetch-subscription.js

输出示例

最终响应状态码: 200
✅ 获取到流量信息 (原始): upload=1234567890;download=9876543210;total=107374182400;expire=1735689600

📊 解析结果:
上传 (bytes): 1234567890
下载 (bytes): 9876543210
总量 (bytes): 107374182400
过期时间戳: 1735689600

📦 流量统计 (GB):
上传:     1.15 GB
下载:     9.20 GB
已用总计: 10.35 GB
套餐总量: 100.00 GB
剩余:     89.65 GB
使用占比: 10.35 %

📅 到期计算:
过期时间: 2025/12/31 08:00:00
剩余天数: 180 天

📊 每日流量分配:
每天需用: 0.50 GB 才能刚好用完

🚀 使用流程

  1. 安装油猴脚本:Tampermonkey → 新建脚本 → 粘贴代码 → 保存。
  2. 创建定时任务:以管理员身份运行 CMD,执行上述 schtasks /create 命令。
  3. 验证:手动打开 https://juzi52.net/user,观察控制台日志是否正常签到。

❓ 常见问题

问题解决方案
按钮没点击检查浏览器是否已登录 juzi52.net
找不到签到按钮页面结构变化,按 F12 检查新元素后更新选择器
定时任务报错确保 CMD 以管理员身份运行
路径错误检查 Edge 安装路径是否为 C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe

📝 总结

环节关键点
脚本@match 匹配目标 URL,#checkin-div a 定位按钮,checkin() 触发签到
定时任务每天 7:51 自动打开浏览器 → 油猴脚本自动执行签到
流量查询使用 Node.js 脚本查询订阅流量使用情况和到期时间
维护网站改版时只需更新脚本中的选择器即可

配置完成后完全自动化,无需人工干预。🎉