Restore robust window.parent theme detection for instant iframe styling

This commit is contained in:
2026-07-10 16:54:58 +05:30
parent 90700c0268
commit ead4942b6d
2 changed files with 32 additions and 10 deletions

View File

@@ -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');