mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-04-27 02:27:41 -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) {
|
hideChatFrom(userid: ID, showRevealButton = true, lineCount = 0) {
|
||||||
const classStart = 'chat chatmessage-' + userid + ' ';
|
const classStart = 'chat chatmessage-' + userid + ' ';
|
||||||
let nodes: HTMLElement[] = [];
|
let nodes: HTMLElement[] = [];
|
||||||
|
const lastChild = this.innerElem.lastChild;
|
||||||
for (const node of this.innerElem.childNodes as any as HTMLElement[]) {
|
for (const node of this.innerElem.childNodes as any as HTMLElement[]) {
|
||||||
if (node.className && (node.className + ' ').startsWith(classStart)) {
|
if (node.className && (node.className + ' ').startsWith(classStart)) {
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
|
|
@ -1033,15 +1034,15 @@ export class BattleLog {
|
||||||
node.style.display = 'none';
|
node.style.display = 'none';
|
||||||
node.className = 'revealed ' + node.className;
|
node.className = 'revealed ' + node.className;
|
||||||
}
|
}
|
||||||
if (!nodes.length || !showRevealButton) return;
|
if (!nodes.length || !showRevealButton || !lastChild) return;
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
button.name = 'toggleMessages';
|
button.name = 'toggleMessages';
|
||||||
|
button.setAttribute('data-cmd', '/togglemessages ' + userid);
|
||||||
button.value = userid;
|
button.value = userid;
|
||||||
button.className = 'subtle';
|
button.className = 'subtle';
|
||||||
button.innerHTML = `<small>(${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid} hidden)</small>`;
|
button.innerHTML = `<small>(${nodes.length} line${nodes.length > 1 ? 's' : ''} from ${userid} hidden)</small>`;
|
||||||
const lastNode = nodes[nodes.length - 1];
|
lastChild.appendChild(document.createTextNode(' '));
|
||||||
lastNode.appendChild(document.createTextNode(' '));
|
lastChild.appendChild(button);
|
||||||
lastNode.appendChild(button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unlinkNodeList(nodeList: ArrayLike<HTMLElement>, classStart: string) {
|
static unlinkNodeList(nodeList: ArrayLike<HTMLElement>, classStart: string) {
|
||||||
|
|
|
||||||
|
|
@ -349,6 +349,40 @@ export class ChatRoom extends PSRoom {
|
||||||
this.log?.reset();
|
this.log?.reset();
|
||||||
this.update(null);
|
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) {
|
'rank,ranking,rating,ladder'(target) {
|
||||||
let arg = target;
|
let arg = target;
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user