Move styles after <head> once it appears; fixes #103
This commit is contained in:
parent
028ac1d299
commit
c0fe8dbf43
12
apply.js
12
apply.js
|
@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user