Last active
January 27, 2023 12:20
-
-
Save aremu-smog/36efb2c9c0e36b92176c6db9e460cc74 to your computer and use it in GitHub Desktop.
Close all tabs excluding the current tab after 5secs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const closeButton = document.querySelector("#close-button") | |
| closeButton.addEventListener("click", async () => { | |
| let [currentTab] = await chrome.tabs.query({ | |
| active: true, | |
| currentWindow: true, | |
| }) | |
| let allTabs = await chrome.tabs.query({ | |
| windowId: chrome.windows.WINDOW_ID_CURRENT, | |
| }) | |
| const tabsToClose = await allTabs | |
| .map(tab => tab.id) | |
| .filter(tabId => tabId !== currentTab.id) | |
| const ONE_SECOND = 1000 | |
| const ONE_MINUTE = ONE_SECOND * 60 | |
| const FIVE_MINUTES = ONE_MINUTE * 5 | |
| setTimeout(async () => { | |
| await chrome.tabs.remove(tabsToClose, () => {}) | |
| }, FIVE_MINUTES) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment