1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00
This commit is contained in:
gorhill 2015-02-14 12:16:36 -05:00
parent 5ab90edc02
commit 65b9ef2468
2 changed files with 50 additions and 28 deletions

View File

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock
*/
/* global vAPI */
/* global vAPI, HTMLDocument */
/******************************************************************************/
@ -62,7 +62,35 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
/******************************************************************************/
// ABP cosmetic filters
// https://github.com/gorhill/uBlock/issues/789
// Be sure that specific cosmetic filters are still applied.
// Executed once, then flushed from memory.
(function() {
// Were there specific cosmetic filters?
var text = vAPI.specificHideStyleText;
if ( typeof text !== 'string' ) {
return;
}
vAPI.specificHideStyleText = undefined;
// Is our style tag still available?
var style = document.getElementById('ublock-preload-1ae7a5f130fc79b4fdb8a4272d9426b5');
if ( style !== null ) {
return;
}
// Put it back
style = document.createElement('style');
style.setAttribute('id', 'ublock-preload-1ae7a5f130fc79b4fdb8a4272d9426b5');
style.appendChild(document.createTextNode(text + '\n{display:none !important;}'));
var parent = document.head || document.documentElement;
if ( parent ) {
parent.appendChild(style);
}
})();
/******************************************************************************/
// Cosmetic filters
(function() {
if ( vAPI.skipCosmeticFiltering ) {
@ -78,15 +106,6 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
var contextNodes = [document];
var nullArray = { push: function(){} };
var domLoaded = function() {
idsFromNodeList(document.querySelectorAll('[id]'));
classesFromNodeList(document.querySelectorAll('[class]'));
retrieveGenericSelectors();
// Flush dead code from memory (does this work?)
domLoaded = null;
};
var retrieveGenericSelectors = function() {
var selectors = classSelectors !== null ? Object.keys(classSelectors) : [];
if ( idSelectors !== null ) {
@ -430,7 +449,9 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
// Start cosmetic filtering.
domLoaded();
idsFromNodeList(document.querySelectorAll('[id]'));
classesFromNodeList(document.querySelectorAll('[class]'));
retrieveGenericSelectors();
// Below this point is the code which takes care to observe changes in
// the page and to add if needed relevant CSS rules as a result of the

View File

@ -20,7 +20,7 @@
*/
/* jshint multistr: true */
/* global vAPI */
/* global vAPI, HTMLDocument */
/******************************************************************************/
@ -71,31 +71,32 @@ var cosmeticFilters = function(details) {
style.setAttribute('id', 'ublock-preload-1ae7a5f130fc79b4fdb8a4272d9426b5');
var donthide = details.cosmeticDonthide;
var hide = details.cosmeticHide;
var i;
if ( donthide.length !== 0 ) {
donthide = donthide.length !== 1 ? donthide.join(',\n') : donthide[0];
donthide = donthide.split(',\n');
var i = donthide.length;
i = donthide.length;
while ( i-- ) {
donthideCosmeticFilters[donthide[i]] = true;
}
// https://github.com/gorhill/uBlock/issues/143
if ( hide.length !== 0 ) {
hide = hide.length !== 1 ? hide.join(',\n') : hide[0];
hide = hide.split(',\n');
i = hide.length;
var selector;
while ( i-- ) {
selector = hide[i];
if ( donthideCosmeticFilters[selector] ) {
hide.splice(i, 1);
} else {
hideCosmeticFilters[selector] = true;
}
}
// https://github.com/gorhill/uBlock/issues/143
if ( hide.length !== 0 ) {
hide = hide.length !== 1 ? hide.join(',\n') : hide[0];
hide = hide.split(',\n');
i = hide.length;
var selector;
while ( i-- ) {
selector = hide[i];
if ( donthideCosmeticFilters[selector] ) {
hide.splice(i, 1);
} else {
hideCosmeticFilters[selector] = true;
}
}
}
if ( hide.length !== 0 ) {
var text = hide.join(',\n');
var text = vAPI.specificHideStyleText = hide.join(',\n');
hideElements(text);
// The linefeed before the style block is very important: do not remove!
style.appendChild(document.createTextNode(text + '\n{display:none !important;}'));