From 5b99800c8e0ab8483ce1c4f1767d92909eb8f2f8 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Tue, 23 Apr 2024 23:44:10 +0800 Subject: [PATCH] Generate random ID for context menu when not previously defined --- scripts/GUI/context_menus.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/GUI/context_menus.js b/scripts/GUI/context_menus.js index 219f33d..3a459f5 100644 --- a/scripts/GUI/context_menus.js +++ b/scripts/GUI/context_menus.js @@ -4,7 +4,9 @@ export default class Menu { #options; constructor (ID, title, contexts, event, type, icon) { - if ((typeof ID).includes(`obj`) && !Array.isArray(ID) && ID.hasOwnProperty(`ID`)) { + if ((typeof ID).includes(`obj`) && !Array.isArray(ID)) { + ID.ID = ((ID.hasOwnProperty(`ID`)) ? ID.ID : false) ? ID.ID : String(Math.random() / Math.random() * 100); + (Object.keys(ID)).forEach((key) => { this[key] = ID[key]; }) @@ -28,16 +30,16 @@ export default class Menu { onclick: this.event }; (this.icon) ? this.#options.icon = this.icon : null; - - if (!this.#options.hidden) {this.show(); delete this.#options.hidden;}; - delete this.#options.id; + ((this.hidden != null) ? (!this.hidden) : true) ? this.show() : null; }; remove() { + this.hidden = true; chrome.contextMenus.remove(this.ID); }; show() { + this.hidden = false; chrome.contextMenus.create(this.#options); }