Restore robust window.parent theme detection for instant iframe styling
This commit is contained in:
@@ -64,8 +64,14 @@ def port_html():
|
||||
# Inject theme initialization at start of script block
|
||||
init_theme_script = """<script>
|
||||
(function(){
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
window.isLightTheme = p.get('theme') === 'light';
|
||||
let isLight = false;
|
||||
try {
|
||||
isLight = !window.parent.document.documentElement.classList.contains('dark');
|
||||
} catch (e) {
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
isLight = p.get('theme') === 'light';
|
||||
}
|
||||
window.isLightTheme = isLight;
|
||||
})();
|
||||
"""
|
||||
html = html.replace("<script>", init_theme_script, 1)
|
||||
@@ -106,9 +112,14 @@ def port_html():
|
||||
<script>
|
||||
(function(){
|
||||
setInterval(() => {
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
window.isLightTheme = p.get('theme') === 'light';
|
||||
const isLight = window.isLightTheme;
|
||||
let isLight = false;
|
||||
try {
|
||||
isLight = !window.parent.document.documentElement.classList.contains('dark');
|
||||
} catch (e) {
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
isLight = p.get('theme') === 'light';
|
||||
}
|
||||
window.isLightTheme = isLight;
|
||||
|
||||
if (isLight) {
|
||||
document.body.style.setProperty('background', '#ffffff', 'important');
|
||||
|
||||
Reference in New Issue
Block a user