Skip to content

Commit 33e201e

Browse files
committed
feat(1.14.0): add username checks for youtube
1 parent ebea7b3 commit 33e201e

File tree

3 files changed

+80
-31
lines changed

3 files changed

+80
-31
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock.json
2+
node_modules

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "remove-bot-comments",
3+
"version": "1.14.0",
4+
"description": "Hide comments made by annoying bots on various websites.",
5+
"main": "removebots.user.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/theusaf/remove-bot-comments.git"
12+
},
13+
"author": "theusaf",
14+
"license": "MIT",
15+
"bugs": {
16+
"url": "https://github.com/theusaf/remove-bot-comments/issues"
17+
},
18+
"homepage": "https://github.com/theusaf/remove-bot-comments#readme",
19+
"devDependencies": {
20+
"prettier": "^2.7.1"
21+
}
22+
}

removebots.user.js

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Hide Bot Comments
33
// @namespace https://theusaf.org
4-
// @version 1.12.1
4+
// @version 1.14.0
55
// @description Removes comments made by bots on websites such as YouTube.
66
// @author theusaf
77
// @match https://www.youtube.com/**
@@ -23,11 +23,11 @@ const SITES = Object.freeze({
2323
// all caps and a link
2424
/^(\s*@.+)?\s*[A-Z\s\r\n!]*https:\/\/[^\s]+[A-Z\s\r\n!]*$/,
2525
// A link and a random message afterwards
26-
/^(\s*@.+)?\s*https:\/\/[^\s]+(\n|.|\s)*(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,
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,
2727
// word + link
2828
/^(\s*@.+)?\s*(This|[Ww]ow!?|Last fight|Yo)\s*https:\/\/[^\s]+/,
2929
// phrase + line + link
30-
/(Link to the clip\.? [Tt]hank me later|is a brain burner.*|^Link to the clip part 2|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]+/,
30+
/((Here'?s the clip thank|^Link to the clip|Finally.*?the clip u all|is a brain burner|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 clip u all.*:|Link to the clip\.? [Tt]hank me later|^Here you go|^yo\b|full vid -)(\n|\s)(\n|.)*https:\/\/[^\s]+/,
3131
// various languages + line + link
3232
/^[\p{Script=Cyrillic}\s!\.]*(\n|\s)(\n|.)*https:\/\/((www|m)\.)?youtu[^\s]+/iu,
3333
// link + random "word"
@@ -41,11 +41,11 @@ const SITES = Object.freeze({
4141
// too many "-"
4242
/-{5,}/,
4343
// single, somewhat strange word
44-
/^(Hii|Ye|Bruhh|Aawww?|🆁🆄🅷\s?!*)$/,
44+
/^([ĤHh]ii|Ye|[Bb]ruhh|[Aa]awww?|🆁🆄🅷\s?!*)$/,
4545
// common phrase
46-
/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/,
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|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/,
4747
// replies to bots/about bots
48-
/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,
48+
/already bots|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,
4949
// upside down chars
5050
/[ϛƐƖΛɹԀ˥ʞſפƎƆʎʍʌʇɹɯʞɾɥƃɟǝɔɐ]/,
5151
// just a single, weird character
@@ -54,24 +54,28 @@ const SITES = Object.freeze({
5454
/[\u200e]/u,
5555
(text) => {
5656
const matches = text.match(/[\u{0E80}-\u{0EFF}]/gu)?.length ?? 0;
57-
if (matches / text.length > 0.5 && /Don.?t tran?slate|Do not tran?slate/i.test(text)) {
57+
if (
58+
matches / text.length > 0.5 &&
59+
/Don.?t tran?slate|Do not tran?slate/i.test(text)
60+
) {
5861
return true;
5962
}
6063
},
6164
(text) => {
6265
const charSets = [
6366
{
64-
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
65-
matchPercent: 0.4
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,
6670
},
6771
{
6872
regex: /[ʙғɢʜɪʟɴ̨ʀsxʏ\s]/g,
69-
matchPercent: 0.5
73+
matchPercent: 0.5,
7074
},
7175
{
7276
regex: /[\u{1D538}-\u{1D56B}\u{1D400}-\u{1D433}]/gu, // math letter symbols
73-
matchPercent: 0.3
74-
}
77+
matchPercent: 0.3,
78+
},
7579
];
7680
for (const check of charSets) {
7781
const { regex, matchPercent } = check,
@@ -80,13 +84,37 @@ const SITES = Object.freeze({
8084
return true;
8185
}
8286
}
83-
}
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+
},
84112
],
85113
getCommentText(node) {
86114
if (node.nodeName === "YTD-COMMENT-RENDERER") {
87115
return node.querySelector("#content-text").textContent;
88116
}
89-
}
117+
},
90118
},
91119
FACEBOOK_EMBED: {
92120
hostname: "www.facebook.com",
@@ -99,36 +127,32 @@ const SITES = Object.freeze({
99127
/(manga|story|site|website).*?:\s?(https?:\/\/[^\s]+|\n.\s])+$/,
100128
// Other weird comments/scams
101129
/look at a website|very popular .*?website|Amazon gift card/,
102-
/^i love sex$/
130+
/^i love sex$/,
103131
],
104132
options: {
105133
initialScan: () => {
106134
return document.querySelectorAll(".clearfix");
107-
}
135+
},
108136
},
109137
getCommentText(node) {
110138
if (node.classList?.contains("clearfix")) {
111139
try {
112-
return node?.lastElementChild
113-
.lastElementChild
114-
.lastElementChild
115-
.firstElementChild
116-
.children[1]
117-
.textContent;
140+
return node?.lastElementChild.lastElementChild.lastElementChild
141+
.firstElementChild.children[1].textContent;
118142
} catch (err) {
119143
return null;
120144
}
121145
}
122-
}
123-
}
146+
},
147+
},
124148
}),
125149
site = getCurrentSite(),
126150
commentMutationListener = new MutationObserver((mutations) => {
127151
for (const mutation of mutations) {
128152
for (const node of mutation.addedNodes) {
129153
const text = site.getCommentText(node);
130154
if (text) {
131-
if (isCommentLikelyBotComment(text, site)) {
155+
if (isCommentLikelyBotComment(text, site, node)) {
132156
node.style.display = "none";
133157
}
134158
}
@@ -138,20 +162,21 @@ const SITES = Object.freeze({
138162

139163
commentMutationListener.observe(document.body, {
140164
subtree: true,
141-
childList: true
165+
childList: true,
142166
});
143167

144168
/**
145169
* Determines whether a comment is likely spam.
146170
*
147-
* @param {String} text The comment's content
148-
* @param {Object} site The website the comment is from
171+
* @param {string} text The comment's content
172+
* @param {object} site The website the comment is from
173+
* @param {Node} node
149174
* @return {Boolean}
150175
*/
151-
function isCommentLikelyBotComment(text, site) {
176+
function isCommentLikelyBotComment(text, site, node) {
152177
for (const check of site.checks) {
153178
if (typeof check === "function") {
154-
if (check(text)) {
179+
if (check(text, node)) {
155180
console.log("Filter Check Failed");
156181
console.log(text);
157182
return true;
@@ -183,7 +208,7 @@ if (site.options?.initialScan) {
183208
for (const node of items) {
184209
const text = site.getCommentText(node);
185210
if (text) {
186-
if (isCommentLikelyBotComment(text, site)) {
211+
if (isCommentLikelyBotComment(text, site, node)) {
187212
node.style.display = "none";
188213
}
189214
}

0 commit comments

Comments
 (0)