From 8f42232105d0dc23d951ae093ba1b52899606ea5 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 14 May 2017 12:01:56 -0400 Subject: [PATCH] fix #2609 --- src/js/contentscript.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/js/contentscript.js b/src/js/contentscript.js index 5d313d6df..dab855408 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -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);