1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-19 11:18:42 +02:00

no need for mutation observer if no scripting on the page

This commit is contained in:
gorhill 2014-07-30 08:05:00 -04:00
parent 297df56d84
commit e1b253fc19

View File

@ -126,8 +126,7 @@ var messaging = (function(name){
// ABP cosmetic filters
var cosmeticFiltering = (function() {
(function() {
var queriedSelectors = {};
var injectedSelectors = {};
var classSelectors = null;
@ -391,9 +390,34 @@ var cosmeticFiltering = (function() {
domLoaded();
return {
processNodeLists: processNodeLists
// Observe changes in the DOM only if...
// - there is a document.body
// - there is at least one `script` tag
if ( !document.body || !document.querySelector('script') ) {
return;
}
var mutationObservedHandler = function(mutations) {
var iMutation = mutations.length;
var nodeLists = [], nodeList;
while ( iMutation-- ) {
nodeList = mutations[iMutation].addedNodes;
if ( nodeList && nodeList.length ) {
nodeLists.push(nodeList);
}
}
if ( nodeLists.length ) {
processNodeLists(nodeLists);
}
};
// https://github.com/gorhill/httpswitchboard/issues/176
var observer = new MutationObserver(mutationObservedHandler);
observer.observe(document.body, {
attributes: false,
childList: true,
characterData: false,
subtree: true
});
})();
/******************************************************************************/
@ -455,34 +479,4 @@ var cosmeticFiltering = (function() {
/******************************************************************************/
// Observe changes in the DOM
var mutationObservedHandler = function(mutations) {
var iMutation = mutations.length;
var nodeLists = [], nodeList;
while ( iMutation-- ) {
nodeList = mutations[iMutation].addedNodes;
if ( nodeList && nodeList.length ) {
nodeLists.push(nodeList);
}
}
if ( nodeLists.length ) {
cosmeticFiltering.processNodeLists(nodeLists);
}
};
// This fixes http://acid3.acidtests.org/
if ( document.body ) {
// https://github.com/gorhill/httpswitchboard/issues/176
var observer = new MutationObserver(mutationObservedHandler);
observer.observe(document.body, {
attributes: false,
childList: true,
characterData: false,
subtree: true
});
}
/******************************************************************************/
})();