From 105154a42b643857426ca522d2811ea207f2ec6c Mon Sep 17 00:00:00 2001 From: Norm Date: Tue, 17 Dec 2024 23:42:35 -0500 Subject: [PATCH] Add regex filter support This makes any filter that starts and ends in forward slashes act as a regex filter instead of a simple substring filter. Currently doesn't support trailing flags unlike actual JS regexes, so modifiers should be used instead for that functionality: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier --- src/services/status_parser/status_parser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/status_parser/status_parser.js b/src/services/status_parser/status_parser.js index ed0f6d57..9647ab44 100644 --- a/src/services/status_parser/status_parser.js +++ b/src/services/status_parser/status_parser.js @@ -4,6 +4,10 @@ export const muteWordHits = (status, muteWords) => { const statusText = status.text.toLowerCase() const statusSummary = status.summary.toLowerCase() const hits = filter(muteWords, (muteWord) => { + if (muteWord.startsWith('/') && muteWord.endsWith('/')) { + const muteRegex = new RegExp(muteWord.slice(1, -1)) + return muteRegex.test(statusText) || muteRegex.test(statusSummary) + } return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase()) })