Skip to content

Commit

Permalink
Experimental fix for #44
Browse files Browse the repository at this point in the history
Disregard no-popups per-site switch for a URL which matches
a link clicked by the user.
  • Loading branch information
gorhill committed Sep 10, 2015
1 parent 6763cca commit 36a15e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ return {
noopFunc: function(){},

apiErrorCount: 0,
contextMenuClientX: -1,
contextMenuClientY: -1,
mouseX: -1,
mouseY: -1,
mouseURL: '',
epickerTarget: '',
epickerEprom: null,

Expand Down
13 changes: 7 additions & 6 deletions src/js/contentscript-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,19 +897,20 @@ var uBlockCollapser = (function() {
if ( window !== window.top ) {
return;
}
var onContextMenu = function(ev) {
var onMouseClick = function(ev) {
messager.send({
what: 'contextMenuEvent',
clientX: ev.clientX,
clientY: ev.clientY
what: 'mouseClick',
x: ev.clientX,
y: ev.clientY,
url: ev.target && ev.target.localName === 'a' ? ev.target.href : ''
});
};

window.addEventListener('contextmenu', onContextMenu, true);
window.addEventListener('contextmenu', onMouseClick, true);

// https://github.com/gorhill/uMatrix/issues/144
vAPI.shutdown.add(function() {
document.removeEventListener('contextmenu', onContextMenu, true);
document.removeEventListener('contextmenu', onMouseClick, true);
});
})();

Expand Down
17 changes: 9 additions & 8 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ var onMessage = function(request, sender, callback) {
var response;

switch ( request.what ) {
case 'contextMenuEvent':
µb.contextMenuClientX = request.clientX;
µb.contextMenuClientY = request.clientY;
case 'mouseClick':
µb.mouseX = request.x;
µb.mouseY = request.y;
µb.mouseURL = request.url;
break;

case 'cosmeticFiltersInjected':
Expand Down Expand Up @@ -133,7 +134,7 @@ var onMessage = function(request, sender, callback) {

case 'launchElementPicker':
// Launched from some auxiliary pages, clear context menu coords.
µb.contextMenuClientX = µb.contextMenuClientY = -1;
µb.mouseX = µb.mouseY = -1;
µb.elementPickerExec(request.tabId, request.targetURL);
break;

Expand Down Expand Up @@ -633,14 +634,14 @@ var onMessage = function(request, sender, callback) {
callback({
frameContent: this.responseText.replace(reStrings, replacer),
target: µb.epickerTarget,
clientX: µb.contextMenuClientX,
clientY: µb.contextMenuClientY,
clientX: µb.mouseX,
clientY: µb.mouseY,
eprom: µb.epickerEprom
});

µb.epickerTarget = '';
µb.contextMenuClientX = -1;
µb.contextMenuClientY = -1;
µb.mouseX = -1;
µb.mouseY = -1;
};
xhr.send();
return;
Expand Down
5 changes: 4 additions & 1 deletion src/js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,10 @@ vAPI.tabs.onPopup = function(details) {
var loggerEnabled = µb.logger.isEnabled();

// Check user switch first
if ( µb.hnSwitches.evaluateZ('no-popups', openerHostname) ) {
if (
targetURL !== µb.mouseURL &&
µb.hnSwitches.evaluateZ('no-popups', openerHostname)
) {
result = 'ub:no-popups: ' + µb.hnSwitches.z + ' true';
}

Expand Down

0 comments on commit 36a15e2

Please sign in to comment.