// ==UserScript== // @name NGA_parse_uid // @version 0.21 // @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/* // @grant none // @namespace https://greasyfork.org/users/163468 // @description 在未登录/实名NGA时解析uid为用户名 // @downloadURL none // ==/UserScript== const pattern = 'nuke.php?func=ucp&uid='; Object.values(document.querySelectorAll('a[href*="' + pattern + '"]')).map((v, i) => { const uid = v.href.split(pattern)[1]; const xhr = new XMLHttpRequest(); function parser() { const res = JSON.parse(this.responseText); //uid to username const username = res.result.username; v.innerText = username; //add avatar const avatarDiv = v.parentNode.parentNode; let avatar = res.result.avatar; if (avatar && (avatarDiv.childNodes[1].className === 'stat')) { if (avatar.indexOf("{") >= 0) { avatar = JSON.parse(avatar); avatar = avatar[parseInt(Math.random() * avatar.l) + ""]; } if (avatar.indexOf("http") < 0 || avatar.indexOf("bbs") >= 0) { const file = avatar.match(/[0-9].*/)[0]; 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; } const img = document.createElement('img'); img.style.maxWidth = '280px'; img.style.margin = '5px auto'; img.style.borderRadius = '50%'; img.setAttribute('src', avatar); avatarDiv.insertBefore(img, avatarDiv.childNodes[1]); } } xhr.addEventListener("load", parser); xhr.open('GET', '/nuke.php?uid=' + uid + '&__output=12&__act=get&__lib=ucp'); xhr.send(); }); Object.values(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); } });