Discord 回復时自动移除标注

Discord 回復时自动移除标注。

  1. // ==UserScript==
  2. // @name Discord Auto remove mention when reply
  3. // @name:zh-TW Discord 回覆時自動移除標註
  4. // @name:zh-CN Discord 回復时自动移除标注
  5. // @name:ja Discord 返信時にメンションを自動的に削除
  6. // @namespace https://gf.qytechs.cn/zh-TW/users/142344-jasn-hr
  7. // @description Discord Auto remove mention when reply.
  8. // @description:zh-TW Discord 回覆時自動移除標註。
  9. // @description:zh-CN Discord 回復时自动移除标注。
  10. // @description:ja Discord 返信時にメンションを自動的に削除。
  11. // @copyright 2022, HrJasn (https://gf.qytechs.cn/zh-TW/users/142344-jasn-hr)
  12. // @license MIT
  13. // @version 1.5
  14. // @icon https://www.google.com/s2/favicons?domain=discord.com
  15. // @match http*://discord.com/*
  16. // @exclude http*://www.google.com/*
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. console.log("Discord Auto remove mention when reply.");
  21.  
  22. window.addEventListener('load', () =>{
  23. let messageLocalize = (messageJson) => {
  24. let userLocale = navigator.userLanguage || navigator.language || navigator.browserLanguage || navigator.systemLanguage
  25. return messageJson[userLocale];
  26. };
  27. const observeDOM = (()=>{
  28. const ObSrvDomMut = window.MutationObserver || window.WebKitMutationObserver;
  29. return (obj,callback)=>{
  30. if( !obj || obj.nodeType !== 1 ) {return;}
  31. if( ObSrvDomMut ) {
  32. const mutObserver = new ObSrvDomMut(callback);
  33. mutObserver.observe( obj, { childList:true, subtree:true });
  34. return mutObserver;
  35. } else if( window.addEventListener ) {
  36. obj.addEventListener('DOMNodeInserted', callback, false);
  37. obj.addEventListener('DOMNodeRemoved', callback, false);
  38. }
  39. }
  40. })();
  41. observeDOM(document.body, function(docElms){
  42. let addedNodes = [];
  43. docElms.forEach(record => record.addedNodes.length & addedNodes.push(...record.addedNodes));
  44. changeProdIDtoLink(this,addedNodes);
  45. });
  46. function changeProdIDtoLink(observeOBJ,addedNodes){
  47. let setCookie = (name,value,days) => {
  48. var expires = "";
  49. if (days) {
  50. var date = new Date();
  51. date.setTime(date.getTime() + (days*24*60*60*1000));
  52. expires = "; expires=" + date.toUTCString();
  53. };
  54. document.cookie = name + "=" + (value || "") + expires + "; path=/";
  55. };
  56. let getCookie=(name) =>{
  57. var nameEQ = name + "=";
  58. var ca = document.cookie.split(';');
  59. for(var i=0;i < ca.length;i++) {
  60. var c = ca[i];
  61. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  62. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  63. };
  64. return null;
  65. };
  66. let eraseCookie=(name) =>{
  67. document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  68. };
  69. addedNodes.forEach((addedNode)=>{
  70. if(addedNode.querySelectorAll){
  71. addedNode.querySelectorAll('div[class*="replyBar"]').forEach((singleRow)=>{
  72. let MentionName = singleRow.querySelector('div[class*="replyLabel"] span[class*="name"]').innerText;
  73. let mentionButton = singleRow.querySelector('div[class*="mentionButton"]');
  74. function getAutoRemoveMentionUserList(){
  75. let UserListArr = [];
  76. try{
  77. let AutoRemoveMentionUserListCookie = getCookie('AutoRemoveMentionUserList');
  78. UserListArr = JSON.parse(AutoRemoveMentionUserListCookie);
  79. }catch(err){
  80. };
  81. if(!UserListArr){UserListArr = [];}
  82. return UserListArr;
  83. };
  84. function findMentionUserList(UserList,UserName){
  85. return UserList.find(u => {
  86. return u.name == UserName
  87. });
  88. };
  89. function removeFromMentionUserList(UserList,UserName){
  90. return UserList.filter(u => {
  91. if (u.name == UserName) {
  92. return false;
  93. };
  94. return true;
  95. });
  96. };
  97. function closeMention(){
  98. if(mentionButton.parentNode.getAttribute('aria-checked') == 'true'){
  99. mentionButton.click();
  100. };
  101. };
  102. function openMention(){
  103. if(mentionButton.parentNode.getAttribute('aria-checked') == 'false'){
  104. mentionButton.click();
  105. };
  106. };
  107. function loadAutoRemoveSetting(){
  108. let AutoRemoveMentionUserList = getAutoRemoveMentionUserList();
  109. let MentionName = singleRow.querySelector('div[class*="replyLabel"] span[class*="name"]').innerText;
  110. let AutoRemoveMentionButton = mentionButton.parentNode.parentNode.querySelector('#AutoRemoveMentionButton > div');
  111. if(findMentionUserList(AutoRemoveMentionUserList,MentionName)){
  112. AutoRemoveMentionButton.style = 'color: var(--text-link);';
  113. closeMention();
  114. } else {
  115. AutoRemoveMentionButton.style = 'color: var(--text-muted);';
  116. openMention();
  117. }
  118. }
  119. let checkMentionEvent = ()=>{
  120. let AutoRemoveMentionUserList = getAutoRemoveMentionUserList();
  121. let MentionName = singleRow.querySelector('div[class*="replyLabel"] span[class*="name"]').innerText;
  122. let AutoRemoveMentionButton = mentionButton.parentNode.parentNode.querySelector('#AutoRemoveMentionButton > div');
  123. if(findMentionUserList(AutoRemoveMentionUserList,MentionName)){
  124. let newAutoRemoveMentionUserList = removeFromMentionUserList(AutoRemoveMentionUserList,MentionName);
  125. setCookie('AutoRemoveMentionUserList',JSON.stringify(newAutoRemoveMentionUserList),null);
  126. newAutoRemoveMentionUserList = [];
  127. } else {
  128. let newUser = JSON.parse(JSON.stringify({'name':MentionName}));
  129. AutoRemoveMentionUserList.push(newUser);
  130. setCookie('AutoRemoveMentionUserList',JSON.stringify(AutoRemoveMentionUserList),null);
  131. }
  132. loadAutoRemoveSetting();
  133. }
  134. let AutoRemoveMentionButtonNameArray = {
  135. 'en':'@Auto remove this people\'s reply mention',
  136. 'zh-TW':'@自動移除此人的回覆標註',
  137. 'zh-CN':'@自动移除此人的回復标注',
  138. 'ja': '@この人の返信の言及を自動的に削除します'
  139. }
  140. let AutoRemoveMentionButton = mentionButton.parentNode.parentNode.insertBefore(mentionButton.parentNode.cloneNode(true),mentionButton.parentNode);
  141. AutoRemoveMentionButton.id = 'AutoRemoveMentionButton';
  142. AutoRemoveMentionButton.querySelector('div[class*="mentionButton"]').textContent = messageLocalize(AutoRemoveMentionButtonNameArray);
  143. AutoRemoveMentionButton.addEventListener('click',checkMentionEvent,false);
  144. loadAutoRemoveSetting();
  145. });
  146. }
  147. });
  148. };
  149. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址