Bind only one DOMContentLoaded event
This commit is contained in:
parent
5f9a4d6172
commit
cbece7ce25
10
apply.js
10
apply.js
|
@ -134,9 +134,7 @@ function applyStyles(styleHash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(g_styleElements).length) {
|
if (Object.keys(g_styleElements).length) {
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", addDocumentStylesToAllIFrames);
|
||||||
getDynamicIFrames(document).forEach(addDocumentStylesToIFrame);
|
|
||||||
});
|
|
||||||
iframeObserver.start();
|
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.
|
// Only dynamic iframes get the parent document's styles. Other ones should get styles based on their own URLs.
|
||||||
function getDynamicIFrames(doc) {
|
function getDynamicIFrames(doc) {
|
||||||
return Array.prototype.filter.call(doc.getElementsByTagName('iframe'), iframeIsDynamic);
|
return Array.prototype.filter.call(doc.getElementsByTagName('iframe'), iframeIsDynamic);
|
||||||
|
@ -253,7 +255,7 @@ function initObserver() {
|
||||||
if (mutations.length > 1000) {
|
if (mutations.length > 1000) {
|
||||||
// use a much faster method for very complex pages with 100,000 mutations
|
// use a much faster method for very complex pages with 100,000 mutations
|
||||||
// (observer usually receives 1k-10k mutations per call)
|
// (observer usually receives 1k-10k mutations per call)
|
||||||
getDynamicIFrames(document).forEach(addDocumentStylesToIFrame);
|
addDocumentStylesToAllIFrames();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// move the check out of current execution context
|
// move the check out of current execution context
|
||||||
|
|
Loading…
Reference in New Issue
Block a user