-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathvisbug.js
More file actions
49 lines (41 loc) · 1.22 KB
/
visbug.js
File metadata and controls
49 lines (41 loc) · 1.22 KB
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
39
40
41
42
43
44
45
46
47
48
49
const state = {
loaded: {},
injected: {},
}
var platform = typeof browser === 'undefined'
? chrome
: browser
var commands = platform.commands.getAll(cmds => {
var [cmd] = cmds
if (!cmd) return
platform.browserAction.setTitle({
title: `Click or press ${cmd.shortcut} to launch VisBug`,
})
})
const toggleIn = ({id:tab_id}) => {
// toggle out: it's currently loaded and injected
if (state.loaded[tab_id] && state.injected[tab_id]) {
platform.tabs.executeScript(tab_id, { file: 'toolbar/eject.js' })
state.injected[tab_id] = false
}
// toggle in: it's loaded and needs injected
else if (state.loaded[tab_id] && !state.injected[tab_id]) {
platform.tabs.executeScript(tab_id, { file: 'toolbar/restore.js' })
state.injected[tab_id] = true
getColorMode()
getColorScheme()
}
// fresh start in tab
else {
platform.tabs.insertCSS(tab_id, { file: 'toolbar/bundle.css' })
platform.tabs.executeScript(tab_id, { file: 'toolbar/inject.js' })
state.loaded[tab_id] = true
state.injected[tab_id] = true
getColorMode()
getColorScheme()
}
platform.tabs.onUpdated.addListener(function(tabId) {
if (tabId === tab_id)
state.loaded[tabId] = false
})
}