This commit is contained in:
gorhill 2016-10-08 15:14:24 -04:00
parent 3ff3ae7d70
commit a1fa4d0fe9
3 changed files with 61 additions and 44 deletions

View File

@ -430,43 +430,42 @@ vAPI.messaging.start();
/******************************************************************************/ /******************************************************************************/
vAPI.userCSS = (function() { if ( self.injectCSS ) {
if ( !self.injectCSS ) { vAPI.userCSS = {
return; _userCSS: '',
} _sheetURI: '',
var injectCSS = self.injectCSS, _load: function() {
removeCSS = self.removeCSS, if ( this._userCSS === '' || this._sheetURI !== '' ) { return; }
userCSS = '', this._sheetURI = 'data:text/css;charset=utf-8,' + encodeURIComponent(this._userCSS);
sheetURI = ''; self.injectCSS(this._sheetURI);
var load = function() { },
if ( userCSS === '' || sheetURI !== '' ) { return; } _unload: function() {
sheetURI = 'data:text/css;charset=utf-8,' + encodeURIComponent(userCSS); if ( this._sheetURI === '' ) { return; }
injectCSS(sheetURI); self.removeCSS(this._sheetURI);
}; this._sheetURI = '';
var unload = function() { },
if ( sheetURI === '' ) { return; } add: function(cssText) {
removeCSS(sheetURI); if ( cssText === '' ) { return; }
sheetURI = ''; if ( this._userCSS !== '' ) { this._userCSS += '\n'; }
}; this._userCSS += cssText;
var add = function(cssText) { this._unload();
if ( cssText === '' ) { return; } this._load();
if ( userCSS !== '' ) { userCSS += '\n'; } },
userCSS += cssText; remove: function(cssText) {
unload(); if ( cssText === '' || this._userCSS === '' ) { return; }
load(); this._userCSS = this._userCSS.replace(cssText, '').trim();
}; this._unload();
var toggle = function(state) { this._load();
if ( userCSS === '' ) { return; } },
if ( state === undefined ) { toggle: function(state) {
state = sheetURI === ''; 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
};
})();
/******************************************************************************/ /******************************************************************************/

View File

@ -292,6 +292,7 @@ var domFilterer = {
removedNodesHandlerMissCount: 0, removedNodesHandlerMissCount: 0,
disabledId: vAPI.randomToken(), disabledId: vAPI.randomToken(),
enabled: true, enabled: true,
excludeId: undefined,
hiddenId: vAPI.randomToken(), hiddenId: vAPI.randomToken(),
hiddenNodeCount: 0, hiddenNodeCount: 0,
hiddenNodeEnforcer: false, hiddenNodeEnforcer: false,
@ -519,10 +520,16 @@ var domFilterer = {
} }
}, },
hideNode: function(node) { getExcludeId: function() {
if ( node[this.hiddenId] !== undefined ) { if ( this.excludeId === undefined ) {
return; 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, ''); node.setAttribute(this.hiddenId, '');
this.hiddenNodeCount += 1; this.hiddenNodeCount += 1;
node.hidden = true; node.hidden = true;
@ -535,9 +542,7 @@ var domFilterer = {
if ( styleAttr !== '' ) { styleAttr += '; '; } if ( styleAttr !== '' ) { styleAttr += '; '; }
node.setAttribute('style', styleAttr + 'display: none !important;'); node.setAttribute('style', styleAttr + 'display: none !important;');
} }
if ( shadowId === undefined ) { if ( shadowId === undefined ) { return; }
return;
}
var shadow = node.shadowRoot; var shadow = node.shadowRoot;
if ( shadow ) { if ( shadow ) {
if ( shadow[shadowId] && shadow.firstElementChild !== null ) { if ( shadow[shadowId] && shadow.firstElementChild !== null ) {

View File

@ -606,7 +606,7 @@ var filtersFrom = function(x, y) {
// https://github.com/gorhill/uBlock/issues/1545 // https://github.com/gorhill/uBlock/issues/1545
// Network filter candidates from all other elements found at point (x, y). // Network filter candidates from all other elements found at point (x, y).
if ( typeof x === 'number' ) { if ( typeof x === 'number' ) {
var attrName = vAPI.sessionId + '-clickblind'; var attrName = pickerRoot.id + '-clickblind';
var previous; var previous;
elem = first; elem = first;
while ( elem !== null ) { while ( elem !== null ) {
@ -1345,6 +1345,11 @@ var stopPicker = function() {
return; return;
} }
// https://github.com/gorhill/uBlock/issues/2060
if ( vAPI.userCSS ) {
vAPI.userCSS.remove(pickerStyle.textContent);
}
window.removeEventListener('scroll', onScrolled, true); window.removeEventListener('scroll', onScrolled, true);
pickerRoot.contentWindow.removeEventListener('keydown', onKeyPressed, true); pickerRoot.contentWindow.removeEventListener('keydown', onKeyPressed, true);
taCandidate.removeEventListener('input', onCandidateChanged); taCandidate.removeEventListener('input', onCandidateChanged);
@ -1496,16 +1501,24 @@ pickerRoot.style.cssText = [
// a dedicated style tag. // a dedicated style tag.
pickerStyle = document.createElement('style'); pickerStyle = document.createElement('style');
pickerStyle.textContent = [ pickerStyle.textContent = [
'#' + vAPI.sessionId + ' {', '#' + pickerRoot.id + ' {',
pickerRoot.style.cssText, pickerRoot.style.cssText,
'}', '}',
'[' + vAPI.sessionId + '-clickblind] {', '[' + pickerRoot.id + '-clickblind] {',
'pointer-events: none !important;', 'pointer-events: none !important;',
'}', '}',
'' ''
].join('\n'); ].join('\n');
document.documentElement.appendChild(pickerStyle); 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() { pickerRoot.onload = function() {
vAPI.shutdown.add(stopPicker); vAPI.shutdown.add(stopPicker);
vAPI.messaging.send( vAPI.messaging.send(