Greasy Fork

Greasy Fork is available in English.

NGA楼主标识

简单的对NGA楼主进行一个标注.

当前为 2022-04-18 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         NGA楼主标识
// @namespace    http://nickdoth.cc/
// @version      0.1.0
// @description  简单的对NGA楼主进行一个标注.
// @compatible   chrome
// @compatible   firefox
// @compatible   safari
// @license      MIT
// @author       nickdoth
// @match        http://bbs.nga.cn/read.php*
// @match        https://bbs.nga.cn/read.php*
// @grant        unsafeWindow
// ==/UserScript==

// MIT License
//
// Copyright (c) 2020 nickdoth
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// @ts-check

/// <reference path="./tieba-louzhu-marks.d.ts" />

(async function() {
    'use strict';

    // Query Theme Colors
    const ngaDark = unsafeWindow.__COLOR.uitxt1 ?? '';
    const ngaLight = unsafeWindow.__COLOR.border2 ?? '';

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

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

    // const qUid = '#post1strow0 a[name=uid]';
    const qUidV2 = '#postauthor0';
    // const uid = firstPageDoc.querySelector(qUid)?.textContent;
    const uid = /uid=(\d+)/.exec(firstPageDoc.querySelector(qUidV2)?.href ?? '')?.[1];

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

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

    sheet.insertRule(`a.author[href*="uid=${uid}"] {
        background: ${ngaLight};
        padding: 2.7px 0px;
        border-radius: 5px;
    }`, 1);
})();