-
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathcontext.js
More file actions
76 lines (71 loc) · 1.93 KB
/
Copy pathcontext.js
File metadata and controls
76 lines (71 loc) · 1.93 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const context = async () => {
if (context.ran) {
return;
}
context.ran = true;
// we do not support custom mode on m3 anymore
chrome.contextMenus.create({
id: 'blacklist',
title: 'Switch to "black-list" mode',
contexts: ['action'],
type: 'radio'
}, () => chrome.runtime.lastError);
chrome.contextMenus.create({
id: 'whitelist',
title: 'Switch to "white-list" mode',
contexts: ['action'],
type: 'radio'
}, () => chrome.runtime.lastError);
chrome.contextMenus.create({
id: 'custom',
title: 'Switch to "custom" mode',
contexts: ['action'],
type: 'radio'
}, () => chrome.runtime.lastError);
chrome.contextMenus.create({
id: 'pause-tab',
title: 'Pause on This Tab',
contexts: ['action']
}, () => chrome.runtime.lastError);
chrome.contextMenus.create({
id: 'resume-tab',
title: 'Resume on This Tab',
contexts: ['action']
}, () => chrome.runtime.lastError);
const prefs = await chrome.storage.local.get({
'mode': 'blacklist'
});
chrome.contextMenus.update(prefs.mode, {
checked: true
});
};
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === 'blacklist' || info.menuItemId === 'whitelist' || info.menuItemId === 'custom') {
chrome.storage.local.set({
mode: info.menuItemId
});
}
else if (info.menuItemId === 'pause-tab') {
chrome.declarativeNetRequest.updateSessionRules({
removeRuleIds: [tab.id],
addRules: [{
id: tab.id,
action: {
type: 'allowAllRequests'
},
priority: 3,
condition: {
tabIds: [tab.id],
resourceTypes: ['main_frame', 'sub_frame']
}
}]
});
}
else if (info.menuItemId === 'resume-tab') {
chrome.declarativeNetRequest.updateSessionRules({
removeRuleIds: [tab.id]
});
}
});
chrome.runtime.onInstalled.addListener(context);
chrome.runtime.onStartup.addListener(context);