[Reddit] ModmailExtraInfo

Shows additional user information on the sidebar of modmail

当前为 2021-07-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name [Reddit] ModmailExtraInfo
  3. // @namespace HKR
  4. // @match https://mod.reddit.com/mail/*
  5. // @grant none
  6. // @version 1.1
  7. // @author HKR
  8. // @description Shows additional user information on the sidebar of modmail
  9. // @require https://greasyfork.org/scripts/21927-arrive-js/code/arrivejs.js
  10. // @icon https://www.redditstatic.com/modmail/favicon/favicon-32x32.png
  11. // @supportURL https://github.com/Hakorr/Userscripts/issues
  12. // ==/UserScript==
  13.  
  14. var dataColor = "#6e6e6e";
  15.  
  16. function Get(url) {
  17. var xmlHttp = new XMLHttpRequest();
  18. xmlHttp.open( "GET", url, false );
  19. xmlHttp.send( null );
  20. return xmlHttp.responseText;
  21. }
  22.  
  23. function time(UNIX_timestamp){
  24. var a = new Date(UNIX_timestamp * 1000);
  25. var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  26. var year = a.getFullYear();
  27. var month = fixnumber(a.getMonth());
  28. var date = fixnumber(a.getDate());
  29. var hour = fixnumber(a.getHours());
  30. var min = fixnumber(a.getMinutes());
  31. var sec = fixnumber(a.getSeconds());
  32. var time = date + '/' + month + '/' + year + ' ' + hour + ':' + min + ':' + sec ;
  33. return time;
  34. }
  35.  
  36. function fixnumber(number) {
  37. if(number < 10) return "0" + number;
  38. else return number;
  39. }
  40.  
  41. function addInfo(){
  42. var username = document.getElementsByClassName("InfoBar__username")[0].innerText;
  43. var about = "https://www.reddit.com/user/" + username +"/about.json";
  44.  
  45. var user = JSON.parse(Get(about));
  46.  
  47. var seperator = document.createElement('div');
  48. seperator.innerHTML = '<div class="InfoBar__modActions">'
  49. + '</div>';
  50.  
  51. var userDetails = document.createElement('div');
  52. userDetails.innerHTML = '<div class="InfoBar__age">'
  53. + '<h1 style="color: #1a1a1b; font-size: 18px; margin-bottom: 10px;">u/' + user.data.name + '\'s info</h1>'
  54. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Icon</h1>'
  55. + '<img style="margin-bottom: 10px; padding-left: 10px;" src="' + user.data.icon_img + '" width="50">'
  56. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Main</h1>'
  57. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Created: ' + time(user.data.created) + '</h1>'
  58. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">UserID: ' + user.data.id + '</h1>'
  59. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Verified: ' + user.data.verified + '</h1>'
  60. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Employee: ' + user.data.is_employee + '</h1>'
  61. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-top: 5px; margin-bottom: 3px;">Karma</h1>'
  62. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Post: ' + user.data.link_karma + '</h1>'
  63. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Comment: ' + user.data.comment_karma + '</h1>'
  64. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Total: ' + user.data.total_karma + '</h1>'
  65. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Awardee: ' + user.data.awardee_karma + '</h1>'
  66. + '<h1 style="color: '+ dataColor +'; font-size: 13px; padding-left: 10px;">Awarder: ' + user.data.awarder_karma + '</h1>'
  67. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Links</h1>'
  68. + '<a style="padding-left: 10px;" class="InfoBar__recent" href="https://redditmetis.com/user/' + user.data.name + '" target="_blank">Redditmetis</a>'
  69. + '<a style="padding-left: 10px;" class="InfoBar__recent" href="https://www.reddit.com/search?q=' + user.data.name + '" target="_blank">Reddit Search</a>'
  70. + '<a style="padding-left: 10px;" class="InfoBar__recent" href="https://www.google.com/search?q=%22' + user.data.name + '%22" target="_blank">Google Search</a>'
  71. + '<a style="padding-left: 10px;" class="InfoBar__recent" href="https://www.google.com/search?q=%22' + user.data.name + '%22%20site%3Areddit.com%20OR%20site%3Aredditgifts.com" target="_blank">Google Reddit Search</a>'
  72. + '<a style="padding-bottom: 20px; padding-left: 10px;" class="InfoBar__recent" href="https://github.com/Hakorr/Userscripts/tree/main/Reddit.com/ModmailExtraInfo">Github</a>'
  73. + '</div>';
  74. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(seperator);
  75. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(userDetails);
  76. }
  77.  
  78. const elementToWatch = 'a[class="InfoBar__username"]';
  79. document.arrive(elementToWatch, function () {
  80. addInfo();
  81. });
  82.  
  83. if(document.getElementsByClassName("InfoBar__username")[0]) addInfo();