TABS is always a dictionary
This commit is contained in:
parent
ea6dd9be93
commit
fc8983c646
1 changed files with 34 additions and 32 deletions
|
@ -1,41 +1,43 @@
|
||||||
export default class Tabs {
|
export default class Tabs {
|
||||||
/* Add an action listener.
|
/* Add an action listener.
|
||||||
|
|
||||||
@param {string} event The event to listen for
|
@param {string} event The event to listen for
|
||||||
@param {function} callback The callback function
|
@param {function} callback The callback function
|
||||||
*/
|
*/
|
||||||
static addActionListener(event, callback) {
|
static addActionListener(event, callback) {
|
||||||
chrome.tabs[event].addListener((tabId, info, tab) => {callback({"tabId": tabId, "info": info, "tab": tab})})
|
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 {string} URL The URL to open
|
||||||
@param {number} index The index of the tab
|
@param {number} index The index of the tab
|
||||||
@param {boolean} pinned Whether the tab is pinned
|
@param {boolean} pinned Whether the tab is pinned
|
||||||
*/
|
*/
|
||||||
static create(URL, index, pinned = false) {
|
static create(URL, index, pinned = false) {
|
||||||
((typeof index).includes(`obj`) && index != null && !Array.isArray(index))
|
((typeof index).includes(`obj`) && index != null && !Array.isArray(index))
|
||||||
// Set the options.
|
// Set the options.
|
||||||
let OPTIONS = {url: URL, active: true, pinned: pinned};
|
let OPTIONS = {url: URL, active: true, pinned: pinned};
|
||||||
(index) ? OPTIONS.index = index : null;
|
(index) ? OPTIONS.index = index : null;
|
||||||
|
|
||||||
// Create the tab.
|
// Create the tab.
|
||||||
chrome.tabs.create(OPTIONS);
|
chrome.tabs.create(OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Filters all tabs and returns a result.
|
/* Filters all tabs and returns a result.
|
||||||
|
|
||||||
@param {Object} filters The filters on tab search
|
@param {Object} filters The filters on tab search
|
||||||
@param {number} index the tab number to return
|
@param {number} index the tab number to return
|
||||||
*/
|
*/
|
||||||
static async query(filters, index) {
|
static async query(filters, index) {
|
||||||
filters = ((typeof filters).includes(`obj`) && filters != null) ? filters : { active: true, currentWindow: true};
|
filters = ((typeof filters).includes(`obj`) && filters != null) ? filters : { active: true, currentWindow: true};
|
||||||
let TABS = {};
|
let TABS = {};
|
||||||
|
|
||||||
TABS.all = await chrome.tabs.query(filters);
|
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.result = (index != null)
|
||||||
|
? TABS.all[Math.abs(parseFloat(index))]
|
||||||
|
: TABS.all;
|
||||||
|
|
||||||
return (TABS.result);
|
return (TABS.result);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue