// ==UserScript== // @name 洛谷取关提醒器 // @namespace Gary0 // @author Gary0 // @version 5.0 // @license GPL-3.0 // @description 可以快速检测近期粉丝变化 // @run-at document-end // @match https://www.luogu.com.cn/* // @icon https://cdn.luogu.com.cn/upload/usericon/3.png // @grant none // ==/UserScript== function esc_html(s) { let str = String(s); return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); } function get_el(id) { return document.getElementById(id); } function new_el(id) { return document.createElement(id); } function insert_el(base, label, content, id, class_list) { const el = new_el(label); el.innerHTML = content, el.id = id, el.classList = class_list; return base.appendChild(el); } function insert_css(content) { insert_el(get_el("fchecker"), "style", content, "", ""); } const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); function string_to_map(data_json) { const data_ob = JSON.parse(data_json); const data_arr = Object.entries(data_ob); const data_map = new Map(data_arr); return data_map; } function map_to_string(data_map) { const data_ob = Object.fromEntries(data_map); const data_json = JSON.stringify(data_ob); return data_json; } const version = "5.0", devs = [1202669], fchecker = insert_el(document.body, "div", "", "fchecker", ""); fchecker.style = "position: fixed; top: 0; left: 0; bottom: 0; right: 0; z-index: 1000; pointer-events: none;"; function get_settings_map() { const saved = localStorage.getItem("fchecker-setting"); if (saved) { try { return string_to_map(saved); } catch(e) { } } const default_map = new Map(); default_map.set("show-btn", "true"); return default_map; } async function update_relation(uid, action) { const token = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); if (!token) return false; try { const res = await fetch("https://www.luogu.com.cn/api/user/updateRelationShip", { method: "POST", headers: { "content-type": "application/json", "x-csrf-token": token, "x-requested-with": "XMLHttpRequest" }, body: JSON.stringify({ uid: Number(uid), relationship: Number(action) }) }); return res.ok; } catch (e) { return false; } } function get_uid() { const m = document.getElementById("lentille-context"); if (!m) return null; const json = JSON.parse(m.innerHTML); if (!json?.user?.uid) return null; return json.user.uid; } async function show_message(msg, time) { main.style.display = "none"; const mask = insert_el(fchecker, "div", "", "", "fchecker-modal-mask"); const dialog = insert_el(mask, "div", "", "", "fchecker-modal-dialog"); const header = insert_el(dialog, "div", " ", "", "fchecker-modal-header"); const quit_btn = insert_el(header, "button", "×", "", "fchecker-modal-close"); mask.style.opacity = 0, mask.style.transition = "opacity 0.3s ease-in-out", dialog.style.height = "auto", dialog.style.width = "300px"; let cls = false; async function destroy_modal() { if (cls) return; cls = true; mask.style.opacity = 0; await sleep(300); mask.remove(); }; quit_btn.addEventListener("click", destroy_modal); setTimeout(destroy_modal, time); insert_el(dialog, "div", msg, "", "fchecker-modal-body"); await sleep(10); mask.style.opacity = 1; } const UID = get_uid(); if (!UID) return; insert_css(` .fchecker-card { background-color: #fff; box-shadow: 0 1px 3px #1a1a1a1a; border-radius: 4px; padding: 10px; margin: 10px; text-align: center; overflow-y: auto; } .fchecker-btn { background-color: #3498db; color: #fff; border: none; border-radius: 4px; padding: 10px; margin: 10px; text-align: center; } .fchecker-btn:hover { cursor: pointer; } .fchecker-user { text-align: left; height: 42px; padding: 10px; overflow: hidden; white-space: nowrap; border-bottom: 1px solid #e8e8e8; display: flex; align-items: center; justify-content: space-between; } .fchecker-user-info { display: flex; align-items: center; overflow: hidden; white-space: nowrap; width: calc(100% - 90px); height: 100%; } .fchecker-user .left { border-radius: 50%; height: 42px; width: 42px; vertical-align: middle; } .fchecker-user .right { padding-left: 10px; display: inline-block; height: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; vertical-align: middle; width: calc(100% - 42px); } .fchecker-user .user-title { display: flex; align-items: center; gap: 4px; height: 22px; } .fchecker-user svg { display: inline-block; height: 1.1em; width: 1.125em; vertical-align: middle; } .fchecker-user .am-badge { display: inline-block; padding: .25em .625em; font-size: 75%; font-weight: 700; line-height: 1; color: #fff; text-align: center; white-space: nowrap; vertical-align: baseline; } .fchecker-user .am-radius { border-radius: 2px; } .fchecker-user .slogan { font-size: .875em; color: #444; margin-top: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .fchecker-action-btn { border: none; border-radius: 4px; padding: 6px 10px; color: #fff; font-size: 11px; cursor: pointer; white-space: nowrap; } .fchecker-setting-item { margin-bottom: 15px; display: flex; align-items: center; gap: 8px; font-size: 14px; } .fchecker-setting-item input { cursor: pointer; width: 16px; height: 16px; } #fchecker-main { position: fixed; top: 60px; right: -300px; width: 300px; pointer-events: auto; transition: transform 0.2s ease; } #fchecker-main:hover { transform: translateX(-280px); } .fchecker-modal-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; pointer-events: auto; z-index: 1050; } .fchecker-modal-dialog { background: #fff; border-radius: 4px; width: 550px; max-width: 90vw; height: 600px; max-height: 80vh; box-shadow: 0 4px 12px rgba(0,0,0,0.15); display: flex; flex-direction: column; overflow: hidden; text-align: left; } .fchecker-modal-header { padding: 14px 20px; border-bottom: 1px solid #e8e8e8; display: flex; align-items: center; justify-content: space-between; } .fchecker-modal-body { padding: 20px; flex: 1; overflow-y: auto; } .fchecker-modal-close { background: none; border: none; font-size: 22px; color: #999; cursor: pointer; line-height: 1; padding: 0; } .fchecker-modal-close:hover { color: #333; } `); const main = insert_el(fchecker, "div", "

取关提醒器

", "fchecker-main", "fchecker-card"); const get_btn = insert_el(main, "button", "获取粉丝列表", "", "fchecker-btn"); const set_btn = insert_el(main, "button", "设置", "", "fchecker-btn"); const info_btn = insert_el(main, "button", "其他", "", "fchecker-btn"); async function show_get() { main.style.display = "none"; document.body.style.overflow = "hidden"; const mask = insert_el(fchecker, "div", "", "", "fchecker-modal-mask"); const dialog = insert_el(mask, "div", "", "", "fchecker-modal-dialog"); const header = insert_el(dialog, "div", "粉丝列表", "", "fchecker-modal-header"); const quit_btn = insert_el(header, "button", "×", "", "fchecker-modal-close"); quit_btn.style.visibility = "hidden"; function destroy_modal() { mask.remove(); document.body.style.overflow = ""; main.style.display = ""; }; quit_btn.addEventListener("click", destroy_modal); const get_card = insert_el(dialog, "div", "", "", "fchecker-modal-body"); const get_card_status = insert_el(get_card, "p", "", "", "", ""); async function parse_followers(html) { const m = html.match(/