-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbackground.js
38 lines (30 loc) · 940 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
loadState().then(state => {
// make the state available via the window of the background page
window.state = state
browser.browserAction.onClicked.addListener(() => {
state.paused = !state.paused
updateBrowserAction(state)
autoclose(state)
})
updateBrowserAction(state)
browser.tabs.onCreated.addListener(tab => {
autoclose(state)
})
browser.tabs.onAttached.addListener(() => autoclose(state))
browser.tabs.onUpdated.addListener(changeInfo => {
if (changeInfo.pinned === false || changeInfo.audible === false) {
autoclose(state)
}
})
browser.storage.onChanged.addListener(changes => {
if ('settings' in changes) {
state.settings = changes.settings.newValue
updateBrowserAction(state)
state.history = state.history.slice(0, state.settings.maxHistorySize)
persistHistory(state)
autoclose(state)
}
})
return autoclose(state)
})