From fc8983c646c694ba9a5154546f99fe7e73765117 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:10:24 +0800 Subject: [PATCH] TABS is always a dictionary --- scripts/GUI/tabs.js | 66 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/scripts/GUI/tabs.js b/scripts/GUI/tabs.js index 94f487c..5933299 100644 --- a/scripts/GUI/tabs.js +++ b/scripts/GUI/tabs.js @@ -1,41 +1,43 @@ export default class Tabs { - /* Add an action listener. - - @param {string} event The event to listen for - @param {function} callback The callback function - */ - static addActionListener(event, callback) { - chrome.tabs[event].addListener((tabId, info, tab) => {callback({"tabId": tabId, "info": info, "tab": tab})}) + /* Add an action listener. + + @param {string} event The event to listen for + @param {function} callback The callback function + */ + static addActionListener(event, callback) { + chrome.tabs[event].addListener((tabId, info, tab) => {callback({"tabId": tabId, "info": info, "tab": tab})}) }; - /* Create a new tab. + /* Create a new tab. - @param {string} URL The URL to open - @param {number} index The index of the tab - @param {boolean} pinned Whether the tab is pinned - */ - static create(URL, index, pinned = false) { - ((typeof index).includes(`obj`) && index != null && !Array.isArray(index)) - // Set the options. - let OPTIONS = {url: URL, active: true, pinned: pinned}; - (index) ? OPTIONS.index = index : null; + @param {string} URL The URL to open + @param {number} index The index of the tab + @param {boolean} pinned Whether the tab is pinned + */ + static create(URL, index, pinned = false) { + ((typeof index).includes(`obj`) && index != null && !Array.isArray(index)) + // Set the options. + let OPTIONS = {url: URL, active: true, pinned: pinned}; + (index) ? OPTIONS.index = index : null; - // Create the tab. - chrome.tabs.create(OPTIONS); - } + // Create the tab. + chrome.tabs.create(OPTIONS); + } - /* Filters all tabs and returns a result. - - @param {Object} filters The filters on tab search - @param {number} index the tab number to return - */ - static async query(filters, index) { - filters = ((typeof filters).includes(`obj`) && filters != null) ? filters : { active: true, currentWindow: true}; - let TABS = {}; + /* Filters all tabs and returns a result. + + @param {Object} filters The filters on tab search + @param {number} index the tab number to return + */ + static async query(filters, index) { + filters = ((typeof filters).includes(`obj`) && filters != null) ? filters : { active: true, currentWindow: true}; + let TABS = {}; - TABS.all = await chrome.tabs.query(filters); - TABS.result = ((Array.isArray(TABS.all) ? (TABS.all).length > 0 : false) && ((index != null && (typeof index).includes(`num`)) ? index >= 0 : false)) ? TABS.all[index] : ((Array.isArray(TABS.all) ? (TABS.all).length > 0 : false) ? TABS.all : null); + TABS.all = await chrome.tabs.query(filters); + TABS.result = (index != null) + ? TABS.all[Math.abs(parseFloat(index))] + : TABS.all; - return (TABS.result); - } + return (TABS.result); + } } \ No newline at end of file