From 96e45efc5940893630134d3a67e528dcdb3f4f9f Mon Sep 17 00:00:00 2001 From: Annika <56906084+AnnikaCodes@users.noreply.github.com> Date: Sun, 26 Jul 2020 15:33:37 -0700 Subject: [PATCH] Support /cleartext (#1572) --- js/client-chat.js | 17 ++++++++++++++++- src/battle-log.ts | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/js/client-chat.js b/js/client-chat.js index 77f9b4862..8956c7b9b 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -1425,6 +1425,7 @@ break; case 'unlink': + // |unlink| is deprecated in favor of |hidelines| // note: this message has global effects, but it's handled here // so that it can be included in the scrollback buffer. if (Dex.prefs('nounlink')) return; @@ -1444,7 +1445,21 @@ this.$chat.children().last().append(' '); } break; - + case 'hidelines': + if (Dex.prefs('nounlink')) return; + var user = toID(row[2]); + var $messages = $('.chatmessage-' + user); + if (!$messages.length) break; + $messages.find('a').contents().unwrap(); + if (row[1] !== 'unlink') { + $messages = this.$chat.find('.chatmessage-' + user); + if (!$messages.length) break; + var lineCount = parseInt(row[3], 10) || 0; + if (lineCount) $messages = $messages.slice(-lineCount); + $messages.hide().addClass('revealed').find('button').parent().remove(); + if (row[1] === 'hide') this.$chat.children().last().append(' '); + } + break; case 'tournament': case 'tournaments': if (Dex.prefs('tournaments') === 'hide') { diff --git a/src/battle-log.ts b/src/battle-log.ts index 2cd38fc90..37eec0bf1 100644 --- a/src/battle-log.ts +++ b/src/battle-log.ts @@ -184,6 +184,7 @@ class BattleLog { return; case 'unlink': { + // |unlink| is deprecated in favor of |hidelines| const user = toID(args[2]) || toID(args[1]); this.unlinkChatFrom(user); if (args[2]) { @@ -192,6 +193,17 @@ class BattleLog { } return; } + + case 'hidelines': { + const user = toID(args[2]); + this.unlinkChatFrom(user); + if (args[1] !== 'unlink') { + const lineCount = parseInt(args[3], 10); + this.hideChatFrom(user, args[1] === 'hide', lineCount); + } + return; + } + case 'debug': divClass = 'debug'; divHTML = '
[DEBUG] ' + BattleLog.escapeHTML(args[1]) + '.
';