Hide Bot Comments

Removes comments made by bots on websites such as YouTube.

当前为 2022-03-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Bot Comments
  3. // @namespace https://theusaf.org
  4. // @version 1.5.2
  5. // @description Removes comments made by bots on websites such as YouTube.
  6. // @author theusaf
  7. // @match https://www.youtube.com/**
  8. // @copyright 2022 theusaf
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const SITES = Object.freeze({
  14. YOUTUBE: [
  15. /^\s{2,}/, // starts with too much whitespace
  16. /^(\s*@.+)?\s*(https:\/\/[^\s]+)(https:\/\/[^\s]+|\n.\s])+$/, // only links and other punctuation
  17. /^(\s*@.+)?\s*[A-Z\s\r\n!]*https:\/\/[^\s]+[A-Z\s\r\n!]*$/, // all caps and a link
  18. /^(\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, // A link and a random message afterwards
  19. /^(\s*@.+)?\s*(This|[Ww]ow!?)\s*https:\/\/[^\s]+/, // word + link
  20. /(IS FREAK!|IS GARBAGE!{1,}|yes\.?|THE GAME.*|After watching this video you will never love.*)(\n|\s)(\n|.)*https:\/\/[^\s]+/, // phrase + line + link
  21. /^(\s*@.+)?\s*https:\/\/[^\s]+\s*[a-z]+\s*$/, // link + random "word"
  22. /PRIVATE S\*X|over 18|Anna is a beautiful girl/i, // ...
  23. /beautyzone\.\w+|\.cam|lust\.\w+|\.host/i, // suspicious websites
  24. /-{5,}/, // too many "-"
  25. /^(Hii|Ye|Bruhh)$/,
  26. /SPECIAL FOR YOU|MY CONTENT|MY WORLD RECORD|(^Yes.{0,5}$)|said this to a fan|[Mm]y mom.*subscribers|literally begging|MY VIDEOS?|fucking cringe|[Dd][Oo][Nn]'?[Tt] read my name/, // common phrase
  27. /[ㄥϛㄣƐᄅƖ⅄Λ∩┴ɹԀ˥ʞſפℲƎƆ∀ʎʍʌʇɹɯʞɾᴉɥƃɟǝɔɐ]/, // upside down chars
  28. /^.$/, // just a single, weird character
  29. (text) => {
  30. const charSets = [
  31. {
  32. 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
  33. matchPercent: 0.4
  34. },
  35. {
  36. regex: /[ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘᴏ̨ʀsᴛᴜᴠᴡxʏᴢ\s]/g,
  37. matchPercent: 0.5
  38. },
  39. {
  40. regex: /[\u{1D538}-\u{1D56B}\u{1D400}-\u{1D433}]/gu, // math letter symbols
  41. matchPercent: 0.3
  42. },
  43. ];
  44. for (const check of charSets) {
  45. const { regex, matchPercent } = check,
  46. matches = text.match(regex)?.length ?? 0;
  47. if (matches / text.length > matchPercent && text.length > 10) {
  48. return true;
  49. }
  50. }
  51. }
  52. ]
  53. }),
  54. site = getCurrentSite(),
  55. commentMutationListener = new MutationObserver((mutations) => {
  56. for (const mutation of mutations) {
  57. for (const node of mutation.addedNodes) {
  58. const text = getCommentText(node, site);
  59. if (text) {
  60. if (isCommentLikelyBotComment(text, site)) {
  61. node.style.display = "none";
  62. }
  63. }
  64. }
  65. }
  66. });
  67.  
  68. commentMutationListener.observe(document.body, {
  69. subtree: true,
  70. childList: true
  71. });
  72.  
  73. /**
  74. * Determines whether a comment is likely spam.
  75. *
  76. * @param {String} text The comment's content
  77. * @param {Object} site The website the comment is from
  78. * @return {Boolean}
  79. */
  80. function isCommentLikelyBotComment(text, siteChecks) {
  81. for (const check of siteChecks) {
  82. if (typeof check === "function") {
  83. if (check(text)) {
  84. return true;
  85. }
  86. } else {
  87. // assume regex
  88. if (check.test(text)) {
  89. return true;
  90. }
  91. }
  92. }
  93. return false;
  94. }
  95.  
  96. function getCommentText(node, site) {
  97. switch (site) {
  98. case SITES.YOUTUBE: {
  99. if (node.nodeName === "YTD-COMMENT-RENDERER") {
  100. return node.querySelector("#content-text").textContent;
  101. }
  102. }
  103. }
  104. return null;
  105. }
  106.  
  107. function getCurrentSite() {
  108. switch (location.hostname) {
  109. case "www.youtube.com": {
  110. return SITES.YOUTUBE;
  111. }
  112. }
  113. }