NGA_parse_uid

uid转用户名

当前为 2018-01-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name NGA_parse_uid
  3. // @version 0.17
  4. // @author Inazuma
  5. // @match https://nga.178.com/*
  6. // @match https://bbs.ngacn.cc/*
  7. // @match https://bbs.nga.cn/*
  8. // @match http://nga.178.com/*
  9. // @match http://bbs.nga.cn/*
  10. // @match http://bbs.ngacn.cc/*
  11. // @require http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.3.min.js
  12. // @grant none
  13. // @namespace https://greasyfork.org/users/163468
  14. // @description uid转用户名
  15. // ==/UserScript==
  16.  
  17. let pattern = 'nuke.php?func=ucp&uid=';
  18. $('a[href*="' + pattern + '"]').each((i, v) => {
  19. let uid = v.href.split(pattern)[1];
  20. $.post('/nuke.php?uid=' + uid + '&__output=12&__act=get&__lib=ucp', res => {
  21.  
  22. //uid to username
  23. let username = res.result.username;
  24. v.innerText = username;
  25.  
  26. //add avatar
  27. let avatarDiv = $(v).parent().next();
  28. let avatar = res.result.avatar;
  29. if (avatar && (avatarDiv[0].className === 'stat')) {
  30. if (avatar.indexOf("{") < 0) {
  31. if (avatar.indexOf("http") < 0 || avatar.indexOf("bbs") >= 0) {
  32. let file = avatar.match(/[0-9].*/);
  33. let hex = parseInt(avatar.match(/[0-9]+/)[0]).toString(16);
  34. avatar = "http://img.ngacn.cc/avatars/2002/";
  35. while (hex.length < 9) {
  36. hex = '0' + hex;
  37. }
  38. hex = hex.match(/.{1,3}/g);
  39. for (let i = hex.length - 1; i >= 0; i--) {
  40. avatar = avatar + hex[i] + '/';
  41. }
  42. avatar += file;
  43. }
  44. } else {
  45. avatar = JSON.parse(avatar);
  46. avatar = avatar[parseInt(Math.random() * avatar.l) + ""];
  47. }
  48. avatarDiv.before('<img style="max-width: 280px; margin: 5px auto; border-radius: 50%;" src="' + avatar + '">');
  49. }
  50. });
  51. });
  52.  
  53. $('a[href="被禁止的链接"]').each((i, v) => {
  54. let link;
  55. if (v.parentNode.className !== 'nobr') {
  56. link = v.previousElementSibling.firstChild.innerText.replace(/<[^>]+>/g, '');
  57. v.setAttribute('href', link);
  58. v.innerText = v.innerText.replace(/被禁止的链接/g, link);
  59. } else {
  60. link = v.parentNode.parentNode.firstChild.innerText.replace(/<[^>]+>/g, '');
  61. v.setAttribute('href', link);
  62. }
  63. });
  64.  
  65.  
  66. //以下代码禁用了相关论坛代码,用于消除启用Tampermonkey脚本时发生的错误(大概不会有什么影响(不是我的锅,在nga上启用任何Tampermonkey脚本都会报错
  67.  
  68. commonui.quoteTo.hideWindow = function(){};
  69. commonui.quoteTo.onmouseup = function(){};