mirror of https://github.com/gorhill/uBlock.git
fix #2060
This commit is contained in:
parent
3ff3ae7d70
commit
a1fa4d0fe9
|
@ -430,43 +430,42 @@ vAPI.messaging.start();
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.userCSS = (function() {
|
||||
if ( !self.injectCSS ) {
|
||||
return;
|
||||
}
|
||||
var injectCSS = self.injectCSS,
|
||||
removeCSS = self.removeCSS,
|
||||
userCSS = '',
|
||||
sheetURI = '';
|
||||
var load = function() {
|
||||
if ( userCSS === '' || sheetURI !== '' ) { return; }
|
||||
sheetURI = 'data:text/css;charset=utf-8,' + encodeURIComponent(userCSS);
|
||||
injectCSS(sheetURI);
|
||||
};
|
||||
var unload = function() {
|
||||
if ( sheetURI === '' ) { return; }
|
||||
removeCSS(sheetURI);
|
||||
sheetURI = '';
|
||||
};
|
||||
var add = function(cssText) {
|
||||
if ( cssText === '' ) { return; }
|
||||
if ( userCSS !== '' ) { userCSS += '\n'; }
|
||||
userCSS += cssText;
|
||||
unload();
|
||||
load();
|
||||
};
|
||||
var toggle = function(state) {
|
||||
if ( userCSS === '' ) { return; }
|
||||
if ( state === undefined ) {
|
||||
state = sheetURI === '';
|
||||
if ( self.injectCSS ) {
|
||||
vAPI.userCSS = {
|
||||
_userCSS: '',
|
||||
_sheetURI: '',
|
||||
_load: function() {
|
||||
if ( this._userCSS === '' || this._sheetURI !== '' ) { return; }
|
||||
this._sheetURI = 'data:text/css;charset=utf-8,' + encodeURIComponent(this._userCSS);
|
||||
self.injectCSS(this._sheetURI);
|
||||
},
|
||||
_unload: function() {
|
||||
if ( this._sheetURI === '' ) { return; }
|
||||
self.removeCSS(this._sheetURI);
|
||||
this._sheetURI = '';
|
||||
},
|
||||
add: function(cssText) {
|
||||
if ( cssText === '' ) { return; }
|
||||
if ( this._userCSS !== '' ) { this._userCSS += '\n'; }
|
||||
this._userCSS += cssText;
|
||||
this._unload();
|
||||
this._load();
|
||||
},
|
||||
remove: function(cssText) {
|
||||
if ( cssText === '' || this._userCSS === '' ) { return; }
|
||||
this._userCSS = this._userCSS.replace(cssText, '').trim();
|
||||
this._unload();
|
||||
this._load();
|
||||
},
|
||||
toggle: function(state) {
|
||||
if ( this._userCSS === '' ) { return; }
|
||||
if ( state === undefined ) {
|
||||
state = this._sheetURI === '';
|
||||
}
|
||||
return state ? this._load() : this._unload();
|
||||
}
|
||||
return state ? load() : unload();
|
||||
};
|
||||
return {
|
||||
add: add,
|
||||
toggle: toggle
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
|
@ -292,6 +292,7 @@ var domFilterer = {
|
|||
removedNodesHandlerMissCount: 0,
|
||||
disabledId: vAPI.randomToken(),
|
||||
enabled: true,
|
||||
excludeId: undefined,
|
||||
hiddenId: vAPI.randomToken(),
|
||||
hiddenNodeCount: 0,
|
||||
hiddenNodeEnforcer: false,
|
||||
|
@ -519,10 +520,16 @@ var domFilterer = {
|
|||
}
|
||||
},
|
||||
|
||||
hideNode: function(node) {
|
||||
if ( node[this.hiddenId] !== undefined ) {
|
||||
return;
|
||||
getExcludeId: function() {
|
||||
if ( this.excludeId === undefined ) {
|
||||
this.excludeId = vAPI.randomToken();
|
||||
}
|
||||
return this.excludeId;
|
||||
},
|
||||
|
||||
hideNode: function(node) {
|
||||
if ( node[this.hiddenId] !== undefined ) { return; }
|
||||
if ( this.excludeId !== undefined && node[this.excludeId] ) { return; }
|
||||
node.setAttribute(this.hiddenId, '');
|
||||
this.hiddenNodeCount += 1;
|
||||
node.hidden = true;
|
||||
|
@ -535,9 +542,7 @@ var domFilterer = {
|
|||
if ( styleAttr !== '' ) { styleAttr += '; '; }
|
||||
node.setAttribute('style', styleAttr + 'display: none !important;');
|
||||
}
|
||||
if ( shadowId === undefined ) {
|
||||
return;
|
||||
}
|
||||
if ( shadowId === undefined ) { return; }
|
||||
var shadow = node.shadowRoot;
|
||||
if ( shadow ) {
|
||||
if ( shadow[shadowId] && shadow.firstElementChild !== null ) {
|
||||
|
|
|
@ -606,7 +606,7 @@ var filtersFrom = function(x, y) {
|
|||
// https://github.com/gorhill/uBlock/issues/1545
|
||||
// Network filter candidates from all other elements found at point (x, y).
|
||||
if ( typeof x === 'number' ) {
|
||||
var attrName = vAPI.sessionId + '-clickblind';
|
||||
var attrName = pickerRoot.id + '-clickblind';
|
||||
var previous;
|
||||
elem = first;
|
||||
while ( elem !== null ) {
|
||||
|
@ -1345,6 +1345,11 @@ var stopPicker = function() {
|
|||
return;
|
||||
}
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/2060
|
||||
if ( vAPI.userCSS ) {
|
||||
vAPI.userCSS.remove(pickerStyle.textContent);
|
||||
}
|
||||
|
||||
window.removeEventListener('scroll', onScrolled, true);
|
||||
pickerRoot.contentWindow.removeEventListener('keydown', onKeyPressed, true);
|
||||
taCandidate.removeEventListener('input', onCandidateChanged);
|
||||
|
@ -1496,16 +1501,24 @@ pickerRoot.style.cssText = [
|
|||
// a dedicated style tag.
|
||||
pickerStyle = document.createElement('style');
|
||||
pickerStyle.textContent = [
|
||||
'#' + vAPI.sessionId + ' {',
|
||||
'#' + pickerRoot.id + ' {',
|
||||
pickerRoot.style.cssText,
|
||||
'}',
|
||||
'[' + vAPI.sessionId + '-clickblind] {',
|
||||
'[' + pickerRoot.id + '-clickblind] {',
|
||||
'pointer-events: none !important;',
|
||||
'}',
|
||||
''
|
||||
].join('\n');
|
||||
document.documentElement.appendChild(pickerStyle);
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/2060
|
||||
if ( vAPI.domFilterer ) {
|
||||
pickerRoot[vAPI.domFilterer.getExcludeId()] = true;
|
||||
}
|
||||
if ( vAPI.userCSS ) {
|
||||
vAPI.userCSS.add(pickerStyle.textContent);
|
||||
}
|
||||
|
||||
pickerRoot.onload = function() {
|
||||
vAPI.shutdown.add(stopPicker);
|
||||
vAPI.messaging.send(
|
||||
|
|
Loading…
Reference in New Issue