From f457ac5e23cdd03119e7ab7336bcb154f29d5bd4 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:07:31 +0800 Subject: [PATCH] add window event listeners --- scripts/GUI/window.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/GUI/window.js b/scripts/GUI/window.js index 949ebf9..b735034 100644 --- a/scripts/GUI/window.js +++ b/scripts/GUI/window.js @@ -25,4 +25,17 @@ export default class Window { show() { this.window = window.open(this.url, this.name, this.options); }; + + /* Create an action listener. + + @param {string} event the event to listen for + @param {function} callback the callback function + */ + static addActionListener(event, callback) { + // Correct possible syntax error on "on" prefix. + event = (!event.includes(`on`)) ? `on${event}` : event; + + // Add the event. + chrome.windows[event].addListener(callback); + } }; \ No newline at end of file