-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
40 lines (34 loc) · 1.18 KB
/
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
39
40
const browser = window.browser || window.chrome;
var currentTab;
var parsedUrl;
var currentDebugStatus;
function updateIcon() {
browser.browserAction.setIcon({
path: currentDebugStatus ? "icons/icon-enabled.svg" : "icons/icon-disabled.svg",
tabId: currentTab.id
});
browser.browserAction.setTitle({
title: currentDebugStatus ? 'Disable Debug Mode' : 'Enable Debug Mode',
tabId: currentTab.id
});
}
function updateActiveTab(tabs) {
browser.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0]) {
currentTab = tabs[0];
parsedUrl = new URL(currentTab.url);
debugParam = parsedUrl.searchParams.get("debug");
currentDebugStatus = (debugParam == 1) ? true : false;
updateIcon();
}
});
}
browser.tabs.onUpdated.addListener(updateActiveTab);
browser.tabs.onActivated.addListener(updateActiveTab);
browser.windows.onFocusChanged.addListener(updateActiveTab);
updateActiveTab();
function toggleDebug() {
(currentDebugStatus) ? parsedUrl.searchParams.delete('debug') : parsedUrl.searchParams.set('debug', '1');
browser.tabs.update({url: `${parsedUrl}`});
}
browser.browserAction.onClicked.addListener(toggleDebug);