[Reddit] ModmailExtraInfo

Shows additional user information on the sidebar of modmail

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

  1. // ==UserScript==
  2. // @name [Reddit] ModmailExtraInfo
  3. // @namespace HKR
  4. // @match https://mod.reddit.com/mail/*
  5. // @grant none
  6. // @version 1.2
  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 textColor = "#6e6e6e";
  15. var dataColor = "#0079d3";
  16.  
  17. function Get(url) {
  18. var xmlHttp = new XMLHttpRequest();
  19. xmlHttp.open( "GET", url, false );
  20. xmlHttp.send( null );
  21. return xmlHttp.responseText;
  22. }
  23.  
  24. function time(UNIX_timestamp){
  25. var a = new Date(UNIX_timestamp * 1000);
  26. var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  27. var year = a.getFullYear();
  28. var month = months[a.getMonth()];
  29. var date = a.getDate();
  30. var hour = fixnumber(a.getHours());
  31. var min = fixnumber(a.getMinutes());
  32. var sec = fixnumber(a.getSeconds());
  33. var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
  34. return time;
  35. }
  36.  
  37. function fixnumber(number) {
  38. if(number < 10) return "0" + number;
  39. else return number;
  40. }
  41.  
  42. function addCSS(cssCode) {
  43. var styleElement = document.createElement("style");
  44. styleElement.type = "text/css";
  45. if (styleElement.styleSheet) {
  46. styleElement.styleSheet.cssText = cssCode;
  47. } else {
  48. styleElement.appendChild(document.createTextNode(cssCode));
  49. }
  50. document.getElementsByTagName("head")[0].appendChild(styleElement);
  51. }
  52.  
  53. function sanitize(evilstring) {
  54. const decoder = document.createElement('div')
  55. decoder.innerHTML = evilstring;
  56. return decoder.textContent;
  57. }
  58. addCSS(".profileIcon:hover {-ms-transform: scale(6); -webkit-transform: scale(6); transform: scale(6);}");
  59. addCSS(".profileIcon {position: relative; bottom: 4px;}");
  60. addCSS(".InfoBar__recentsNone {color: #6e6e6e;}");
  61. addCSS(".InfoBar__metadata, .InfoBar__recents { margin: 6px 0; margin-left: 10px;}");
  62. addCSS(".value {color:"+ dataColor +";}");
  63. addCSS(".InfoBar__banText {padding-bottom: 15px;}");
  64. addCSS(".InfoBar__username, .InfoBar__username:visited {padding-left: 10px;}");
  65. addCSS(".ThreadViewer__infobarContainer {display: table;}");
  66.  
  67. function addInfo(){
  68. var username = document.getElementsByClassName("InfoBar__username")[0].innerText;
  69. var about = "https://www.reddit.com/user/" + username +"/about.json";
  70.  
  71. var user = JSON.parse(Get(about));
  72.  
  73. var seperator = document.createElement('div');
  74. seperator.innerHTML = '<div class="InfoBar__modActions">'
  75. + '</div>';
  76.  
  77. var userDetails = document.createElement('div');
  78. userDetails.innerHTML = '<div class="InfoBar__age">'
  79. + '<img class="profileIcon" style="margin-bottom: 10px; float: left; border-radius: 50%; transition: transform .2s;" src="' + user.data.icon_img + '" width="25">'
  80. + '<a class="InfoBar__username" href="https://www.reddit.com/user/'+ user.data.name +'">' + user.data.subreddit.display_name_prefixed + '</a>'
  81. + '<h1 style="color: '+ textColor +'; font-size: 11px; margin-top: 17px; margin-bottom: 10px;">' + sanitize(user.data.subreddit.public_description) + '</h1>'
  82. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Main</h1>'
  83. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Created: <span class="value">' + time(user.data.created) + '</span></p>'
  84. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">UserID: <span class="value">' + user.data.id + '</span></p>'
  85. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Verified: <span class="value">' + user.data.verified + '</span></p>'
  86. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Employee: <span class="value">' + user.data.is_employee + '</span></p>'
  87. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">NSFW Profile: <span class="value">' + user.data.subreddit.over_18 + '</span></p>'
  88. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-top: 5px; margin-bottom: 3px;">Karma</h1>'
  89. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Post: <span class="value">' + user.data.link_karma + '</span></p>'
  90. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Comment: <span class="value">' + user.data.comment_karma + '</span></p>'
  91. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Total: <span class="value">' + user.data.total_karma + '</span></p>'
  92. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Awardee: <span class="value">' + user.data.awardee_karma + '</span></p>'
  93. + '<p style="color: '+ textColor +'; font-size: 13px; padding-left: 10px;">Awarder: <span class="value">' + user.data.awarder_karma + '</span></p>'
  94.  
  95. + '<h1 style="color: #2c2c2c; font-size: 15px; margin-bottom: 3px; margin-top: 5px;">Links</h1>'
  96. + '<a style="padding-left: 10px;" class="InfoBar__recent" href="https://redditmetis.com/user/' + user.data.name + '" target="_blank">Redditmetis</a>'
  97. + '<a style="padding-left: 10px;" class="InfoBar__recent" href="https://www.reddit.com/search?q=' + user.data.name + '" target="_blank">Reddit Search</a>'
  98. + '<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>'
  99. + '</div>';
  100. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(seperator);
  101. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(userDetails);
  102. document.getElementsByClassName("ThreadViewer__infobar")[0].appendChild(document.getElementsByClassName("ThreadViewer__infobar")[0].firstChild);
  103. document.getElementsByClassName("InfoBar")[0].appendChild(document.getElementsByClassName("InfoBar__modActions")[0]);
  104. document.getElementsByClassName("InfoBar")[0].insertBefore(document.getElementsByClassName("InfoBar__modActions")[0],document.getElementsByClassName("InfoBar")[0].firstChild);
  105. if(document.getElementsByClassName("InfoBar__banText")[0])
  106. document.getElementsByClassName("ThreadViewer__infobar")[0].insertBefore(document.getElementsByClassName("InfoBar__banText")[0],document.getElementsByClassName("ThreadViewer__infobar")[0].firstChild);
  107. document.getElementsByClassName("InfoBar__username")[1].outerHTML = "";
  108. document.getElementsByClassName("InfoBar__age")[1].outerHTML = "";
  109. document.getElementsByClassName("InfoBar__modActions")[1].outerHTML = "";
  110. //document.getElementsByClassName("InfoBar__modActions")[0].outerHTML = document.getElementsByClassName("InfoBar__modActions")[0].outerHTML + "<div class=\"InfoBar__modActions\"></div>";
  111. }
  112.  
  113. const elementToWatch = 'a[class="InfoBar__username"]';
  114. document.arrive(elementToWatch, function () {
  115. addInfo();
  116. });
  117.  
  118. if(document.getElementsByClassName("InfoBar__username")[0]) addInfo();