Skip to content

Instantly share code, notes, and snippets.

@aremu-smog
Last active January 27, 2023 12:20
Show Gist options
  • Select an option

  • Save aremu-smog/36efb2c9c0e36b92176c6db9e460cc74 to your computer and use it in GitHub Desktop.

Select an option

Save aremu-smog/36efb2c9c0e36b92176c6db9e460cc74 to your computer and use it in GitHub Desktop.
Close all tabs excluding the current tab after 5secs.
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