From a850cb2cc219c50f8a22e2eea66dd4a46b28a02f Mon Sep 17 00:00:00 2001 From: vyneer Date: Sun, 30 Jun 2024 16:03:30 +0300 Subject: [PATCH] fix: don't censor emotes --- .../formatters/BadWordsCensorshipFormatter.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/chat/js/formatters/BadWordsCensorshipFormatter.js b/assets/chat/js/formatters/BadWordsCensorshipFormatter.js index 51ab8480..b053c3e1 100644 --- a/assets/chat/js/formatters/BadWordsCensorshipFormatter.js +++ b/assets/chat/js/formatters/BadWordsCensorshipFormatter.js @@ -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;