feat: sync embedded analytics theme with parent app

This commit is contained in:
2026-04-02 20:11:33 +08:00
parent 1b5977a420
commit cc66034e59
8 changed files with 219 additions and 44 deletions

View File

@@ -30,8 +30,15 @@ export default function RootLayout({
<head>
<script dangerouslySetInnerHTML={{ __html: `
(function(){
var parentTheme=null;
try{
if(window.self!==window.top){
var parentDoc=window.parent.document;
parentTheme=(parentDoc.body&&parentDoc.body.getAttribute('theme-mode')==='dark')||parentDoc.documentElement.classList.contains('dark')?'dark':'light';
}
}catch(e){}
var t=localStorage.getItem('theme')||'system';
var r=t==='system'?window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light':t;
var r=parentTheme||(t==='system'?window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light':t);
document.documentElement.classList.add(r);
document.documentElement.setAttribute('data-theme',r);
})();