mirror of https://github.com/gorhill/uBlock.git
Prevent sites from disabling mouse events for element picker
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/380
Previous fix was incorrect:
84818fcd84
Additionally, I fixed the "Network filters" or "Cosmetic filters"
sections not being properly hidden when there was not valid
filters found.
This commit is contained in:
parent
86e5d0384c
commit
e8ff6a2abf
|
@ -704,7 +704,7 @@ var filtersFrom = function(x, y) {
|
||||||
TODO: need to be revised once I implement chained cosmetic operators.
|
TODO: need to be revised once I implement chained cosmetic operators.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
var filterToDOMInterface = (function() {
|
const filterToDOMInterface = (function() {
|
||||||
// Net filters: we need to lookup manually -- translating into a foolproof
|
// Net filters: we need to lookup manually -- translating into a foolproof
|
||||||
// CSS selector is just not possible.
|
// CSS selector is just not possible.
|
||||||
var fromNetworkFilter = function(filter) {
|
var fromNetworkFilter = function(filter) {
|
||||||
|
@ -997,7 +997,7 @@ var filterToDOMInterface = (function() {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var userFilterFromCandidate = function(callback) {
|
const userFilterFromCandidate = function(callback) {
|
||||||
var v = rawFilterFromTextarea();
|
var v = rawFilterFromTextarea();
|
||||||
filterToDOMInterface.set(v, function(items) {
|
filterToDOMInterface.set(v, function(items) {
|
||||||
if ( !items || items.length === 0 ) {
|
if ( !items || items.length === 0 ) {
|
||||||
|
@ -1041,7 +1041,7 @@ var userFilterFromCandidate = function(callback) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var onCandidateChanged = (function() {
|
const onCandidateChanged = (function() {
|
||||||
var process = function(items) {
|
var process = function(items) {
|
||||||
var elems = [], valid = items !== undefined;
|
var elems = [], valid = items !== undefined;
|
||||||
if ( valid ) {
|
if ( valid ) {
|
||||||
|
@ -1064,7 +1064,7 @@ var onCandidateChanged = (function() {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var candidateFromFilterChoice = function(filterChoice) {
|
const candidateFromFilterChoice = function(filterChoice) {
|
||||||
let slot = filterChoice.slot;
|
let slot = filterChoice.slot;
|
||||||
let filters = filterChoice.filters;
|
let filters = filterChoice.filters;
|
||||||
let filter = filters[slot];
|
let filter = filters[slot];
|
||||||
|
@ -1127,7 +1127,7 @@ var candidateFromFilterChoice = function(filterChoice) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var filterChoiceFromEvent = function(ev) {
|
const filterChoiceFromEvent = function(ev) {
|
||||||
var li = ev.target;
|
var li = ev.target;
|
||||||
var isNetFilter = li.textContent.slice(0, 2) !== '##';
|
var isNetFilter = li.textContent.slice(0, 2) !== '##';
|
||||||
var r = {
|
var r = {
|
||||||
|
@ -1207,7 +1207,7 @@ const onDialogClicked = function(ev) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var removeAllChildren = function(parent) {
|
const removeAllChildren = function(parent) {
|
||||||
while ( parent.firstChild ) {
|
while ( parent.firstChild ) {
|
||||||
parent.removeChild(parent.firstChild);
|
parent.removeChild(parent.firstChild);
|
||||||
}
|
}
|
||||||
|
@ -1215,9 +1215,6 @@ var removeAllChildren = function(parent) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// TODO: for convenience I could provide a small set of net filters instead
|
|
||||||
// of just a single one. Truncating the right-most part of the path etc.
|
|
||||||
|
|
||||||
const showDialog = function(options) {
|
const showDialog = function(options) {
|
||||||
pausePicker();
|
pausePicker();
|
||||||
|
|
||||||
|
@ -1230,16 +1227,19 @@ const showDialog = function(options) {
|
||||||
|
|
||||||
// Create lists of candidate filters
|
// Create lists of candidate filters
|
||||||
const populate = function(src, des) {
|
const populate = function(src, des) {
|
||||||
var root = dialog.querySelector(des);
|
const root = dialog.querySelector(des);
|
||||||
var ul = root.querySelector('ul');
|
const ul = root.querySelector('ul');
|
||||||
removeAllChildren(ul);
|
removeAllChildren(ul);
|
||||||
var li;
|
for ( let i = 0; i < src.length; i++ ) {
|
||||||
for ( var i = 0; i < src.length; i++ ) {
|
const li = document.createElement('li');
|
||||||
li = document.createElement('li');
|
|
||||||
li.textContent = src[i];
|
li.textContent = src[i];
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
}
|
}
|
||||||
root.style.display = src.length !== 0 ? '' : 'none';
|
if ( src.length !== 0 ) {
|
||||||
|
root.style.removeProperty('display');
|
||||||
|
} else {
|
||||||
|
root.style.setProperty('display', 'none', 'important');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
populate(netFilterCandidates, '#netFilters');
|
populate(netFilterCandidates, '#netFilters');
|
||||||
|
@ -1298,32 +1298,33 @@ var elementFromPoint = (function() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( !pickerRoot ) { return null; }
|
if ( !pickerRoot ) { return null; }
|
||||||
pickerRoot.style.pointerEvents = 'none';
|
pickerRoot.style.setProperty('pointer-events', 'none', 'important');
|
||||||
var elem = document.elementFromPoint(x, y);
|
var elem = document.elementFromPoint(x, y);
|
||||||
if ( elem === document.body || elem === document.documentElement ) {
|
if ( elem === document.body || elem === document.documentElement ) {
|
||||||
elem = null;
|
elem = null;
|
||||||
}
|
}
|
||||||
pickerRoot.style.pointerEvents = '';
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/380
|
||||||
|
pickerRoot.style.setProperty('pointer-events', 'auto', 'important');
|
||||||
return elem;
|
return elem;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var onSvgHovered = (function() {
|
const onSvgHovered = (function() {
|
||||||
var timer = null;
|
let timer;
|
||||||
var mx = 0, my = 0;
|
let mx = 0, my = 0;
|
||||||
|
|
||||||
var onTimer = function() {
|
const onTimer = function() {
|
||||||
timer = null;
|
timer = undefined;
|
||||||
var elem = elementFromPoint(mx, my);
|
const elem = elementFromPoint(mx, my);
|
||||||
highlightElements(elem ? [elem] : []);
|
highlightElements(elem ? [elem] : []);
|
||||||
};
|
};
|
||||||
|
|
||||||
return function onMove(ev) {
|
return function onMove(ev) {
|
||||||
mx = ev.clientX;
|
mx = ev.clientX;
|
||||||
my = ev.clientY;
|
my = ev.clientY;
|
||||||
if ( timer === null ) {
|
if ( timer === undefined ) {
|
||||||
timer = vAPI.setTimeout(onTimer, 40);
|
timer = vAPI.setTimeout(onTimer, 40);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1677,7 +1678,6 @@ const pickerCSSStyle = [
|
||||||
'opacity: 1',
|
'opacity: 1',
|
||||||
'outline: 0',
|
'outline: 0',
|
||||||
'padding: 0',
|
'padding: 0',
|
||||||
'pointer-events: auto',
|
|
||||||
'position: fixed',
|
'position: fixed',
|
||||||
'top: 0',
|
'top: 0',
|
||||||
'visibility: visible',
|
'visibility: visible',
|
||||||
|
@ -1688,12 +1688,12 @@ const pickerCSSStyle = [
|
||||||
pickerRoot.style.cssText = pickerCSSStyle;
|
pickerRoot.style.cssText = pickerCSSStyle;
|
||||||
|
|
||||||
const pickerCSS1 = [
|
const pickerCSS1 = [
|
||||||
'#' + pickerRoot.id + ' {',
|
`#${pickerRoot.id} {`,
|
||||||
pickerCSSStyle,
|
pickerCSSStyle,
|
||||||
'}'
|
'}'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
const pickerCSS2 = [
|
const pickerCSS2 = [
|
||||||
'[' + pickerRoot.id + '-clickblind] {',
|
`[${pickerRoot.id}-clickblind] {`,
|
||||||
'pointer-events: none !important;',
|
'pointer-events: none !important;',
|
||||||
'}'
|
'}'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
Loading…
Reference in New Issue