From a13702e0c207a44f4cc90b523b09fb1b7200fb47 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sat, 27 Apr 2024 09:48:37 +0800 Subject: [PATCH] change more properties regarding the icon --- scripts/GUI/extensionIcon.js | 46 ++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/scripts/GUI/extensionIcon.js b/scripts/GUI/extensionIcon.js index d514ee8..eb651cc 100644 --- a/scripts/GUI/extensionIcon.js +++ b/scripts/GUI/extensionIcon.js @@ -1,11 +1,43 @@ class BrowserIcon { - /* Change the extension icon. - - @param {string} path The path to the icon. - */ - static set(path) { - chrome.browserAction.setIcon({"path": path}); - }; + /* Change a property of the browser icon. + + @param {object} options The options to change. + @param {object} parameters The parameters to apply with the change. + */ + static set(options, parameters) { + /* Format the parameter to pass. */ + function format(option, parameters) { + // Remove windowId if both that and tabId is present. + (parameters) ? ((parameters.tabId != null && parameters.windowId != null) ? delete parameters.windowId : null) : null; + + // Merge the option to be passed and the updated parameters. + return ((parameters) ? Object.assign(option, parameters) : option); + } + + (options.Icon) ? chrome.browserAction.setIcon(format({"path": path}, parameters)) : null; + (options.BadgeText) ? chrome.browserAction.setBadgeText(format({"text": String(options.text)}, parameters)) : null; + (options.BadgeBackgroundColor) ? chrome.browserAction.setBadgeBackgroundColor(format({"color": color}, parameters)) : null; + (options.Popup) ? chrome.browserAction.setPopup(format({"popup": popup}, parameters)) : null; + }; + + /* + Get a detail regarding the current browser icon. + + @param {string} detail The detail to get. + @param {object} parameters The filter parameters + */ + static get(detail, parameters) { + /* Format the parameter to pass. */ + function format(parameters) { + // Remove windowId if both that and tabId is present. + (parameters) ? ((parameters.tabId != null && parameters.windowId != null) ? delete parameters.windowId : null) : null; + + // Merge the option to be passed and the updated parameters. + return (parameters); + } + + return (chrome.browserAction[`get`.concat(detail)](((parameters) ? format(parameters) : null))); + } }; export {BrowserIcon as default}; \ No newline at end of file