From e53227622790913e680ef2ceff30848f93de0db2 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Sun, 10 May 2026 14:45:30 -0500 Subject: [PATCH] stack those menus! --- src/webpage/contextmenu.ts | 12 +++++++++++- src/webpage/direct.ts | 30 ++++++++++++++++-------------- src/webpage/user.ts | 5 +++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/webpage/contextmenu.ts b/src/webpage/contextmenu.ts index c21d510..957be17 100644 --- a/src/webpage/contextmenu.ts +++ b/src/webpage/contextmenu.ts @@ -159,7 +159,10 @@ class Seperator implements menuPart { } makeContextHTML(obj1: x, obj2: y, menu: HTMLDivElement): void { if (!this.visible || this.visible(obj1, obj2)) { - if (menu.children[menu.children.length - 1].tagName === "HR") { + if ( + !menu.children[menu.children.length - 1] || + menu.children[menu.children.length - 1].tagName === "HR" + ) { return; } menu.append(document.createElement("hr")); @@ -303,6 +306,10 @@ class Contextmenu { this.buttons.push(button); return button; } + excluded = [] as string[]; + excludeGroup(group: string) { + this.excluded.push(group); + } addSeperator(visible?: (obj1: x, obj2: y) => boolean, group?: string) { this.buttons.push(new Seperator(visible, group)); } @@ -338,7 +345,10 @@ class Contextmenu { div.classList.add("contextmenu", "flexttb"); const processed = new WeakSet>(); + const excluded = new Set(layered.flatMap((_) => _[0].excluded)); + for (const button of this.buttons) { + if (excluded.has(button.group || "")) continue; button.makeContextHTML(addinfo, other, div, layered, processed); } if (div.children[div.children.length - 1]?.tagName !== "HR") { diff --git a/src/webpage/direct.ts b/src/webpage/direct.ts index 8c3c3c4..717f2e2 100644 --- a/src/webpage/direct.ts +++ b/src/webpage/direct.ts @@ -396,7 +396,7 @@ dmPermissions.setPermission("USE_VAD", 1); class Group extends Channel { users: User[]; owner_id?: string; - static groupcontextmenu = new Contextmenu("channel menu"); + static groupcontextmenu = new Contextmenu("channel menu", true); static groupMenu = this.makeGroupMenu(); static makeGroupMenu() { const menu = new Contextmenu("group menu", true); @@ -427,9 +427,13 @@ class Group extends Channel { function (this: Group) { this.readbottom(); }, + { + group: "dm", + }, ); + this.groupcontextmenu.excludeGroup("dmPerson"); - this.groupcontextmenu.addSeperator(); + this.groupcontextmenu.addSeperator(undefined, "dm"); this.groupcontextmenu.addButton( () => I18n.group.edit(), @@ -450,6 +454,7 @@ class Group extends Channel { }, { color: "red", + group: "dm", }, ); @@ -458,27 +463,21 @@ class Group extends Channel { function (this: Group) { this.addPerson(); }, - ); - - this.groupcontextmenu.addSeperator(); - - this.groupcontextmenu.addButton( - () => I18n.user.copyId(), - function () { - navigator.clipboard.writeText(this.users[0].id); - }, { - visible: function () { - return this.type === 1; - }, + group: "dm", }, ); + this.groupcontextmenu.addSeperator(undefined, "dm"); + this.groupcontextmenu.addButton( () => I18n.DMs.copyId(), function (this: Group) { navigator.clipboard.writeText(this.id); }, + { + group: "id", + }, ); } @@ -593,6 +592,9 @@ class Group extends Channel { createguildHTML() { const div = document.createElement("div"); Group.groupcontextmenu.bindContextmenu(div, this, undefined); + if (this.type === 1 && this.users[0]) { + User.contextmenu.bindContextmenu(div, this.users[0], undefined); + } this.html = new WeakRef(div); div.classList.add("flexltr", "liststyle"); const myhtml = document.createElement("span"); diff --git a/src/webpage/user.ts b/src/webpage/user.ts index bde651e..d87b830 100644 --- a/src/webpage/user.ts +++ b/src/webpage/user.ts @@ -308,6 +308,9 @@ class User extends SnowFlake { await relChange; } static setUpContextMenu(): void { + this.contextmenu.addGroup("dm"); + this.contextmenu.addSeperator(); + this.contextmenu.addButton( () => I18n.user.message(), function (this: User) { @@ -317,6 +320,7 @@ class User extends SnowFlake { icon: { css: "svg-frmessage", }, + group: "dmPerson", }, ); @@ -578,6 +582,7 @@ class User extends SnowFlake { navigator.clipboard.writeText(this.id); }, ); + this.contextmenu.addGroup("id"); this.contextmenu.addSeperator();