一键jc

· · 个人记录

rt,文本修改第 13 行,时间间隔修改第 14 行(初始为 30s)

// ==UserScript==
// @name         Benben Auto Poster
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  一键JC(支持白名单)
// @author       a_small_OIer
// @match        https://www.luogu.com.cn
// @grant        none
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';

    const TARGET_TEXT = '#I AK IOI';
    const INTERVAL = 30 * 1000;

    // ====== 白名单配置 ======
    const WHITELIST = {
        uids: ['1523280'],        // UID 列表(字符串)
        names: ['a_small_OIer']   // 用户名列表(区分大小写)
    };
    // =======================

    function getCurrentUserInfo() {
        const avatarLink = document.querySelector('a[href^="/user/"] img.avatar');
        if (avatarLink) {
            const parentHref = avatarLink.closest('a[href^="/user/"]')?.href || '';
            const uidMatch = parentHref.match(/\/user\/(\d+)/);
            return {
                uid: uidMatch ? uidMatch[1] : null,
                name: avatarLink.alt || ''
            };
        }
        const nameSpan = document.querySelector('span[style*="font-weight: bold"]');
        if (nameSpan) {
            return { uid: null, name: nameSpan.textContent.trim() };
        }

        return { uid: null, name: '' };
    }
    function isInWhitelist(userInfo) {
        if (!userInfo) return false;
        const { uid, name } = userInfo;
        if (uid && WHITELIST.uids.includes(uid)) return true;
        if (name && WHITELIST.names.includes(name)) return true;
        return false;
    }
    function sendBenben() {
        const input = document.querySelector('#feed-content');
        const btn = document.querySelector('#feed-submit');

        if (input && btn) {
            input.value = TARGET_TEXT;
            input.dispatchEvent(new Event('input', { bubbles: true }));
            input.dispatchEvent(new Event('change', { bubbles: true }));
            btn.click();
            console.log('【一键JC】 已发送:' + TARGET_TEXT);
        } else {
            setTimeout(sendBenben, 500);
        }
    }
    window.addEventListener('load', () => {
        setTimeout(() => {
            const userInfo = getCurrentUserInfo();
            if (isInWhitelist(userInfo)) {
                const who = userInfo.name || userInfo.uid || '未知用户';
                console.log(`【一键JC】 用户 ${who} 在白名单中,脚本已停止。`);
                return;
            }
            sendBenben();
            setInterval(sendBenben, INTERVAL);
        }, 3000);
    });
})();