mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-21 17:50:29 -05:00
Preact: Add togglemessages command and handle 'hidelines' properly (#2553)
Some checks are pending
Node.js CI / build (22.x) (push) Waiting to run
Some checks are pending
Node.js CI / build (22.x) (push) Waiting to run
This commit is contained in:
parent
c46bac0471
commit
a7f3c522e0
|
|
@ -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 = `<small>(${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid} hidden)</small>`;
|
||||
const lastNode = nodes[nodes.length - 1];
|
||||
lastNode.appendChild(document.createTextNode(' '));
|
||||
lastNode.appendChild(button);
|
||||
lastChild.appendChild(document.createTextNode(' '));
|
||||
lastChild.appendChild(button);
|
||||
}
|
||||
|
||||
static unlinkNodeList(nodeList: ArrayLike<HTMLElement>, classStart: string) {
|
||||
|
|
|
|||
|
|
@ -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 ?
|
||||
`<small>(${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid} hidden)</small>` :
|
||||
`<small>(Hide ${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid})</small>`;
|
||||
}
|
||||
}
|
||||
},
|
||||
'rank,ranking,rating,ladder'(target) {
|
||||
let arg = target;
|
||||
if (!arg) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user