[Reddit] ModmailAdditionalInfo

Shows additional user information on the sidebar of modmail

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

  1. // ==UserScript==
  2. // @name [Reddit] ModmailAdditionalInfo
  3. // @namespace HKR
  4. // @match https://mod.reddit.com/mail/*
  5. // @grant none
  6. // @version 1.0
  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. function Get(url) {
  15. var xmlHttp = new XMLHttpRequest();
  16. xmlHttp.open( "GET", url, false );
  17. xmlHttp.send( null );
  18. return xmlHttp.responseText;
  19. }
  20.  
  21. function timeConverter(UNIX_timestamp){
  22. var a = new Date(UNIX_timestamp * 1000);
  23. var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  24. var year = a.getFullYear();
  25. var month = months[a.getMonth()];
  26. var date = a.getDate();
  27. var hour = a.getHours();
  28. var min = a.getMinutes();
  29. var sec = a.getSeconds();
  30. var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
  31. return time;
  32. }
  33.  
  34. function addInfo(){
  35. var dataColor = "#006DC6";
  36. var username = document.getElementsByClassName("InfoBar__username")[0].innerText;
  37. var about = "https://www.reddit.com/user/" + username +"/about.json";
  38.  
  39. var user = JSON.parse(Get(about));
  40.  
  41. var seperator = document.createElement('div');
  42. seperator.innerHTML = '<div class="InfoBar__modActions">'
  43. + '</div>';
  44.  
  45. var userDetails = document.createElement('div');
  46. userDetails.innerHTML = '<div class="InfoBar__age">'
  47. + '<h1 style="color: #1a1a1b; font-size: 18px; margin-bottom: 10px;">u/' + user.data.name + '\'s info</h1>'
  48. + '<h1 style="color: #515151; font-size: 15px; margin-bottom: 3px;">Karma</h1>'
  49. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Total: ' + user.data.total_karma + '</h1>'
  50. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Post: ' + user.data.link_karma + '</h1>'
  51. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Comment: ' + user.data.comment_karma + '</h1>'
  52. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Awardee: ' + user.data.awardee_karma + '</h1>'
  53. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Awarder: ' + user.data.awarder_karma + '</h1>'
  54.  
  55. + '<h1 style="color: #515151; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Other</h1>'
  56. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">UserID: ' + user.data.id + '</h1>'
  57. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Created: ' + timeConverter(user.data.created) + '</h1>'
  58. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Verified: ' + user.data.verified + '</h1>'
  59. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Gold: ' + user.data.is_gold + '</h1>'
  60. + '<h1 style="color: '+ dataColor +'; font-size: 13px;">Employee: ' + user.data.is_employee + '</h1>'
  61. + '<h1 style="color: #515151; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Icon</h1>'
  62. + '<img style="margin-bottom: 10px;" src="' + user.data.icon_img + '" width="100">'
  63.  
  64. + '</div>';
  65. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(seperator);
  66. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(userDetails);
  67. }
  68.  
  69. const elementToWatch = 'a[class="InfoBar__username"]';
  70. document.arrive(elementToWatch, function () {
  71. addInfo();
  72. });
  73.  
  74. if(document.getElementsByClassName("InfoBar__username")[0]) addInfo();