From d33e5f0a2d66ad9df96c2eb3a2ad64ab57433fa1 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sat, 27 Apr 2024 18:52:07 +0800 Subject: [PATCH] add events properly --- scripts/GUI/menus.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/GUI/menus.js b/scripts/GUI/menus.js index e4787af..67f2730 100644 --- a/scripts/GUI/menus.js +++ b/scripts/GUI/menus.js @@ -3,7 +3,7 @@ export default class Menu { #options; - constructor (ID, title, contexts, event, type, icon) { + constructor (ID, title, contexts, events, type, icon) { if ((typeof ID).includes(`obj`) && !Array.isArray(ID)) { // Create the ID if it doesn't exist. ID.ID = ((ID.hasOwnProperty(`ID`)) ? ID.ID : false) ? ID.ID : String(Math.random() / Math.random() * 100); @@ -41,14 +41,15 @@ export default class Menu { show() { if (this.hidden || this.hidden == null) { this.hidden = false; - this.ID = chrome.contextMenus.create(this.#options); - - if (((this.events && (typeof this.events).includes(`obj`) && !Array.isArray(this.events))) ? Object.keys(this.events) > 0 : false) { + this.ID = chrome.contextMenus.create(this.#options); + + console.log(Object.keys(this.events)); + if (((this.events && (typeof this.events).includes(`obj`) && !Array.isArray(this.events))) ? Object.keys(this.events).length > 0 : false) { (Object.keys(this.events)).forEach((EVENT) => { chrome.contextMenus[EVENT].addListener((info, tab) => { - ((info.menuItemId) ? info.menuItemId == this.ID : false) - ? this.events[EVENT](info, tab) - : false; + if (info.menuItemId == this.ID) { + this.events[EVENT](info, tab) + } }) }); };