Files
DP/AdminPanel/接收PS主题示例.js
zuowei1216 1b19ff1b92 20251222
2025-12-22 21:06:29 +08:00

57 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 在你的网站https://app.aidg168.uk中添加此代码
* 用于接收来自 Photoshop CEP 插件的主题信息
*/
// 监听来自 PS 插件的主题消息
window.addEventListener('message', function(event) {
// 安全检查(可选)
// if (event.origin !== 'expected-origin') return;
const data = event.data;
// 检查是否是 PS 主题消息
if (data && data.type === 'PS_THEME' && data.theme) {
const theme = data.theme;
console.log('📨 收到 PS 主题:', theme);
// theme.bgColor: 背景颜色 (例如 'rgb(50, 50, 50)')
// theme.isLight: 是否为浅色主题 (true/false)
// theme.fontSize: 字体大小 (数字)
// 应用主题到你的网站
applyPSTheme(theme);
}
});
// 应用 PS 主题到网站
function applyPSTheme(theme) {
const root = document.documentElement;
// 设置 CSS 变量
root.style.setProperty('--ps-bg-color', theme.bgColor);
root.style.setProperty('--ps-font-size', theme.fontSize + 'px');
// 根据亮度切换主题
if (theme.isLight) {
// 浅色主题
document.body.classList.remove('dark-theme');
document.body.classList.add('light-theme');
root.style.setProperty('--ps-text-color', '#222222');
} else {
// 深色主题
document.body.classList.remove('light-theme');
document.body.classList.add('dark-theme');
root.style.setProperty('--ps-text-color', '#dfdfdf');
}
// 直接应用到 body
document.body.style.backgroundColor = theme.bgColor;
console.log('✅ PS 主题已应用');
}
// 可选:主动请求主题(如果插件已经加载)
window.parent.postMessage({ type: 'REQUEST_THEME' }, '*');