Skip to content

Commit

Permalink
Add running URLs into storage
Browse files Browse the repository at this point in the history
  • Loading branch information
bflatmajor committed Jul 13, 2019
1 parent 0c99f38 commit ee38d1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@ const init = async () => {

browser.tabs.onRemoved.addListener(stopTab)

setTimersByStoredUrls()

const currentTab = await browser.tabs.query({active: true})
setStatus(currentTab.id)
}

const setTimersByStoredUrls = async () => {
const urls = (await browser.storage.local.get()).urls

if (!urls) {
return
}

urls.forEach(async (url) => {
const tab = (await browser.tabs.query({url}))[0]
runTab(tab)
})
}

const setStatusByTabId = async (id) => {
const tab = await browser.tabs.get(id)
setStatus(tab.id)
Expand All @@ -62,12 +77,20 @@ const runTab = (tab) => {
browser.tabs.reload(tab.id)
}, timeout)
runningItems.push({tab, timer})
setStoredUrls()
}

const stopTab = (id) => {
const runningItem = findRunningItemByTabId(id)
clearInterval(runningItem.timer)
runningItems.splice(runningItems.indexOf(runningItem), 1)
setStoredUrls()
}

const setStoredUrls = () => {
browser.storage.local.set({
urls: [...new Set(runningItems.map(({tab}) => tab.url))]
})
}

const timeout = 1000 * 111
Expand Down
4 changes: 2 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "Borefresh",
"version": "0.1.0",
"description": "Refresh your tabs automatically every 111 seconds.",
"version": "0.2.1",
"description": "Refresh my tabs automatically every 111 seconds.",
"homepage_url": "https://github.com/gnirob/borefresh",
"icons": {
"48": "icon-running.svg",
Expand Down

0 comments on commit ee38d1e

Please sign in to comment.