fix: copy ALL CSS custom properties via getComputedStyle from opener
- Iterates through ALL computed CSS variables (--*) from main app - Uses getComputedStyle which works even if setProperty was used (themes.js) - Sets properties via setProperty on popout root — EXACT theme match - Fallback: localStorage obsigate-theme-mode for direct popout access - Fixed typo in --text-primary (was 'teext-primary')
This commit is contained in:
+29
-17
@@ -5,24 +5,36 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>ObsiGate - Popout</title>
|
<title>ObsiGate - Popout</title>
|
||||||
<script>
|
<script>
|
||||||
// Copy theme from opener window (uses themes.js inline styles via setProperty)
|
|
||||||
(function() {
|
(function() {
|
||||||
if (window.opener && window.opener.document.documentElement.style.cssText) {
|
var root = document.documentElement;
|
||||||
// Copy all CSS variable inline styles from main app
|
// Primary: copy ALL CSS custom properties from main app's <html> element
|
||||||
document.documentElement.style.cssText = window.opener.document.documentElement.style.cssText;
|
if (window.opener) {
|
||||||
}
|
try {
|
||||||
// Fallback: read from localStorage theme key + mode
|
var openerRoot = window.opener.document.documentElement;
|
||||||
var themeKey = localStorage.getItem('obsigate-theme') || 'dark';
|
var cs = window.opener.getComputedStyle(openerRoot);
|
||||||
var themeMode = localStorage.getItem('obsigate-theme-mode') || 'dark';
|
// Copy every CSS variable (--*) from main app to popout
|
||||||
document.documentElement.setAttribute('data-theme', themeMode);
|
for (var i = 0; i < cs.length; i++) {
|
||||||
// Also set inline background/color as absolute fallback
|
var prop = cs[i];
|
||||||
if (!window.opener || !window.opener.document.documentElement.style.cssText) {
|
if (prop.startsWith('--')) {
|
||||||
var bg = themeMode === 'light' ? '#ffffff' : '#0f1117';
|
root.style.setProperty(prop, cs.getPropertyValue(prop));
|
||||||
var fg = themeMode === 'light' ? '#1a1a1a' : '#e6edf3';
|
}
|
||||||
document.documentElement.style.setProperty('--bg-primary', bg, 'important');
|
}
|
||||||
document.documentElement.style.setProperty('--text-primary', fg, 'important');
|
// Also copy inline style as backup
|
||||||
document.body.style.background = bg;
|
root.style.cssText = openerRoot.style.cssText;
|
||||||
document.body.style.color = fg;
|
// Copy data-theme attribute
|
||||||
|
root.setAttribute('data-theme', openerRoot.getAttribute('data-theme') || 'dark');
|
||||||
|
} catch(e) {
|
||||||
|
// Cross-origin or security restriction — use localStorage fallback
|
||||||
|
var mode = localStorage.getItem('obsigate-theme-mode') || 'dark';
|
||||||
|
root.setAttribute('data-theme', mode);
|
||||||
|
root.style.setProperty('--bg-primary', mode === 'light' ? '#fff' : '#0f1117');
|
||||||
|
root.style.setProperty('--text-primary', mode === 'light' ? '#1a1a1a' : '#e6edf3');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var mode = localStorage.getItem('obsigate-theme-mode') || 'dark';
|
||||||
|
root.setAttribute('data-theme', mode);
|
||||||
|
root.style.setProperty('--bg-primary', mode === 'light' ? '#fff' : '#0f1117');
|
||||||
|
root.style.setProperty('--text-primary', mode === 'light' ? '#1a1a1a' : '#e6edf3');
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user