mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-05 18:32:30 +01:00
Revisit element picker arguments code
No need to store mouse coordinates in background page, thus no need to post mouse coordinates information for every click. Rename/group element picker arguments and popup arguments separately.
This commit is contained in:
parent
146e2ff186
commit
917f3620e0
@ -174,16 +174,17 @@ const µBlock = (function() { // jshint ignore:line
|
||||
|
||||
apiErrorCount: 0,
|
||||
|
||||
mouseEventRegister: {
|
||||
tabId: '',
|
||||
x: -1,
|
||||
y: -1,
|
||||
url: ''
|
||||
maybeGoodPopup: {
|
||||
tabId: 0,
|
||||
url: '',
|
||||
},
|
||||
|
||||
epickerTarget: '',
|
||||
epickerZap: false,
|
||||
epickerEprom: null,
|
||||
epickerArgs: {
|
||||
eprom: null,
|
||||
mouse: false,
|
||||
target: '',
|
||||
zap: false,
|
||||
},
|
||||
|
||||
scriptlets: {},
|
||||
|
||||
|
@ -136,7 +136,7 @@ vAPI.commands.onCommand.addListener(async command => {
|
||||
case 'launch-element-zapper': {
|
||||
const tab = await vAPI.tabs.getCurrent();
|
||||
if ( tab instanceof Object === false ) { return; }
|
||||
µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1;
|
||||
µb.epickerArgs.mouse = false;
|
||||
µb.elementPickerExec(
|
||||
tab.id,
|
||||
undefined,
|
||||
|
@ -1417,23 +1417,25 @@ vAPI.bootstrap = (function() {
|
||||
return;
|
||||
}
|
||||
|
||||
// To send mouse coordinates to main process, as the chrome API fails
|
||||
// to provide the mouse position to context menu listeners.
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/1143
|
||||
// Also, find a link under the mouse, to try to avoid confusing new tabs
|
||||
// as nuisance popups.
|
||||
// Ref.: https://developer.mozilla.org/en-US/docs/Web/Events/contextmenu
|
||||
// To be used by element picker/zapper.
|
||||
vAPI.mouseClick = { x: -1, y: -1 };
|
||||
|
||||
const onMouseClick = function(ev) {
|
||||
if ( ev.isTrusted === false ) { return; }
|
||||
vAPI.mouseClick.x = ev.clientX;
|
||||
vAPI.mouseClick.y = ev.clientY;
|
||||
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/1143
|
||||
// Find a link under the mouse, to try to avoid confusing new tabs
|
||||
// as nuisance popups.
|
||||
let elem = ev.target;
|
||||
while ( elem !== null && elem.localName !== 'a' ) {
|
||||
elem = elem.parentElement;
|
||||
}
|
||||
if ( elem === null ) { return; }
|
||||
vAPI.messaging.send('contentscript', {
|
||||
what: 'mouseClick',
|
||||
x: ev.clientX,
|
||||
y: ev.clientY,
|
||||
url: elem !== null && ev.isTrusted !== false ? elem.href : '',
|
||||
what: 'maybeGoodPopup',
|
||||
url: elem.href || '',
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -57,6 +57,7 @@ const onBlockElement = function(details, tab) {
|
||||
}
|
||||
}
|
||||
|
||||
µBlock.epickerArgs.mouse = true;
|
||||
µBlock.elementPickerExec(tab.id, tagName + '\t' + src);
|
||||
};
|
||||
|
||||
|
@ -129,7 +129,7 @@ const onMessage = function(request, sender, callback) {
|
||||
|
||||
case 'launchElementPicker':
|
||||
// Launched from some auxiliary pages, clear context menu coords.
|
||||
µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1;
|
||||
µb.epickerArgs.mouse = false;
|
||||
µb.elementPickerExec(request.tabId, request.targetURL, request.zap);
|
||||
break;
|
||||
|
||||
@ -539,11 +539,9 @@ const onMessage = function(request, sender, callback) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mouseClick':
|
||||
µb.mouseEventRegister.tabId = tabId;
|
||||
µb.mouseEventRegister.x = request.x;
|
||||
µb.mouseEventRegister.y = request.y;
|
||||
µb.mouseEventRegister.url = request.url;
|
||||
case 'maybeGoodPopup':
|
||||
µb.maybeGoodPopup.tabId = tabId;
|
||||
µb.maybeGoodPopup.url = request.url;
|
||||
break;
|
||||
|
||||
case 'shouldRenderNoscriptTags':
|
||||
@ -669,15 +667,13 @@ const onMessage = function(request, sender, callback) {
|
||||
|
||||
callback({
|
||||
frameContent: this.responseText.replace(reStrings, replacer),
|
||||
target: µb.epickerTarget,
|
||||
clientX: µb.mouseEventRegister.x,
|
||||
clientY: µb.mouseEventRegister.y,
|
||||
zap: µb.epickerZap,
|
||||
eprom: µb.epickerEprom
|
||||
target: µb.epickerArgs.target,
|
||||
mouse: µb.epickerArgs.mouse,
|
||||
zap: µb.epickerArgs.zap,
|
||||
eprom: µb.epickerArgs.eprom,
|
||||
});
|
||||
|
||||
µb.epickerTarget = '';
|
||||
µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1;
|
||||
µb.epickerArgs.target = '';
|
||||
};
|
||||
xhr.send();
|
||||
return;
|
||||
@ -703,7 +699,7 @@ const onMessage = function(request, sender, callback) {
|
||||
break;
|
||||
|
||||
case 'elementPickerEprom':
|
||||
µb.epickerEprom = request;
|
||||
µb.epickerArgs.eprom = request;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1636,8 +1636,12 @@ const startPicker = function(details) {
|
||||
highlightElements([], true);
|
||||
|
||||
// Try using mouse position
|
||||
if ( details.clientX !== -1 ) {
|
||||
if ( filtersFrom(details.clientX, details.clientY) !== 0 ) {
|
||||
if (
|
||||
details.mouse &&
|
||||
typeof vAPI.mouseClick.x === 'number' &&
|
||||
vAPI.mouseClick.x > 0
|
||||
) {
|
||||
if ( filtersFrom(vAPI.mouseClick.x, vAPI.mouseClick.y) !== 0 ) {
|
||||
showDialog();
|
||||
return;
|
||||
}
|
||||
|
@ -437,8 +437,8 @@ housekeep itself.
|
||||
this.opener = {
|
||||
tabId: openerTabId,
|
||||
popunder: false,
|
||||
trustedURL: openerTabId === µb.mouseEventRegister.tabId
|
||||
? µb.mouseEventRegister.url
|
||||
trustedURL: openerTabId === µb.maybeGoodPopup.tabId
|
||||
? µb.maybeGoodPopup.url
|
||||
: ''
|
||||
};
|
||||
this.selfDestructionTimer = null;
|
||||
|
@ -414,22 +414,22 @@ const matchBucket = function(url, hostname, bucket, start) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µBlock.elementPickerExec = async function(tabId, targetElement, zap) {
|
||||
µBlock.elementPickerExec = async function(tabId, targetElement, zap = false) {
|
||||
if ( vAPI.isBehindTheSceneTabId(tabId) ) { return; }
|
||||
|
||||
this.epickerTarget = targetElement || '';
|
||||
this.epickerZap = zap || false;
|
||||
this.epickerArgs.target = targetElement || '';
|
||||
this.epickerArgs.zap = zap;
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/40
|
||||
// The element picker needs this library
|
||||
vAPI.tabs.executeScript(tabId, {
|
||||
file: '/lib/diff/swatinem_diff.js',
|
||||
runAt: 'document_end'
|
||||
runAt: 'document_end',
|
||||
});
|
||||
|
||||
await vAPI.tabs.executeScript(tabId, {
|
||||
file: '/js/scriptlets/element-picker.js',
|
||||
runAt: 'document_end'
|
||||
runAt: 'document_end',
|
||||
});
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/168
|
||||
|
Loading…
Reference in New Issue
Block a user