Skip to content

Commit 386adc6

Browse files
committed
context menu entries for most common operations
1 parent 4fc1698 commit 386adc6

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

icon_16.png

798 Bytes
Loading

js/start.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function onUpdatedTabsHandler(tabId, changeInfo, tab) {
130130
},
131131
injectedCodeCallback
132132
);
133+
134+
updateContextMenu();
133135
}
134136

135137
chrome.tabs.onUpdated.addListener(onUpdatedTabsHandler);
@@ -149,6 +151,10 @@ chrome.tabs.onRemoved.addListener(onRemovedTabHandler);
149151

150152
/******************************************************************************/
151153

154+
chrome.tabs.onActivated.addListener(updateContextMenu)
155+
156+
/******************************************************************************/
157+
152158
// Might help.
153159
// https://github.com/gorhill/httpswitchboard/issues/35
154160

@@ -221,3 +227,78 @@ function onDisconnectHandler() {
221227

222228
chrome.extension.onConnect.addListener(onConnectHandler);
223229

230+
/******************************************************************************/
231+
232+
chrome.contextMenus.create({
233+
type: 'normal',
234+
id: 'gdt-group0',
235+
title: 'Temporarily whitelist ...',
236+
documentUrlPatterns: ['http://*/*', 'https://*/*']
237+
},
238+
function(){}
239+
);
240+
241+
chrome.contextMenus.create({
242+
type: 'normal',
243+
id: 'revertPermissions',
244+
title: 'Remove all temporary permissions',
245+
documentUrlPatterns: ['http://*/*', 'https://*/*']
246+
},
247+
function(){}
248+
);
249+
250+
function contextMenuClickHandler(info, tab) {
251+
// "If the click did not take place in a tab,
252+
// "this parameter will be missing"
253+
if ( !tab ) {
254+
return;
255+
}
256+
257+
var pageURL = uriTools.normalizeURI(tab.url);
258+
var pageDomain = uriTools.domainFromURI(pageURL);
259+
260+
if ( !pageDomain ) {
261+
return;
262+
}
263+
264+
switch ( info.menuItemId ) {
265+
case 'gdt-group0':
266+
HTTPSB.whitelistTemporarily(pageURL, '*', pageDomain);
267+
smartReloadTab(tab.id);
268+
break;
269+
270+
case 'revertPermissions':
271+
HTTPSB.revertPermissions();
272+
smartReloadTabs();
273+
break;
274+
}
275+
}
276+
277+
chrome.contextMenus.onClicked.addListener(contextMenuClickHandler);
278+
279+
/******************************************************************************/
280+
281+
function updateContextMenuHandler(tabs) {
282+
if ( !tabs.length ) {
283+
return;
284+
}
285+
var tab = tabs[0];
286+
if ( !tab.url || !tab.url.length ) {
287+
return;
288+
}
289+
var pageUrl = uriTools.normalizeURI(tab.url);
290+
var pageDomain = uriTools.domainFromURI(pageUrl);
291+
var color = HTTPSB.evaluate(pageUrl, '*', pageDomain);
292+
chrome.contextMenus.update('gdt-group0', {
293+
title: 'Temporarily whitelist *.' + pageDomain,
294+
enabled: color.charAt(0) !== 'g' && !HTTPSB.off
295+
});
296+
chrome.contextMenus.update('revertPermissions', {
297+
enabled: !HTTPSB.off
298+
});
299+
}
300+
301+
function updateContextMenu() {
302+
chrome.tabs.query({ active: true }, updateContextMenuHandler);
303+
}
304+

manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"manifest_version": 2,
33
"name": "__MSG_extName__",
4-
"version": "0.6.2",
4+
"version": "0.6.3",
55
"description": "__MSG_extShortDesc__",
66
"icons": {
7+
"16": "icon_16.png",
78
"128": "icon_128.png"
89
},
910
"browser_action": {
@@ -23,6 +24,7 @@
2324
"options_page": "settings.html",
2425
"permissions": [
2526
"contentSettings",
27+
"contextMenus",
2628
"cookies",
2729
"storage",
2830
"tabs",

0 commit comments

Comments
 (0)