Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getTabsToClose(tabs,args) {
- var foundActiveTab = false;
- var toClose = [];
- function checkTab(tab) {
- var add = args === "above" ? !foundActiveTab : foundActiveTab;
- if (add) {
- if (!toClose.includes(tab.id)) {
- console.log(`Adding ${tab.id} - "${tab.title}" to toClose.`);
- toClose.push(tab.id);
- }
- }
- if (tab.states.includes("active")) {
- console.log(`Found active tab: ${tab.id} - "${tab.title}"`);
- foundActiveTab = true;
- toClose.pop();
- }
- if (tab.children === undefined || tab.children.length == 0) {
- return;
- }
- for (const child of tab.children) {
- checkTab(child);
- }
- }
- for (const tab of tabs) {
- checkTab(tab);
- }
- console.log(`got ${toClose.length} tabs to close. ids=${toClose.join(",")}`);
- executeInBackground(toClose => {
- browser.tabs.remove(toClose);
- }, [toClose])
- .then(() => console.log("executing in bg complete"))
- .catch(e => console.log(`caught exception: ${e}`));
- }
- console.log("running executeAsync");
- const kTST_ID = 'treestyletab@piro.sakura.ne.jp';
- async function executeAsync() {
- console.log("starting executeAsync");
- var tabs = await browser.runtime.sendMessage(kTST_ID, {
- type: 'get-tree', // or 'demote'
- tab: '*',
- window: 0
- });
- console.log(`got ${tabs.length} tabs`);
- getTabsToClose(tabs,"above");
- return true;
- }
- executeAsync().then(q=>console.log(`something executeAsync: ${q}`)).catch(e=>console.log(`caught executeAsync error - ${e}`));
Add Comment
Please, Sign In to add comment