ModmailAdditionalInfo

Shows additional user information on the sidebar of modmail

目前為 2021-07-22 提交的版本,檢視 最新版本

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