remove context menu entry and picker tools for whitelisted sites

This commit is contained in:
Raymond Hill 2018-09-07 10:42:59 -04:00
parent 89c073f3e9
commit 8b5a7aa398
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 15 additions and 23 deletions

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2017 Raymond Hill Copyright (C) 2014-present Raymond Hill
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -33,19 +33,13 @@ if ( vAPI.contextMenu === undefined ) {
}; };
} }
var µb = µBlock;
/******************************************************************************/ /******************************************************************************/
var onBlockElement = function(details, tab) { var onBlockElement = function(details, tab) {
if ( tab === undefined ) { if ( tab === undefined ) { return; }
return; if ( /^https?:\/\//.test(tab.url) === false ) { return; }
} let tagName = details.tagName || '';
if ( /^https?:\/\//.test(tab.url) === false ) { let src = details.frameUrl || details.srcUrl || details.linkUrl || '';
return;
}
var tagName = details.tagName || '';
var src = details.frameUrl || details.srcUrl || details.linkUrl || '';
if ( !tagName ) { if ( !tagName ) {
if ( typeof details.frameUrl === 'string' ) { if ( typeof details.frameUrl === 'string' ) {
@ -63,14 +57,14 @@ var onBlockElement = function(details, tab) {
} }
} }
µb.elementPickerExec(tab.id, tagName + '\t' + src); µBlock.elementPickerExec(tab.id, tagName + '\t' + src);
}; };
/******************************************************************************/ /******************************************************************************/
var onTemporarilyAllowLargeMediaElements = function(details, tab) { var onTemporarilyAllowLargeMediaElements = function(details, tab) {
if ( tab === undefined ) { return; } if ( tab === undefined ) { return; }
var pageStore = µb.pageStoreFromTabId(tab.id); let pageStore = µBlock.pageStoreFromTabId(tab.id);
if ( pageStore === null ) { return; } if ( pageStore === null ) { return; }
pageStore.temporarilyAllowLargeMediaElements(true); pageStore.temporarilyAllowLargeMediaElements(true);
}; };
@ -106,21 +100,19 @@ var menuEntries = [
/******************************************************************************/ /******************************************************************************/
var update = function(tabId) { var update = function(tabId) {
var newBits = 0; let newBits = 0;
if ( µb.userSettings.contextMenuEnabled && tabId !== null ) { if ( µBlock.userSettings.contextMenuEnabled && tabId !== null ) {
var pageStore = µb.pageStoreFromTabId(tabId); let pageStore = µBlock.pageStoreFromTabId(tabId);
if ( pageStore ) { if ( pageStore && pageStore.getNetFilteringSwitch() ) {
newBits |= 0x01; newBits |= 0x01;
if ( pageStore.largeMediaCount !== 0 ) { if ( pageStore.largeMediaCount !== 0 ) {
newBits |= 0x02; newBits |= 0x02;
} }
} }
} }
if ( newBits === currentBits ) { if ( newBits === currentBits ) { return; }
return;
}
currentBits = newBits; currentBits = newBits;
var usedEntries = []; let usedEntries = [];
if ( newBits & 0x01 ) { if ( newBits & 0x01 ) {
usedEntries.push(menuEntries[0]); usedEntries.push(menuEntries[0]);
} }
@ -138,7 +130,7 @@ vAPI.contextMenu.onMustUpdate = update;
return { return {
update: function(tabId) { update: function(tabId) {
if ( µb.userSettings.contextMenuEnabled && tabId === undefined ) { if ( µBlock.userSettings.contextMenuEnabled && tabId === undefined ) {
vAPI.tabs.get(null, function(tab) { vAPI.tabs.get(null, function(tab) {
if ( tab ) { if ( tab ) {
update(tab.id); update(tab.id);

View File

@ -325,7 +325,7 @@ var popupDataFromTabId = function(tabId, tabTitle) {
r.hostnameDict = getHostnameDict(pageStore.hostnameToCountMap); r.hostnameDict = getHostnameDict(pageStore.hostnameToCountMap);
r.contentLastModified = pageStore.contentLastModified; r.contentLastModified = pageStore.contentLastModified;
r.firewallRules = getFirewallRules(rootHostname, r.hostnameDict); r.firewallRules = getFirewallRules(rootHostname, r.hostnameDict);
r.canElementPicker = µb.URI.isNetworkURI(r.rawURL); r.canElementPicker = µb.URI.isNetworkURI(r.rawURL) && r.netFilteringSwitch;
r.noPopups = µb.sessionSwitches.evaluateZ('no-popups', rootHostname); r.noPopups = µb.sessionSwitches.evaluateZ('no-popups', rootHostname);
r.popupBlockedCount = pageStore.popupBlockedCount; r.popupBlockedCount = pageStore.popupBlockedCount;
r.noCosmeticFiltering = µb.sessionSwitches.evaluateZ('no-cosmetic-filtering', rootHostname); r.noCosmeticFiltering = µb.sessionSwitches.evaluateZ('no-cosmetic-filtering', rootHostname);