From cbece7ce25e0f31d00335ed6034941749d71f208 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 25 Dec 2015 00:39:50 +0300 Subject: [PATCH] Bind only one DOMContentLoaded event --- apply.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apply.js b/apply.js index f7d661cb..cb0b48f1 100644 --- a/apply.js +++ b/apply.js @@ -134,9 +134,7 @@ function applyStyles(styleHash) { } if (Object.keys(g_styleElements).length) { - document.addEventListener("DOMContentLoaded", function() { - getDynamicIFrames(document).forEach(addDocumentStylesToIFrame); - }); + document.addEventListener("DOMContentLoaded", addDocumentStylesToAllIFrames); iframeObserver.start(); } @@ -199,6 +197,10 @@ function addDocumentStylesToIFrame(iframe) { } } +function addDocumentStylesToAllIFrames() { + getDynamicIFrames(document).forEach(addDocumentStylesToIFrame); +} + // Only dynamic iframes get the parent document's styles. Other ones should get styles based on their own URLs. function getDynamicIFrames(doc) { return Array.prototype.filter.call(doc.getElementsByTagName('iframe'), iframeIsDynamic); @@ -253,7 +255,7 @@ function initObserver() { if (mutations.length > 1000) { // use a much faster method for very complex pages with 100,000 mutations // (observer usually receives 1k-10k mutations per call) - getDynamicIFrames(document).forEach(addDocumentStylesToIFrame); + addDocumentStylesToAllIFrames(); return; } // move the check out of current execution context