NGA_parse_uid

uid转用户名

Versione datata 18/01/2018. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         NGA_parse_uid
// @version      0.17
// @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/*
// @require      http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.3.min.js
// @grant       none
// @namespace https://greasyfork.org/users/163468
// @description uid转用户名
// ==/UserScript==

let pattern = 'nuke.php?func=ucp&uid=';
$('a[href*="' + pattern + '"]').each((i, v) => {
    let uid = v.href.split(pattern)[1];
    $.post('/nuke.php?uid=' + uid + '&__output=12&__act=get&__lib=ucp', res => {

        //uid to username
        let username = res.result.username;
        v.innerText = username;

        //add avatar
        let avatarDiv = $(v).parent().next();
        let avatar = res.result.avatar;
        if (avatar && (avatarDiv[0].className === 'stat')) {
            if (avatar.indexOf("{") < 0) {
                if (avatar.indexOf("http") < 0 || avatar.indexOf("bbs") >= 0) {
                    let file = avatar.match(/[0-9].*/);
                    let hex = parseInt(avatar.match(/[0-9]+/)[0]).toString(16);
                    avatar = "http://img.ngacn.cc/avatars/2002/";
                    while (hex.length < 9) {
                        hex = '0' + hex;
                    }
                    hex = hex.match(/.{1,3}/g);
                    for (let i = hex.length - 1; i >= 0; i--) {
                        avatar = avatar + hex[i] + '/';
                    }
                    avatar += file;
                }
            } else {
                avatar = JSON.parse(avatar);
                avatar = avatar[parseInt(Math.random() * avatar.l) + ""];
            }
            avatarDiv.before('<img style="max-width: 280px; margin: 5px auto; border-radius: 50%;" src="' + avatar + '">');
        }
    });
});

$('a[href="被禁止的链接"]').each((i, v) => {
    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);
    }
});


//以下代码禁用了相关论坛代码,用于消除启用Tampermonkey脚本时发生的错误(大概不会有什么影响(不是我的锅,在nga上启用任何Tampermonkey脚本都会报错

commonui.quoteTo.hideWindow = function(){};
commonui.quoteTo.onmouseup = function(){};