NGA_parse_uid

uid转用户名

Version vom 18.01.2018. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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