NGA楼主标识红色版

把NGA楼主标识成红底白字,修改自https://gf.qytechs.cn/zh-CN/scripts/443563

// ==UserScript==
// @name         NGA楼主标识红色版
// @version      0.0.5
// @namespace    https://gf.qytechs.cn/zh-CN/users/170891
// @description  把NGA楼主标识成红底白字,修改自https://gf.qytechs.cn/zh-CN/scripts/443563
// @compatible   chrome
// @compatible   firefox
// @compatible   safari
// @license      MIT
// @author       oscawty
// @match        http://bbs.nga.cn/*
// @match        https://bbs.nga.cn/*
// @match        http://nga.178.com/*
// @match        https://nga.178.com/*
// @grant        window
// ==/UserScript==

(
/**
 * @param {Window & { __COLOR: { [k: string]: string } }} window
 */
async function(window) {
    'use strict';

    const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));


    // Sheet
    /** @type {*} */
    let styleEl = undefined;


    const tidCb = async (tid, sheet) => {
        const firstPageHtml = await (fetch(`/read.php?tid=${tid}`, { credentials: 'include' }).then(res => res.text()));
        const firstPageDoc = (new DOMParser).parseFromString(firstPageHtml, 'text/html');

        const qUid = '#postauthor0';
        /** @type {HTMLAnchorElement | null} */
        const elUid = firstPageDoc.querySelector(qUid);
        const uid = /uid=(\d+)/.exec(elUid?.href ?? '')?.[1];

        console.debug('楼主', uid);

        sheet.insertRule(`a.b[href*="uid=${uid}"]:after {
            content: "楼主";
            background: #FF0000;
            color: #fff;
            border: 1px transparent solid;
            border-radius: 5px;
            padding: 2px 4px;
            margin-left: 1px;
            margin-right: 1px;
            font-size: 10px;
        }`, 0);


        sheet.insertRule(`a.b[href*="uid=${uid}"] {
        }`, 1);
    };


    let currTid;
    while (true) {
        await sleep(100);

        const tid = /tid=(\d+)/.exec(location.search ?? '')?.[1];
        if (tid === currTid) continue;

        currTid = tid;

        // cleanup
        if (styleEl && window.document.head) {
            console.debug('cleanup style');
            styleEl.remove();
        }

        if (!currTid) continue;

        styleEl = window.document.createElement('style');
        window.document.head.appendChild(styleEl);
        /** @type {CSSStyleSheet} */
        let sheet = styleEl.sheet;

        await tidCb(currTid, sheet);
    }

})(unsafeWindow);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址