22 lines
954 B
JavaScript
22 lines
954 B
JavaScript
'use strict';
|
||
/**
|
||
* 首屏主题预应用:在首次绘制前从 localStorage 读取上次的主题/强调色,
|
||
* 避免等 IPC 返回期间的白屏闪烁。
|
||
*
|
||
* 必须是「外部脚本」——页面 CSP 为 default-src 'self',未开 script-src 'unsafe-inline',
|
||
* 内联 <script> 会被直接拒绝执行。
|
||
*/
|
||
try {
|
||
const cached = JSON.parse(localStorage.getItem('clipboard-theme') || 'null');
|
||
if (cached) {
|
||
// 优先用 effectiveTheme:「跟随系统」开时它就是上次实际显示的主题,
|
||
// 直接套上去能省一次闪。旧版缓存里只有 theme(旧版在 followSystem
|
||
// 开时存的是 raw,会闪一下),这里向后兼容。
|
||
const theme = cached.effectiveTheme || cached.theme;
|
||
if (theme) {
|
||
document.documentElement.setAttribute('data-theme', theme);
|
||
document.documentElement.setAttribute('data-accent', cached.accent || 'purple');
|
||
}
|
||
}
|
||
} catch (e) { /* 静默 */ }
|