From 1e55c10a458e5f509cf73ba3c05e9a524716b9e6 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 2 May 2024 11:56:48 +0800 Subject: [PATCH] removed broken window and menu creation --- scripts/GUI/entrypoints/ManagedWindow.js | 14 --- scripts/GUI/entrypoints/menuentry.js | 27 ------ scripts/GUI/menus.js | 112 ----------------------- 3 files changed, 153 deletions(-) delete mode 100644 scripts/GUI/entrypoints/ManagedWindow.js delete mode 100644 scripts/GUI/entrypoints/menuentry.js delete mode 100644 scripts/GUI/menus.js diff --git a/scripts/GUI/entrypoints/ManagedWindow.js b/scripts/GUI/entrypoints/ManagedWindow.js deleted file mode 100644 index 5d759a7..0000000 --- a/scripts/GUI/entrypoints/ManagedWindow.js +++ /dev/null @@ -1,14 +0,0 @@ -import Window from "/scripts/GUI/window.js"; - -export default class ManagedWindow { - constructor () { - this.instance = new Window("/pages/popup.htm", {"width": 500, "height": 500, "type": "popup", "hidden": true}); - } - - /* - Show the popup. - */ - show() { - this.instance.show(); - } -} \ No newline at end of file diff --git a/scripts/GUI/entrypoints/menuentry.js b/scripts/GUI/entrypoints/menuentry.js deleted file mode 100644 index 309e409..0000000 --- a/scripts/GUI/entrypoints/menuentry.js +++ /dev/null @@ -1,27 +0,0 @@ -import Menu from '/scripts/GUI/menus.js'; -import texts from "/scripts/mapping/read.js"; - -export default class MenuEntry { - /* Create all entries. */ - constructor() { - // Add the context menu. - this.menu = new Menu({title: (new texts(`entry_contextMenu`)).localized, contexts: [`all`], events: {"onClicked": this.onclick}, hidden: true}); - }; - - /* - Enable the sidebar. - */ - enable () { - // First disable to prevent ghost entries. - this.disable(); - - this.menu.show(); - } - - /* - Disable. - */ - disable () { - this.menu.remove(); - } -} \ No newline at end of file diff --git a/scripts/GUI/menus.js b/scripts/GUI/menus.js deleted file mode 100644 index cc636c6..0000000 --- a/scripts/GUI/menus.js +++ /dev/null @@ -1,112 +0,0 @@ -/* context_menus.js -Context menu management -*/ - -export default class Menu { - #options; - - 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); - - (Object.keys(ID)).forEach((key) => { - this[key] = ID[key]; - }) - } else { - this.ID = String((ID) ? ID : (Math.random() / Math.random() * 100)); - this.title = (title) ? title : `Menu`; - this.contexts = (Array.isArray(contexts)) ? contexts : [`all`]; - this.events = (events) ? events : {"onClicked" : function() {}}; - this.type = (((typeof type).includes(`str`) && type) ? type.trim() : false) ? type : `normal`; - - if (icon) { - this.icon = icon; - }; - }; - - this.#options = { - id: this.ID, - title: this.title, - contexts: this.contexts, - type: this.type - }; - (this.icon) ? this.#options.icon = this.icon : null; - ((this.hidden != null) ? (!this.hidden) : true) ? this.show() : null; - }; - - remove() { - (!this.hidden) ? chrome.contextMenus.remove(this.ID) : false; - this.hidden = true; - }; - - 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).length > 0 : false) { - (Object.keys(this.events)).forEach((EVENT) => { - chrome.contextMenus[EVENT].addListener((info, tab) => { - if (info.menuItemId == this.ID) { - this.events[EVENT](info, tab) - } - }) - }); - }; - } - } - - /* Update the context menu. - - @param {Object} options The new options for the context menu. - */ - update(options) { - if ((typeof options).includes(`obj`) && options != null && !Array.isArray(options)) { - (Object.keys(options)).forEach((key) => { - (options[key] != null && options[key] != undefined) ? this[key] = options[key] : delete this[key]; - }); - } - - this.#options = { - id: this.ID, - title: this.title, - contexts: this.contexts, - type: this.type - }; - (this.icon) ? this.#options.icon = this.icon : null; - - (!this.hidden) ? chrome.contextMenus.update(this.ID, this.#options) : false; - - (((this.events && (typeof this.events).includes(`obj`) && !Array.isArray(this.events))) ? Object.keys(this.events) > 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; - }) - }) - : false; - } - - /* - Run a new function when triggered. - - @param {function} callback the function to run - */ - onclick(callback) { - this.addActionListener("onClicked", callback); - } - - /* - Run an event following an action. - - @param {string} event the event - @param {function} callback the function to run - */ - addActionListener(event, callback) { - this.events = (this.events == null) ? {} : this.events; - this.events[event] = callback; - this.update(); - }; -} \ No newline at end of file