diff --git a/play.pokemonshowdown.com/src/battle-log.ts b/play.pokemonshowdown.com/src/battle-log.ts
index 7f7b9cee4..f822e0ede 100644
--- a/play.pokemonshowdown.com/src/battle-log.ts
+++ b/play.pokemonshowdown.com/src/battle-log.ts
@@ -1015,6 +1015,7 @@ export class BattleLog {
hideChatFrom(userid: ID, showRevealButton = true, lineCount = 0) {
const classStart = 'chat chatmessage-' + userid + ' ';
let nodes: HTMLElement[] = [];
+ const lastChild = this.innerElem.lastChild;
for (const node of this.innerElem.childNodes as any as HTMLElement[]) {
if (node.className && (node.className + ' ').startsWith(classStart)) {
nodes.push(node);
@@ -1033,15 +1034,15 @@ export class BattleLog {
node.style.display = 'none';
node.className = 'revealed ' + node.className;
}
- if (!nodes.length || !showRevealButton) return;
+ if (!nodes.length || !showRevealButton || !lastChild) return;
const button = document.createElement('button');
button.name = 'toggleMessages';
+ button.setAttribute('data-cmd', '/togglemessages ' + userid);
button.value = userid;
button.className = 'subtle';
button.innerHTML = `(${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid} hidden)`;
- const lastNode = nodes[nodes.length - 1];
- lastNode.appendChild(document.createTextNode(' '));
- lastNode.appendChild(button);
+ lastChild.appendChild(document.createTextNode(' '));
+ lastChild.appendChild(button);
}
static unlinkNodeList(nodeList: ArrayLike, classStart: string) {
diff --git a/play.pokemonshowdown.com/src/panel-chat.tsx b/play.pokemonshowdown.com/src/panel-chat.tsx
index 666c69110..0e33438c7 100644
--- a/play.pokemonshowdown.com/src/panel-chat.tsx
+++ b/play.pokemonshowdown.com/src/panel-chat.tsx
@@ -349,6 +349,40 @@ export class ChatRoom extends PSRoom {
this.log?.reset();
this.update(null);
},
+ 'togglemessages'(target) {
+ if (this.pmTarget ||
+ this.type !== 'chat') return this.errorReply('This command can only be used in proper chat rooms.');
+ if (this.log) {
+ const userid = toID(target);
+ const classStart = 'revealed chat chatmessage-' + userid;
+ const nodes: HTMLElement[] = [];
+ let isHidden = true;
+ for (const node of this.log.innerElem.childNodes as any as HTMLElement[]) {
+ if (node.className && (node.className + ' ').startsWith(classStart)) {
+ nodes.push(node);
+ }
+ }
+ if (this.log.preemptElem) {
+ for (const node of this.log.preemptElem.childNodes as any as HTMLElement[]) {
+ if (node.className && (node.className + ' ').startsWith(classStart)) {
+ nodes.push(node);
+ }
+ }
+ }
+ isHidden = nodes[0].style.display === 'none';
+ nodes.every(node => {
+ node.style.display = isHidden ? '' : 'none';
+ return true;
+ });
+ isHidden = !isHidden;
+ const toggleButtons = this.log.innerElem.querySelectorAll(`button[name="toggleMessages"][value="${userid}"]`);
+ for (const button of toggleButtons) {
+ button.innerHTML = isHidden ?
+ `(${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid} hidden)` :
+ `(Hide ${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid})`;
+ }
+ }
+ },
'rank,ranking,rating,ladder'(target) {
let arg = target;
if (!arg) {