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