NGA_parse_uid_dev

在未登录/实名NGA时解析uid为用户名

目前為 2019-09-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         NGA_parse_uid_dev
// @version      1.0.0
// @author       Inazuma
// @match        https://nga.178.com/*
// @match        https://bbs.ngacn.cc/*
// @match        https://bbs.nga.cn/*
// @match        http://nga.178.com/*
// @match        http://bbs.nga.cn/*
// @match        http://bbs.ngacn.cc/*
// @namespace    https://greasyfork.org/users/163468
// @description  在未登录/实名NGA时解析uid为用户名
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(async () => {
    const pattern = 'nuke.php?func=ucp&uid=';
    const fetchedInfo = JSON.parse(await GM_getValue('uidMap', '{}'));
    [...document.querySelectorAll(`a[href*="${pattern}"]`)].map((v, i) => {
        const uid = v.href.split(pattern)[1];
        if (v.parentNode.className === 'quote' && !fetchedInfo[uid]) {
            fetchedInfo[uid] = v.innerText.slice(1, -1);
        } else if (fetchedInfo[uid]) {
            v.innerText = fetchedInfo[uid];
        }
    });
    await GM_setValue('uidMap', JSON.stringify(fetchedInfo));

    [...document.querySelectorAll('a[href="被禁止的链接"]')].map((v, i) => {
        let link;
        if (v.parentNode.className !== 'nobr') {
            link = v.previousElementSibling.firstChild.innerText.replace(/<[^>]+>/g, '');
            v.setAttribute('href', link);
            v.innerText = v.innerText.replace(/被禁止的链接/g, link);
        } else {
            link = v.parentNode.parentNode.firstChild.innerText.replace(/<[^>]+>/g, '');
            v.setAttribute('href', link);
        }
    });

})();