Hide Bot Comments

Removes comments made by bots on websites such as YouTube.

当前为 2022-08-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Bot Comments
  3. // @namespace https://theusaf.org
  4. // @version 1.11.2
  5. // @description Removes comments made by bots on websites such as YouTube.
  6. // @author theusaf
  7. // @match https://www.youtube.com/**
  8. // @match https://www.facebook.com/plugins/comments.php*
  9. // @match https://www.facebook.com/plugins/feedback.php*
  10. // @copyright 2022 theusaf
  11. // @license MIT
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. const SITES = Object.freeze({
  16. YOUTUBE: {
  17. hostname: "www.youtube.com",
  18. checks: [
  19. // starts with too much whitespace
  20. /^\s{2,}/,
  21. // only links and other punctuation
  22. /^(\s*@.+)?\s*(https:\/\/[^\s]+)(https:\/\/[^\s]+|\n.\s])+$/,
  23. // all caps and a link
  24. /^(\s*@.+)?\s*[A-Z\s\r\n!]*https:\/\/[^\s]+[A-Z\s\r\n!]*$/,
  25. // A link and a random message afterwards
  26. /^(\s*@.+)?\s*https:\/\/[^\s]+(\n|.|\s)*(It'll blow your mind\.|[dD]on'?t [mM]iss|Bots for u|Finally|💜|fax|only until|Bots are|:]|\.\.?\.$|I found it :|Do not miss this|:)|Ye[sp] ¤? (true|exactly)/i,
  27. // word + link
  28. /^(\s*@.+)?\s*(This|[Ww]ow!?|Last fight|Yo)\s*https:\/\/[^\s]+/,
  29. // phrase + line + link
  30. /(is a brain burner.*|10,000.*?!|by having this:|it.?s finally here|Finally it's here\.?(\s*YES)?|deceives.*subscribers:\.{1,}|you .*will never love.*|[\u0401\u0451\u0410-\u044f,.:]{15,}.*|HOW STRONG IS KETTLE\?!|EXPOSED:|IS FREAK!|IS GARBAGE!{1,}|shocking truth.*|his subscribers.*|will stop watching.*|yes\.?|THE GAME.*|After watching this video you will never love.*)(\n|\s)(\n|.)*https:\/\/[^\s]+/,
  31. // link + random "word"
  32. /^(\s*@.+)?\s*https:\/\/[^\s]+\s*[a-z]+\s*$/,
  33. // link with a star at the end??
  34. /https:\/\/youtu.be\/\w+\*/,
  35. // ...
  36. /SWEET-GIRL|xvideos|specialdate|HOTGIRL|PRIVATE S\*X|over 18|Anna is a beautiful girl|adult porn videos/i,
  37. // suspicious websites
  38. /beautyzone\.\w+|[a-z]+\.online|\.cam|lust\.\w+|[a-z]+\.monster|\.host|\.uno|\.fun|asian\w*\.\w+|she.*\.online|\w*teen\.\w+/i,
  39. // too many "-"
  40. /-{5,}/,
  41. // single, somewhat strange word
  42. /^(Hii|Ye|Bruhh|Aawww?|🆁🆄🅷\s?!*)$/,
  43. // common phrase
  44. /I'm not scared of ghosts,? and you\?|SCREAMING IN H[E3]LL BECAUSE MY.*?BETTER|I MADE.*VIDS|is bad i make better content|оп му с[hН]аппе[ІlL]|I MAKE.*CONTENT|my videos are better|^I.m better than|I UPLOAD.*VIDEO|I (make|made).*(video|content)| (● ´ω ●) ✨💕|[Oo]mg.*it.?s finally here|I POST [A-Z\s]*?VIDEOS|HATE COMMENT|I can read you mind brother|SPECIAL FOR YOU|l1ke my v1deo|small channel trying to grow| YouT\*ber|MY CONTENT|MY NAME|at my profile|My video|pedophile😱|MY WORLD RECORD|(^Yes.{0,5}$)|said this to a fan|Read my name|[Mm]y mom.*subscribers|r[\.\s]e[\.\s]a[\.\s]d[\.\s]? m[\.\s]y[\.\s]? n[\.\s]a[\.\s]m[\.\s]e|literally begging|MY VIDEOS?|my playlist|fucking cringe|[Dd][Oo][Nn].?[Tt] read my name/,
  45. // replies to bots/about bots
  46. /When the bots|@.*a bot|@Don'?t read my|@.*ok.*[Ii].*wont|remove bots|^(ro)?bot+$|with bots|hi bot|bots.*get worse|why are.*bots|bots.*everywhere|bot repl.*row|there are.{0,15}bots|oh god.*bots|report.*bots|so many.*?bots|holy bots|do nothing about bots|bots.*common/i,
  47. // upside down chars
  48. /[ㄥϛㄣƐᄅƖ⅄Λ∩┴ɹԀ˥ʞſפℲƎƆ∀ʎʍʌʇɹɯʞɾᴉɥƃɟǝɔɐ]/,
  49. // just a single, weird character
  50. /^.$/s,
  51. // invisible characters
  52. /[\u200e]/u,
  53. (text) => {
  54. const matches = text.match(/[\u{0E80}-\u{0EFF}]/gu)?.length ?? 0;
  55. if (matches / text.length > 0.5 && /Don.?t tran?slate|Do not tran?slate/i.test(text)) {
  56. return true;
  57. }
  58. },
  59. (text) => {
  60. const charSets = [
  61. {
  62. regex: /[\u{fe27}-\u{fe2f}\u{1df5}-\u{1dff}\u{1dc0}-\u{1de6}\u{1ab0}-\u{1abe}\u{0300}-\u{0333}\u{0339}-\u{033f}\u{0346}-\u{034a}\u{034b}-\u{034e}\u{0350}-\u{0357}\u{0358}-\u{035b}]/gu, // weird combining characters
  63. matchPercent: 0.4
  64. },
  65. {
  66. regex: /[ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘᴏ̨ʀsᴛᴜᴠᴡxʏᴢ\s]/g,
  67. matchPercent: 0.5
  68. },
  69. {
  70. regex: /[\u{1D538}-\u{1D56B}\u{1D400}-\u{1D433}]/gu, // math letter symbols
  71. matchPercent: 0.3
  72. }
  73. ];
  74. for (const check of charSets) {
  75. const { regex, matchPercent } = check,
  76. matches = text.match(regex)?.length ?? 0;
  77. if (matches / text.length > matchPercent && text.length > 10) {
  78. return true;
  79. }
  80. }
  81. }
  82. ],
  83. getCommentText(node) {
  84. if (node.nodeName === "YTD-COMMENT-RENDERER") {
  85. return node.querySelector("#content-text").textContent;
  86. }
  87. }
  88. },
  89. FACEBOOK_EMBED: {
  90. hostname: "www.facebook.com",
  91. checks: [
  92. // "Easy cash" scams
  93. /easy cash|earning money is very easy.*https?:\/\/|work online|real passive income|(making|paid|get) over \$?\d+k?|salary from home/s,
  94. // Scammy manga sites
  95. /(I liked it.*?recommend|try this manga.*?https?s:\/\/|you should try:|[Ss]hare a cartoon website|top [a-z]*?(comic|website)|there is no cost|try this one out|[Jj]ust read this|you [a-z\s]*?want [a-z\s]*?manga|(tons|a lot) of [a-z\s]*?man[gh][wu]?a|You can find the last part here|looking forward to seeing where this goes|YET ANOTHER RECOMMENDATION|enjoy another manga|I prefer this type of comic|hottest comics|Google led me|will love this one|I like this one: |FEE IS FREE|another [a-z\s]*?manga|WEBSITE[A-Z\s]*FREE|good read|must check this out|read more:|300 or more chapters|comics for free|website [a-z\s]*?manga:|favorite mange which I have read|\*{1,} SPOILER ALERT \*{1,}|FREE ACCESS|FREE (TO|FOR) READ).*(\n\s)*(https?:\/\/[^\s]+|\n.\s])+/,
  96. /geoagiphy\.com|.giphy\.com/,
  97. /(manga|story|site|website).*?:\s?(https?:\/\/[^\s]+|\n.\s])+$/,
  98. // Other weird comments/scams
  99. /look at a website|very popular .*?website|Amazon gift card/,
  100. /^i love sex$/
  101. ],
  102. options: {
  103. initialScan: () => {
  104. return document.querySelectorAll(".clearfix");
  105. }
  106. },
  107. getCommentText(node) {
  108. if (node.classList?.contains("clearfix")) {
  109. try {
  110. return node?.lastElementChild
  111. .lastElementChild
  112. .lastElementChild
  113. .firstElementChild
  114. .children[1]
  115. .textContent;
  116. } catch (err) {
  117. return null;
  118. }
  119. }
  120. }
  121. }
  122. }),
  123. site = getCurrentSite(),
  124. commentMutationListener = new MutationObserver((mutations) => {
  125. for (const mutation of mutations) {
  126. for (const node of mutation.addedNodes) {
  127. const text = site.getCommentText(node);
  128. if (text) {
  129. if (isCommentLikelyBotComment(text, site)) {
  130. node.style.display = "none";
  131. }
  132. }
  133. }
  134. }
  135. });
  136.  
  137. commentMutationListener.observe(document.body, {
  138. subtree: true,
  139. childList: true
  140. });
  141.  
  142. /**
  143. * Determines whether a comment is likely spam.
  144. *
  145. * @param {String} text The comment's content
  146. * @param {Object} site The website the comment is from
  147. * @return {Boolean}
  148. */
  149. function isCommentLikelyBotComment(text, site) {
  150. for (const check of site.checks) {
  151. if (typeof check === "function") {
  152. if (check(text)) {
  153. console.log("Filter Check Failed");
  154. console.log(text);
  155. return true;
  156. }
  157. } else {
  158. // assume regex
  159. if (check.test(text)) {
  160. console.log("Regex Check Failed");
  161. console.log(check);
  162. console.log(text);
  163. return true;
  164. }
  165. }
  166. }
  167. return false;
  168. }
  169.  
  170. function getCurrentSite() {
  171. for (let key in SITES) {
  172. const site = SITES[key];
  173. if (location.hostname === site.hostname) {
  174. return site;
  175. }
  176. }
  177. }
  178.  
  179. if (site.options?.initialScan) {
  180. const items = site.options.initialScan();
  181. for (const node of items) {
  182. const text = site.getCommentText(node);
  183. if (text) {
  184. if (isCommentLikelyBotComment(text, site)) {
  185. node.style.display = "none";
  186. }
  187. }
  188. }
  189. }