This commit is contained in:
gorhill 2017-05-14 12:01:56 -04:00
parent a97c5cdaf4
commit 8f42232105
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 17 additions and 19 deletions

View File

@ -233,7 +233,7 @@ var platformHideNode = vAPI.hideNode,
var uid, var uid,
timer, timer,
observer, observer,
changedNodes = [], changedNodes = new Set(),
observerOptions = { observerOptions = {
attributes: true, attributes: true,
attributeFilter: [ 'style' ] attributeFilter: [ 'style' ]
@ -256,34 +256,33 @@ var platformHideNode = vAPI.hideNode,
// on sites which try to use inline styles to bypass blockers. // on sites which try to use inline styles to bypass blockers.
var batchProcess = function() { var batchProcess = function() {
timer.clear(); timer.clear();
var cNodes = changedNodes, i = cNodes.length, var uid_ = uid;
vNodes = [], j = 0, for ( var node of changedNodes ) {
node; if (
while ( i-- ) { node[uid_] === undefined ||
node = cNodes[i]; node.clientHeight === 0 || node.clientWidth === 0
if ( node[uid] !== undefined && node.clientHeight && node.clientWidth ) { ) {
vNodes[j++] = node; continue;
} }
}
cNodes.length = 0;
while ( j-- ) {
node = vNodes[j];
var attr = node.getAttribute('style'); var attr = node.getAttribute('style');
if ( !attr ) { if ( attr === null ) {
attr = ''; attr = '';
} else { } else if (
attr.length !== 0 &&
attr.charCodeAt(attr.length - 1) !== 0x3B /* ';' */
) {
attr += '; '; attr += '; ';
} }
node.setAttribute('style', attr + 'display: none !important;'); node.setAttribute('style', attr + 'display: none !important;');
} }
changedNodes.clear();
}; };
var observerHandler = function(mutations) { var observerHandler = function(mutations) {
var i = mutations.length, var i = mutations.length,
cNodes = changedNodes, changedNodes_ = changedNodes;
j = cNodes.length;
while ( i-- ) { while ( i-- ) {
cNodes[j++] = mutations[i].target; changedNodes_.add(mutations[i].target);
} }
timer.start(); timer.start();
}; };
@ -297,8 +296,7 @@ var platformHideNode = vAPI.hideNode,
node[uid] = node.hasAttribute('style') && (node.getAttribute('style') || ''); node[uid] = node.hasAttribute('style') && (node.getAttribute('style') || '');
} }
// Performance: batch-process nodes to hide. // Performance: batch-process nodes to hide.
var cNodes = changedNodes; changedNodes.add(node);
cNodes[cNodes.length] = node;
timer.start(); timer.start();
if ( observer === undefined ) { if ( observer === undefined ) {
observer = new MutationObserver(observerHandler); observer = new MutationObserver(observerHandler);