Always-Off Ping Reply

Adds an option in the reply bar to keep reply pings off automatically.

目前为 2022-07-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Always-Off Ping Reply
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description Adds an option in the reply bar to keep reply pings off automatically.
  6. // @author TheVoidUnknown
  7. // @match https://discord.com/channels/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=discord.com
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. jQuery(function($){
  18.  
  19. let toggle = GM_getValue('toggle');
  20. let css
  21. let html
  22.  
  23. if (toggle == null) { // Set toggle switch to true when running for the first time
  24. GM_setValue('toggle', true);
  25. toggle = true
  26. }
  27.  
  28. function define() {
  29. css = `
  30. .switch {
  31. position: relative;
  32. display: inline-block;
  33. width: 35px;
  34. height: 20px;
  35. }
  36.  
  37. .switch input {
  38. opacity: 0;
  39. width: 0;
  40. height: 0;
  41. }
  42.  
  43. .slider {
  44. position: absolute;
  45. cursor: pointer;
  46. top: 0;
  47. left: 0;
  48. right: 0;
  49. bottom: 0;
  50. background-color: var(--text-muted);
  51. -webkit-transition: .4s;
  52. transition: .4s;
  53. }
  54.  
  55. .slider:before {
  56. position: absolute;
  57. content: "";
  58. height: 16px;
  59. width: 16px;
  60. left: 2px;
  61. bottom: 2px;
  62. background-color: var(--text-normal);
  63. -webkit-transition: .4s;
  64. transition: .4s;
  65. }
  66.  
  67. input:checked + .slider {
  68. background-color: var(--text-link);
  69. }
  70.  
  71. input:focus + .slider {
  72. box-shadow: 0 0 1px #2196F3;
  73. }
  74.  
  75. input:checked + .slider:before {
  76. -webkit-transform: translateX(15px);
  77. -ms-transform: translateX(15px);
  78. transform: translateX(15px);
  79. }
  80.  
  81. .slider.round {
  82. border-radius: 34px;
  83. }
  84.  
  85. .slider.round:before {
  86. border-radius: 50%;
  87. }
  88. `
  89.  
  90. html = `
  91. <div id="alwaysOffPings_wrapper" style="padding: 8px;">
  92. <label id="infoTxt" style="
  93. font-family: var(--font-primary);
  94. font-size: 14px;
  95. line-height: 18px;
  96. color: var(--header-secondary);
  97. ">Always Off Pings:
  98. </label>
  99.  
  100. <label class="switch" id="alwaysOffPings">
  101. <input type="checkbox" id="switchCheckBox" checked=${toggle}>
  102. <span class="slider round"></span>
  103. </label>
  104. </div>
  105.  
  106. <div class="separator" style="width: 1px; height: 20px; background-color: var(--background-modifier-accent);" aria-hidden="true"></div>`
  107. }
  108. define();
  109. // ^ This function is solely to let me minimize these 50 lines
  110.  
  111. let style = document.createElement("style");
  112. style.id = "epicStyle";
  113. style.innerHTML = css;
  114. document.head.append(style)
  115.  
  116.  
  117.  
  118. // No. Dont say it. I was too lazy to do it the right way.
  119. // If it works it works
  120. let loop = setInterval(function(){
  121.  
  122. let replyBar = document.querySelector('[class^="actions"]');
  123. let checkbox = document.querySelector('#switchCheckBox');
  124. let mention = document.querySelector('[class*="mentionButton"]');
  125.  
  126. try{checkbox.addEventListener('change', (event) => {
  127. GM_setValue('toggle',checkbox.checked);
  128. toggle = GM_getValue('toggle');
  129. })}catch{};
  130.  
  131. if (replyBar!=null && checkbox==null) {
  132. $('[class*="actions"]').prepend(html);
  133. } else if (replyBar!=null && mention.parentElement.ariaChecked == "true" && toggle==true){
  134. mention.parentElement.click();
  135. } else if (replyBar!=null && toggle==false) {
  136. mention.parentElement.style.display = 'block'
  137. } else if (replyBar!=null && toggle==true) {
  138. mention.parentElement.style.display = 'none'
  139. };
  140.  
  141. },10);
  142.  
  143. })})();