From 006949b7fd015c30afbf95ae2481fbdca1be0998 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Wed, 16 Dec 2020 17:21:00 -0500 Subject: [PATCH] Add matching links and mentions for blacklist / highlight using the strings '$@' for mentions and '$#' for links for the current message matching system instead of an independent setting forming one multiline if statement to cover all related features Closes #4272 Thanks to @Nareese for guidance Signed-off-by: Michael Pratt --- .../index.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/modules/chat_highlight_blacklist_keywords/index.js b/src/modules/chat_highlight_blacklist_keywords/index.js index f83cd55c42..f1d981a6a8 100644 --- a/src/modules/chat_highlight_blacklist_keywords/index.js +++ b/src/modules/chat_highlight_blacklist_keywords/index.js @@ -14,10 +14,10 @@ const REPEATING_SPACE_REGEX = /\s\s+/g; const BLACKLIST_KEYWORD_PROMPT = `Type some blacklist keywords. Messages containing keywords will be filtered from your chat. -Use spaces in the field to specify multiple keywords. Place {} around a set of words to form a phrase, <> inside the {} to use exact search, and () around a single word to specify a username. Wildcards (*) are supported.`; +Use spaces in the field to specify multiple keywords. Place {} around a set of words to form a phrase, <> inside the {} to use exact search, and () around a single word to specify a username. '$@' for all mentions, '$#' for all links. Wildcards (*) are supported.`; const HIGHLIGHT_KEYWORD_PROMPT = `Type some highlight keywords. Messages containing keywords will turn red to get your attention. -Use spaces in the field to specify multiple keywords. Place {} around a set of words to form a phrase, <> inside the {} to use exact search, and () around a single word to specify a username. Wildcards (*) are supported.`; +Use spaces in the field to specify multiple keywords. Place {} around a set of words to form a phrase, <> inside the {} to use exact search, and () around a single word to specify a username. '$@' for all mentions, '$#' for all links. Wildcards (*) are supported.`; const CHAT_LIST_SELECTOR = '.chat-list .chat-scrollable-area__message-container,.chat-list--default .chat-scrollable-area__message-container,.chat-list--other .chat-scrollable-area__message-container'; const VOD_CHAT_FROM_SELECTOR = '.video-chat__message-author'; @@ -144,6 +144,14 @@ function messageContainsKeyword(keywords, from, message) { return false; } +function hasLink($message) { + return $message.find('a').hasClass('link-fragment'); +} + +function isMention($message) { + return $message.find('span').hasClass('mention-fragment'); +} + function isReply($message) { return $message.parent().hasClass('chat-input-tray__open'); } @@ -235,7 +243,14 @@ class ChatHighlightBlacklistKeywordsModule { return this.markBlacklisted($message); } - if (fromContainsKeyword(highlightUsers, from) || messageContainsKeyword(highlightKeywords, from, message)) { + if ((blacklistKeywords.includes('$@') && isMention($message)) || (blacklistKeywords.includes('$#') && hasLink($message))) { + return this.markBlacklisted($message); + } + + if (fromContainsKeyword(highlightUsers, from) || + messageContainsKeyword(highlightKeywords, from, message) || + (highlightKeywords.includes('$@') && isMention($message)) || + (highlightKeywords.includes('$#') && hasLink($message))) { this.markHighlighted($message); if (isReply($message)) return; @@ -258,6 +273,14 @@ class ChatHighlightBlacklistKeywordsModule { return this.markBlacklisted($message); } + if ((blacklistKeywords.includes('$@') && isMention($message)) || (blacklistKeywords.includes('$#') && hasLink($message))) { + return this.markBlacklisted($message); + } + + if ((highlightKeywords.includes('$@') && isMention($message)) || (highlightKeywords.includes('$#') && hasLink($message))) { + return this.markHighlighted($message); + } + if (fromContainsKeyword(highlightUsers, from) || messageContainsKeyword(highlightKeywords, from, messageContent)) { this.markHighlighted($message); }