NGA_parse_uid

uid转用户名

Stan na 18-01-2018. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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(){};