mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
this fixes #143
This commit is contained in:
parent
bfbea2e12a
commit
63b3e29cbe
3 changed files with 49 additions and 51 deletions
|
|
@ -667,8 +667,8 @@ FilterContainer.prototype.retrieveDomainSelectors = function(request) {
|
||||||
donthide: []
|
donthide: []
|
||||||
};
|
};
|
||||||
|
|
||||||
var bucket;
|
var hash, bucket;
|
||||||
var hash = makeHash('#', r.domain, this.domainHashMask);
|
hash = makeHash('#', r.domain, this.domainHashMask);
|
||||||
if ( bucket = this.hostnameFilters[hash] ) {
|
if ( bucket = this.hostnameFilters[hash] ) {
|
||||||
bucket.retrieve(hostname, r.hide);
|
bucket.retrieve(hostname, r.hide);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ var messaging = (function(name){
|
||||||
var style = document.getElementById('uBlock1ae7a5f130fc79b4fdb8a4272d9426b5');
|
var style = document.getElementById('uBlock1ae7a5f130fc79b4fdb8a4272d9426b5');
|
||||||
var exceptions = style && style.getAttribute('uBlock1ae7a5f130fc79b4fdb8a4272d9426b5');
|
var exceptions = style && style.getAttribute('uBlock1ae7a5f130fc79b4fdb8a4272d9426b5');
|
||||||
if ( exceptions ) {
|
if ( exceptions ) {
|
||||||
exceptions = decodeURIComponent(exceptions).split(',');
|
exceptions = JSON.parse(exceptions);
|
||||||
var i = exceptions.length;
|
var i = exceptions.length;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
injectedSelectors[exceptions[i]] = true;
|
injectedSelectors[exceptions[i]] = true;
|
||||||
|
|
@ -173,34 +173,27 @@ var messaging = (function(name){
|
||||||
if ( !selectors ) {
|
if ( !selectors ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var styleText = [];
|
filterLowGenerics(selectors, 'donthide');
|
||||||
|
filterHighGenerics(selectors, 'donthide');
|
||||||
|
if ( selectors.donthide.length ) {
|
||||||
|
var i = selectors.donthide.length;
|
||||||
|
while ( i-- ) {
|
||||||
|
injectedSelectors[selectors.donthide[i]] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
filterLowGenerics(selectors, 'hide');
|
filterLowGenerics(selectors, 'hide');
|
||||||
filterHighGenerics(selectors, 'hide');
|
filterHighGenerics(selectors, 'hide');
|
||||||
reduce(selectors.hide, injectedSelectors);
|
reduce(selectors.hide, injectedSelectors);
|
||||||
if ( selectors.hide.length ) {
|
if ( selectors.hide.length ) {
|
||||||
var hideStyleText = '{{hideSelectors}} {display:none !important;}'
|
|
||||||
.replace('{{hideSelectors}}', selectors.hide.join(','));
|
|
||||||
styleText.push(hideStyleText);
|
|
||||||
applyCSS(selectors.hide, 'display', 'none');
|
applyCSS(selectors.hide, 'display', 'none');
|
||||||
//console.debug('µBlock> generic cosmetic filters: injecting %d CSS rules:', selectors.hide.length, hideStyleText);
|
|
||||||
}
|
|
||||||
filterLowGenerics(selectors, 'donthide');
|
|
||||||
filterHighGenerics(selectors, 'donthide');
|
|
||||||
reduce(selectors.donthide, injectedSelectors);
|
|
||||||
if ( selectors.donthide.length ) {
|
|
||||||
var dontHideStyleText = '{{donthideSelectors}} {display:initial !important;}'
|
|
||||||
.replace('{{donthideSelectors}}', selectors.donthide.join(','));
|
|
||||||
styleText.push(dontHideStyleText);
|
|
||||||
applyCSS(selectors.donthide, 'display', 'initial');
|
|
||||||
//console.debug('µBlock> generic cosmetic filters: injecting %d CSS rules:', selectors.donthide.length, dontHideStyleText);
|
|
||||||
}
|
|
||||||
if ( styleText.length > 0 ) {
|
|
||||||
var style = document.createElement('style');
|
var style = document.createElement('style');
|
||||||
style.appendChild(document.createTextNode(styleText.join('\n')));
|
var text = selectors.hide.join(',\n') + ' {display:none !important;}';
|
||||||
|
style.appendChild(document.createTextNode(text));
|
||||||
var parent = document.body || document.documentElement;
|
var parent = document.body || document.documentElement;
|
||||||
if ( parent ) {
|
if ( parent ) {
|
||||||
parent.appendChild(style);
|
parent.appendChild(style);
|
||||||
}
|
}
|
||||||
|
//console.debug('µBlock> generic cosmetic filters: injecting %d CSS rules:', selectors.hide.length, hideStyleText);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,38 +137,43 @@ var domainCosmeticFilteringHandler = function(selectors) {
|
||||||
if ( !selectors ) {
|
if ( !selectors ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var styleText = [];
|
if ( selectors.hide.length === 0 && selectors.donthide.length === 0 ) {
|
||||||
if ( selectors.hide.length ) {
|
return;
|
||||||
var hideStyleText = '{{hideSelectors}} {display:none !important;}'
|
}
|
||||||
.replace('{{hideSelectors}}', selectors.hide.join(','));
|
var style = document.createElement('style');
|
||||||
styleText.push(hideStyleText);
|
var donthide = selectors.donthide;
|
||||||
domainCosmeticFilteringApplyCSS(selectors.hide, 'display', 'none');
|
var hide = selectors.hide;
|
||||||
|
if ( donthide.length !== 0 ) {
|
||||||
|
donthide = donthide.length !== 1 ? donthide.join(',') : donthide[0];
|
||||||
|
donthide = donthide.split(',');
|
||||||
|
style.setAttribute('id', 'uBlock1ae7a5f130fc79b4fdb8a4272d9426b5');
|
||||||
|
style.setAttribute('uBlock1ae7a5f130fc79b4fdb8a4272d9426b5', JSON.stringify(donthide));
|
||||||
|
// https://github.com/gorhill/uBlock/issues/143
|
||||||
|
if ( hide.length !== 0 ) {
|
||||||
|
// I chose to use Array.indexOf() instead of converting the array to
|
||||||
|
// a map, then deleting whitelisted selectors, and then converting
|
||||||
|
// back the map into an array, because there are typically very few
|
||||||
|
// exception filters, if any.
|
||||||
|
hide = hide.length !== 1 ? hide.join(',') : hide[0];
|
||||||
|
hide = hide.split(',');
|
||||||
|
var i = donthide.length, j;
|
||||||
|
while ( i-- ) {
|
||||||
|
j = hide.indexOf(donthide[i]);
|
||||||
|
if ( j !== -1 ) {
|
||||||
|
hide.splice(j, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( hide.length !== 0 ) {
|
||||||
|
var text = hide.join(',');
|
||||||
|
domainCosmeticFilteringApplyCSS(text, 'display', 'none');
|
||||||
|
style.appendChild(document.createTextNode(text + ' {display:none !important;}'));
|
||||||
//console.debug('µBlock> "%s" cosmetic filters: injecting %d CSS rules:', selectors.domain, selectors.hide.length, hideStyleText);
|
//console.debug('µBlock> "%s" cosmetic filters: injecting %d CSS rules:', selectors.domain, selectors.hide.length, hideStyleText);
|
||||||
}
|
}
|
||||||
if ( selectors.donthide.length ) {
|
var parent = document.head || document.documentElement;
|
||||||
var dontHideStyleText = '{{donthideSelectors}} {display:initial !important;}'
|
if ( parent ) {
|
||||||
.replace('{{donthideSelectors}}', selectors.donthide.join(','));
|
parent.appendChild(style);
|
||||||
styleText.push(dontHideStyleText);
|
|
||||||
domainCosmeticFilteringApplyCSS(selectors.donthide, 'display', 'initial');
|
|
||||||
//console.debug('µBlock> "%s" cosmetic filters: injecting %d CSS rules:', selectors.domain, selectors.donthide.length, dontHideStyleText);
|
|
||||||
}
|
|
||||||
if ( styleText.length > 0 ) {
|
|
||||||
var style = document.createElement('style');
|
|
||||||
style.appendChild(document.createTextNode(styleText.join('\n')));
|
|
||||||
if ( selectors.donthide.length > 0 ) {
|
|
||||||
style.setAttribute(
|
|
||||||
'id',
|
|
||||||
'uBlock1ae7a5f130fc79b4fdb8a4272d9426b5'
|
|
||||||
);
|
|
||||||
style.setAttribute(
|
|
||||||
'uBlock1ae7a5f130fc79b4fdb8a4272d9426b5',
|
|
||||||
encodeURIComponent(selectors.donthide.join(','))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
var parent = document.head || document.documentElement;
|
|
||||||
if ( parent ) {
|
|
||||||
parent.appendChild(style);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue