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
1 changed files with 28 additions and 34 deletions

View File

@ -126,8 +126,7 @@ var messaging = (function(name){
// ABP cosmetic filters // ABP cosmetic filters
var cosmeticFiltering = (function() { (function() {
var queriedSelectors = {}; var queriedSelectors = {};
var injectedSelectors = {}; var injectedSelectors = {};
var classSelectors = null; var classSelectors = null;
@ -391,9 +390,34 @@ var cosmeticFiltering = (function() {
domLoaded(); domLoaded();
return { // Observe changes in the DOM only if...
processNodeLists: processNodeLists // - 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
});
}
/******************************************************************************/
})(); })();