Greasy Fork is available in English.

Hide Bot Comments

Removes comments made by bots on websites such as YouTube.

  1. // ==UserScript==
  2. // @name Hide Bot Comments
  3. // @namespace https://theusaf.org
  4. // @version 1.14.3
  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)*(Here'?s the full video.*?this video|It'll blow your mind\.|This is where (the )?world'?s first " ?Rick Rolled" started\.?|[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. /((Here is the final video|Here'?s the clip thank|Here is the (full|trending) clip|^Link to the clip|Finally.*?the clip u all|is a brain burner|Let'?s be honest we|LET'?S BE HONEST WE|I have been waiting so long|by having this:|[iI]t.?s finally here|Finally.*is finally here|it is finally there|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|THE GAME|After watching this video you will never love).*|(yes\.?|deceives.*subscribers:\.{1,}|Finally it'?s here\.?(\s*YES)?)|^Link to the clip part 2|10,000.*?!|This is the [Cc]lip u all.*:|Link to the clip\.? [Tt]hank me later|^Here you go|^yo\b|full vid -|\*YO\*🔥|GOLUM:)(\n|\s)(\n|.)*https:\/\/[^\s]+/,
  31. // various languages + line + link
  32. /^[\p{Script=Cyrillic}\s!\.]*(\n|\s)(\n|.)*https:\/\/((www|m)\.)?youtu[^\s]+/iu,
  33. // link + random "word"
  34. /^(\s*@.+)?\s*https:\/\/[^\s]+\s*[a-z]+\s*$/,
  35. // link with a star at the end??
  36. /https:\/\/youtu.be\/\w+\*/,
  37. // ...
  38. /SWEET-GIRL|xvideos|specialdate|HOTGIRL|PRIVATE S\*X|over 18|Anna is a beautiful girl|adult porn videos/i,
  39. // suspicious websites
  40. /beautyzone\.\w+|[a-z]+\.online|\.cam|lust\.\w+|[a-z]+\.monster|\.host|\.uno|\.fun|asian\w*\.\w+|she.*\.online|\w*teen\.\w+/i,
  41. // too many "-"
  42. /-{5,}/,
  43. // single, somewhat strange word
  44. /^([ĤHh]ii|Ye|[Bb]ruhh|[Aa]awww?|🆁🆄🅷\s?!*)$/,
  45. // common phrase
  46. /Send(.|\n)*?direct message(.|\n)*?(won a gift|your prize)|BECOME THE MOST HATED|Thanks for watching..? messages|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|I AM THE BEE?ST YOUU?TUBER|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/,
  47. // replies to bots/about bots
  48. /they are bots|get out.*bots|full of bots|bots be like|all these bots|the bots.*not|already bots|When the bots|@.*a bot|@Don'?t read|@.*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,
  49. // upside down chars
  50. /[ㄥϛㄣƐᄅƖ⅄Λ∩┴ɹԀ˥ʞſפℲƎƆ∀ʎʍʌʇɹɯʞɾᴉɥƃɟǝɔɐ]/,
  51. // just a single, weird character
  52. /^.$/s,
  53. // invisible characters
  54. /[\u200e]/u,
  55. (text) => {
  56. const matches = text.match(/[\u{0E80}-\u{0EFF}]/gu)?.length ?? 0;
  57. if (
  58. matches / text.length > 0.5 &&
  59. /Don.?t tran?slate|Do not tran?slate/i.test(text)
  60. ) {
  61. return true;
  62. }
  63. },
  64. (text) => {
  65. const charSets = [
  66. {
  67. regex:
  68. /[\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
  69. matchPercent: 0.4,
  70. },
  71. {
  72. regex: /[ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘᴏ̨ʀsᴛᴜᴠᴡxʏᴢ\s]/g,
  73. matchPercent: 0.5,
  74. },
  75. {
  76. regex: /[\u{1D538}-\u{1D56B}\u{1D400}-\u{1D433}]/gu, // math letter symbols
  77. matchPercent: 0.3,
  78. },
  79. ];
  80. for (const check of charSets) {
  81. const { regex, matchPercent } = check,
  82. matches = text.match(regex)?.length ?? 0;
  83. if (matches / text.length > matchPercent && text.length > 10) {
  84. return true;
  85. }
  86. }
  87. },
  88. // Username checks
  89. (_, node) => {
  90. const usernameNode = node.querySelector("#author-text"),
  91. userImage = node.querySelector("#img"),
  92. username = usernameNode.textContent.trim(),
  93. BAD_NAMES = [
  94. // remove
  95. /^SUB FOR SUB$/,
  96. ],
  97. HIDE_NAMES = [
  98. // don't remove, just hide pic and name
  99. ];
  100. for (const regex of BAD_NAMES) {
  101. if (regex.test(username)) {
  102. return true;
  103. }
  104. }
  105. for (const regex of HIDE_NAMES) {
  106. if (regex.test(username)) {
  107. userImage.src = "data:application/svg+xml,<svg></svg>";
  108. }
  109. }
  110. return false;
  111. },
  112. ],
  113. getCommentText(node) {
  114. if (node.nodeName === "YTD-COMMENT-RENDERER") {
  115. return node.querySelector("#content-text").textContent;
  116. }
  117. },
  118. },
  119. FACEBOOK_EMBED: {
  120. hostname: "www.facebook.com",
  121. checks: [
  122. // "Easy cash" scams
  123. /easy cash|earning money is very easy.*https?:\/\/|work online|real passive income|(making|paid|get) over \$?\d+k?|salary from home/s,
  124. // Scammy manga sites
  125. /(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])+/,
  126. /geoagiphy\.com|.giphy\.com/,
  127. /(manga|story|site|website).*?:\s?(https?:\/\/[^\s]+|\n.\s])+$/,
  128. // Other weird comments/scams
  129. /look at a website|very popular .*?website|Amazon gift card/,
  130. /^i love sex$/,
  131. ],
  132. options: {
  133. initialScan: () => {
  134. return document.querySelectorAll(".clearfix");
  135. },
  136. },
  137. getCommentText(node) {
  138. if (node.classList?.contains("clearfix")) {
  139. try {
  140. return node?.lastElementChild.lastElementChild.lastElementChild
  141. .firstElementChild.children[1].textContent;
  142. } catch (err) {
  143. return null;
  144. }
  145. }
  146. },
  147. },
  148. }),
  149. site = getCurrentSite(),
  150. commentMutationListener = new MutationObserver((mutations) => {
  151. for (const mutation of mutations) {
  152. for (const node of mutation.addedNodes) {
  153. const text = site.getCommentText(node);
  154. if (text) {
  155. if (isCommentLikelyBotComment(text, site, node)) {
  156. node.style.display = "none";
  157. }
  158. }
  159. }
  160. }
  161. });
  162.  
  163. commentMutationListener.observe(document.body, {
  164. subtree: true,
  165. childList: true,
  166. });
  167.  
  168. /**
  169. * Determines whether a comment is likely spam.
  170. *
  171. * @param {string} text The comment's content
  172. * @param {object} site The website the comment is from
  173. * @param {Node} node
  174. * @return {Boolean}
  175. */
  176. function isCommentLikelyBotComment(text, site, node) {
  177. for (const check of site.checks) {
  178. if (typeof check === "function") {
  179. if (check(text, node)) {
  180. console.log("Filter Check Failed");
  181. console.log(text);
  182. return true;
  183. }
  184. } else {
  185. // assume regex
  186. if (check.test(text)) {
  187. console.log("Regex Check Failed");
  188. console.log(check);
  189. console.log(text);
  190. return true;
  191. }
  192. }
  193. }
  194. return false;
  195. }
  196.  
  197. function getCurrentSite() {
  198. for (let key in SITES) {
  199. const site = SITES[key];
  200. if (location.hostname === site.hostname) {
  201. return site;
  202. }
  203. }
  204. }
  205.  
  206. if (site.options?.initialScan) {
  207. const items = site.options.initialScan();
  208. for (const node of items) {
  209. const text = site.getCommentText(node);
  210. if (text) {
  211. if (isCommentLikelyBotComment(text, site, node)) {
  212. node.style.display = "none";
  213. }
  214. }
  215. }
  216. }