Append addon CSS at the end of <body>

Fixes https://github.com/TurboWarp/scratch-gui/issues/685
This commit is contained in:
GarboMuffin committed 2023-01-04 16:23:54 -06:00
1 parent 003fc2550b
commit 253e48d12d
2 files changed
+5 -3

No files matched your search

+3 -3
View File
@@ -1,8 +1,8 @@
// Stylesheets are added at the start of <body> so that they have higher precedence
// than those in <head>
// Stylesheets are added at the end of <body> so that they have higher precedence
// than those in <head> and above dark mode which is appended at the start of <body>
const stylesheetContainer = document.createElement('div');
stylesheetContainer.style.display = 'none';
document.body.insertBefore(stylesheetContainer, document.body.firstChild);
document.body.appendChild(stylesheetContainer);
/**
* Maps opaque module IDs to its ConditionalStyle.
+2
View File
@@ -55,6 +55,8 @@ const ThemeHOC = function (WrappedComponent) {
const dark = this.state.dark;
document.body.setAttribute('theme', dark ? 'dark' : 'light');
if (dark && !darkModeStylesheet.parentNode) {
// Append at the start of <body> we override scratch-gui styles in <head>
// but are overridden by addon styles at the end of <body>
document.body.insertBefore(darkModeStylesheet, document.body.firstChild);
} else if (!dark && darkModeStylesheet.parentNode) {
darkModeStylesheet.parentNode.removeChild(darkModeStylesheet);