Move styles after <head> once it appears; fixes #103

This commit is contained in:
tophf 2017-06-22 12:16:20 +03:00
parent 028ac1d299
commit c0fe8dbf43

View File

@ -12,6 +12,7 @@ var styleElements = new Map();
var disabledElements = new Map();
var retiredStyleTimers = new Map();
var docRewriteObserver;
var docHeadObserver;
requestStyles();
chrome.runtime.onMessage.addListener(applyOnMessage);
@ -211,6 +212,17 @@ function applyStyles(styles) {
}
});
}
// TODO: remove when https://bugzilla.mozilla.org/show_bug.cgi?id=1375358 is fixed
if (styleElements.size && !document.head && !docHeadObserver) {
docHeadObserver = new MutationObserver(() => {
docHeadObserver.disconnect();
docHeadObserver = null;
for (const el of styleElements.values()) {
ROOT.insertBefore(el, document.body);
}
});
docHeadObserver.observe(ROOT, {childList: true});
}
}