-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
55 lines (52 loc) · 1.24 KB
/
background.js
File metadata and controls
55 lines (52 loc) · 1.24 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
50
51
52
53
54
55
function handleActivate(tab) {
browser.cookies.get({
url: tab.url,
name: 'XDEBUG_TRIGGER',
}).then((cookie) => {
return toggleCookie(cookie, tab.url);
});
}
function toggleCookie(cookie, url) {
if (cookie) {
browser.cookies.remove({
url: url,
name: 'XDEBUG_TRIGGER',
}).then((cookie) => {
browser.browserAction.setIcon({});
});
}
else {
browser.cookies.set({
url: url,
path: '/',
name: 'XDEBUG_TRIGGER',
value: '1',
}).then((cookie) => {
browser.browserAction.setIcon({ path: 'bug-48-active.png' });
}).catch((e) => {
browser.notifications.create('xdebug_trigger_set', {
title: 'XDEBUG_TRIGGER Set',
message: e.message,
type: "basic"
});
});
}
}
function handleTabSwitch(tabId, changeInfo, tab) {
browser.cookies.get({
url: tab.url,
name: 'XDEBUG_TRIGGER',
}).then((cookie) => {
if (cookie) {
browser.browserAction.setIcon({ path: 'bug-48-active.png' });
}
else {
browser.browserAction.setIcon({});
}
});
}
browser.browserAction.onClicked.addListener(handleActivate);
browser.tabs.onUpdated.addListener(handleTabSwitch, {
urls: [ '*://*.test/*' ],
properties: [ 'attention' ]
})