Skip to content

Commit

Permalink
fix: don't censor emotes
Browse files Browse the repository at this point in the history
  • Loading branch information
vyneer committed Jun 30, 2024
1 parent 19d966e commit a850cb2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions assets/chat/js/formatters/BadWordsCensorshipFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ export default class BadWordsCensorshipFormatter {
constructor() {
this.badWordsRegex =
/(fuck|shit|cunt|whore|bitch|faggot|fag|nigger|nigga|gusano|cracker|rape)/gi;
this.parser = new DOMParser();
}

format(chat, str /* , message=null */) {
if (chat.settings.get('censorbadwords')) {
return str.replace(this.badWordsRegex, (match) =>
'*'.repeat(match.length),
);
try {
const msg = this.parser.parseFromString(str, 'text/html').body;

[...msg.childNodes].forEach((c) => {
if (c.classList?.contains('emote')) {
return;
}

c.textContent = c.textContent.replace(this.badWordsRegex, (match) =>
'*'.repeat(match.length),
);
});

return msg.innerHTML;
} catch {
return str;
}
}

return str;
Expand Down

0 comments on commit a850cb2

Please sign in to comment.