Hide Bot Comments

Removes comments made by bots on websites such as YouTube.

目前為 2022-03-22 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Hide Bot Comments
  3. // @namespace https://theusaf.org
  4. // @version 1.7.0
  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. checks: [
  18. // starts with too much whitespace
  19. /^\s{2,}/,
  20. // only links and other punctuation
  21. /^(\s*@.+)?\s*(https:\/\/[^\s]+)(https:\/\/[^\s]+|\n.\s])+$/,
  22. // all caps and a link
  23. /^(\s*@.+)?\s*[A-Z\s\r\n!]*https:\/\/[^\s]+[A-Z\s\r\n!]*$/,
  24. // A link and a random message afterwards
  25. /^(\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,
  26. // word + link
  27. /^(\s*@.+)?\s*(This|[Ww]ow!?)\s*https:\/\/[^\s]+/,
  28. // phrase + line + link
  29. /(Finally it's here\.?|deceives.*subscribers:\.{1,}|[\u0401\u0451\u0410-\u044f,.:]{15,}.*|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]+/,
  30. // link + random "word"
  31. /^(\s*@.+)?\s*https:\/\/[^\s]+\s*[a-z]+\s*$/,
  32. // link with a star at the end??
  33. /https:\/\/youtu.be\/\w+\*/,
  34. // ...
  35. /PRIVATE S\*X|over 18|Anna is a beautiful girl/i,
  36. // suspicious websites
  37. /beautyzone\.\w+|\.cam|lust\.\w+|\.host|asian\w*\.\w+|\w*teen\.\w+/i,
  38. // too many "-"
  39. /-{5,}/,
  40. // single, somewhat strange word
  41. /^(Hii|Ye|Bruhh|Aawww?)$/,
  42. // common phrase
  43. / (● ´ω ●) ✨💕|I can read you mind brother|SPECIAL FOR YOU|l1ke my v1deo|small channel trying to grow| YouT\*ber|MY CONTENT|My video|pedophile😱|MY WORLD RECORD|(^Yes.{0,5}$)|said this to a fan|Read my name|[Mm]y mom.*subscribers|literally begging|MY VIDEOS?|my playlist|fucking cringe|[Dd][Oo][Nn]'?[Tt] read my name/,
  44. // replies to bots
  45. /@Don'?t read my|^(ro)?bot+$/i,
  46. // upside down chars
  47. /[ㄥϛㄣƐᄅƖ⅄Λ∩┴ɹԀ˥ʞſפℲƎƆ∀ʎʍʌʇɹɯʞɾᴉɥƃɟǝɔɐ]/,
  48. // just a single, weird character
  49. /^.$/,
  50. (text) => {
  51. const charSets = [
  52. {
  53. 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
  54. matchPercent: 0.4
  55. },
  56. {
  57. regex: /[ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘᴏ̨ʀsᴛᴜᴠᴡxʏᴢ\s]/g,
  58. matchPercent: 0.5
  59. },
  60. {
  61. regex: /[\u{1D538}-\u{1D56B}\u{1D400}-\u{1D433}]/gu, // math letter symbols
  62. matchPercent: 0.3
  63. },
  64. ];
  65. for (const check of charSets) {
  66. const { regex, matchPercent } = check,
  67. matches = text.match(regex)?.length ?? 0;
  68. if (matches / text.length > matchPercent && text.length > 10) {
  69. return true;
  70. }
  71. }
  72. }
  73. ]
  74. },
  75. FACEBOOK_EMBED: {
  76. checks: [
  77. // "Easy cash" scams
  78. /easy cash|work online/
  79. ],
  80. options: {
  81. initialScan: () => {
  82. return document.querySelectorAll(".clearfix");
  83. }
  84. }
  85. }
  86. }),
  87. site = getCurrentSite(),
  88. commentMutationListener = new MutationObserver((mutations) => {
  89. for (const mutation of mutations) {
  90. for (const node of mutation.addedNodes) {
  91. const text = getCommentText(node, site);
  92. if (text) {
  93. if (isCommentLikelyBotComment(text, site)) {
  94. node.style.display = "none";
  95. }
  96. }
  97. }
  98. }
  99. });
  100.  
  101. commentMutationListener.observe(document.body, {
  102. subtree: true,
  103. childList: true
  104. });
  105.  
  106. /**
  107. * Determines whether a comment is likely spam.
  108. *
  109. * @param {String} text The comment's content
  110. * @param {Object} site The website the comment is from
  111. * @return {Boolean}
  112. */
  113. function isCommentLikelyBotComment(text, site) {
  114. for (const check of site.checks) {
  115. if (typeof check === "function") {
  116. if (check(text)) {
  117. console.log("Filter Check Failed");
  118. console.log(text);
  119. return true;
  120. }
  121. } else {
  122. // assume regex
  123. if (check.test(text)) {
  124. console.log("Regex Check Failed");
  125. console.log(check);
  126. console.log(text);
  127. return true;
  128. }
  129. }
  130. }
  131. return false;
  132. }
  133.  
  134. function getCommentText(node, site) {
  135. switch (site) {
  136. case SITES.YOUTUBE: {
  137. if (node.nodeName === "YTD-COMMENT-RENDERER") {
  138. return node.querySelector("#content-text").textContent;
  139. }
  140. break;
  141. }
  142. case SITES.FACEBOOK_EMBED: {
  143. if (node.classList?.contains("clearfix")) {
  144. try {
  145. return node?.lastElementChild
  146. .lastElementChild
  147. .lastElementChild
  148. .firstElementChild
  149. .children[1]
  150. .textContent;
  151. } catch (err) {
  152. return null;
  153. }
  154. }
  155. }
  156. }
  157. return null;
  158. }
  159.  
  160. function getCurrentSite() {
  161. switch (location.hostname) {
  162. case "www.youtube.com": {
  163. return SITES.YOUTUBE;
  164. }
  165. case "www.facebook.com": {
  166. return SITES.FACEBOOK_EMBED;
  167. }
  168. }
  169. }
  170.  
  171. if (site.options?.initialScan) {
  172. const items = site.options.initialScan();
  173. for (const node of items) {
  174. const text = getCommentText(node, site);
  175. if (text) {
  176. if (isCommentLikelyBotComment(text, site)) {
  177. node.style.display = "none";
  178. }
  179. }
  180. }
  181. }