feat(theme): add postMessage listener for real-time appearance updates in dashboard
This commit is contained in:
parent
92c87909d9
commit
52a531dd78
4 changed files with 168 additions and 100 deletions
|
|
@ -19,39 +19,56 @@
|
|||
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
<script>
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'UPDATE_APPEARANCE') {
|
||||
const { primaryColor, backgroundColor, fontFamily } = event.data.settings;
|
||||
const root = document.documentElement;
|
||||
const style = root.style;
|
||||
|
||||
if (primaryColor) {
|
||||
style.setProperty('--primary', primaryColor);
|
||||
style.setProperty('--color-primary', primaryColor);
|
||||
style.setProperty('--color-tech-primary', primaryColor);
|
||||
style.setProperty('--color-seo-primary', primaryColor);
|
||||
style.setProperty('--color-finance-primary', primaryColor);
|
||||
style.setProperty('--color-recipe-primary', primaryColor);
|
||||
style.setProperty('--color-health-primary', primaryColor);
|
||||
style.setProperty('--color-corporate-primary', primaryColor);
|
||||
const settings = event.data.settings;
|
||||
if (!settings) return;
|
||||
let css = '';
|
||||
if (settings.primaryColor) {
|
||||
css += "
|
||||
:root { " +
|
||||
"--color-brand-primary: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-blue: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-gold: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-600: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-600: " + settings.primaryColor + " !important; " +
|
||||
"} " +
|
||||
".text-brand-blue, .text-blue-600, .group-hover\:text-blue-600:hover, .text-brand-gold, .text-emerald-600, .text-blue-500, .text-emerald-500 { color: " + settings.primaryColor + " !important; } " +
|
||||
".bg-brand-blue, .bg-blue-600, .hover\:bg-blue-500:hover, .bg-brand-gold, .bg-emerald-600, .bg-blue-500, .bg-emerald-500 { background-color: " + settings.primaryColor + " !important; } " +
|
||||
".border-brand-blue, .border-blue-600, .focus\:border-blue-600:focus, .border-brand-gold, .border-emerald-600, .border-blue-500, .border-emerald-500 { border-color: " + settings.primaryColor + " !important; } " +
|
||||
".fill-blue-600, .fill-emerald-600 { fill: " + settings.primaryColor + " !important; }";
|
||||
}
|
||||
if (backgroundColor) {
|
||||
style.setProperty('--background', backgroundColor);
|
||||
style.setProperty('--color-bg', backgroundColor);
|
||||
style.setProperty('--color-tech-surface', backgroundColor);
|
||||
style.setProperty('--color-seo-surface', backgroundColor);
|
||||
style.backgroundColor = backgroundColor;
|
||||
if (settings.backgroundColor) {
|
||||
css += "
|
||||
:root { --color-brand-bg: " + settings.backgroundColor + " !important; } body { background-color: " + settings.backgroundColor + " !important; }";
|
||||
}
|
||||
if (fontFamily) {
|
||||
const fontString = '"' + fontFamily + '", sans-serif';
|
||||
style.setProperty('--font-family', fontString);
|
||||
style.setProperty('--font-sans', fontString);
|
||||
style.fontFamily = fontString;
|
||||
if (settings.fontFamily) {
|
||||
const fontLink = document.getElementById('dynamic-font');
|
||||
const fontName = settings.fontFamily.replace(/ /g, '+');
|
||||
const fontUrl = 'https://fonts.googleapis.com/css2?family=' + fontName + ':wght@300;400;500;600;700&display=swap';
|
||||
if (fontLink) { fontLink.href = fontUrl; } else {
|
||||
const link = document.createElement('link'); link.id = 'dynamic-font'; link.rel = 'stylesheet'; link.href = fontUrl; document.head.appendChild(link);
|
||||
}
|
||||
css += "
|
||||
:root { " +
|
||||
"--font-sans: "" + settings.fontFamily + "", sans-serif !important; " +
|
||||
"--font-serif: "" + settings.fontFamily + "", serif !important; " +
|
||||
"--font-mono: "" + settings.fontFamily + "", monospace !important; " +
|
||||
"} * { font-family: "" + settings.fontFamily + "", sans-serif !important; }";
|
||||
}
|
||||
let styleNode = document.getElementById('dynamic-theme-style');
|
||||
if (!styleNode) { styleNode = document.createElement('style'); styleNode.id = 'dynamic-theme-style'; document.head.appendChild(styleNode); }
|
||||
styleNode.innerHTML = css;
|
||||
}
|
||||
});
|
||||
// Ping parent window that we are ready
|
||||
window.parent.postMessage({ type: 'IFRAME_READY' }, '*');
|
||||
|
||||
</body>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -30,39 +30,56 @@
|
|||
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
<script>
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'UPDATE_APPEARANCE') {
|
||||
const { primaryColor, backgroundColor, fontFamily } = event.data.settings;
|
||||
const root = document.documentElement;
|
||||
const style = root.style;
|
||||
|
||||
if (primaryColor) {
|
||||
style.setProperty('--primary', primaryColor);
|
||||
style.setProperty('--color-primary', primaryColor);
|
||||
style.setProperty('--color-tech-primary', primaryColor);
|
||||
style.setProperty('--color-seo-primary', primaryColor);
|
||||
style.setProperty('--color-finance-primary', primaryColor);
|
||||
style.setProperty('--color-recipe-primary', primaryColor);
|
||||
style.setProperty('--color-health-primary', primaryColor);
|
||||
style.setProperty('--color-corporate-primary', primaryColor);
|
||||
const settings = event.data.settings;
|
||||
if (!settings) return;
|
||||
let css = '';
|
||||
if (settings.primaryColor) {
|
||||
css += "
|
||||
:root { " +
|
||||
"--color-brand-primary: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-blue: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-gold: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-600: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-600: " + settings.primaryColor + " !important; " +
|
||||
"} " +
|
||||
".text-brand-blue, .text-blue-600, .group-hover\:text-blue-600:hover, .text-brand-gold, .text-emerald-600, .text-blue-500, .text-emerald-500 { color: " + settings.primaryColor + " !important; } " +
|
||||
".bg-brand-blue, .bg-blue-600, .hover\:bg-blue-500:hover, .bg-brand-gold, .bg-emerald-600, .bg-blue-500, .bg-emerald-500 { background-color: " + settings.primaryColor + " !important; } " +
|
||||
".border-brand-blue, .border-blue-600, .focus\:border-blue-600:focus, .border-brand-gold, .border-emerald-600, .border-blue-500, .border-emerald-500 { border-color: " + settings.primaryColor + " !important; } " +
|
||||
".fill-blue-600, .fill-emerald-600 { fill: " + settings.primaryColor + " !important; }";
|
||||
}
|
||||
if (backgroundColor) {
|
||||
style.setProperty('--background', backgroundColor);
|
||||
style.setProperty('--color-bg', backgroundColor);
|
||||
style.setProperty('--color-tech-surface', backgroundColor);
|
||||
style.setProperty('--color-seo-surface', backgroundColor);
|
||||
style.backgroundColor = backgroundColor;
|
||||
if (settings.backgroundColor) {
|
||||
css += "
|
||||
:root { --color-brand-bg: " + settings.backgroundColor + " !important; } body { background-color: " + settings.backgroundColor + " !important; }";
|
||||
}
|
||||
if (fontFamily) {
|
||||
const fontString = '"' + fontFamily + '", sans-serif';
|
||||
style.setProperty('--font-family', fontString);
|
||||
style.setProperty('--font-sans', fontString);
|
||||
style.fontFamily = fontString;
|
||||
if (settings.fontFamily) {
|
||||
const fontLink = document.getElementById('dynamic-font');
|
||||
const fontName = settings.fontFamily.replace(/ /g, '+');
|
||||
const fontUrl = 'https://fonts.googleapis.com/css2?family=' + fontName + ':wght@300;400;500;600;700&display=swap';
|
||||
if (fontLink) { fontLink.href = fontUrl; } else {
|
||||
const link = document.createElement('link'); link.id = 'dynamic-font'; link.rel = 'stylesheet'; link.href = fontUrl; document.head.appendChild(link);
|
||||
}
|
||||
css += "
|
||||
:root { " +
|
||||
"--font-sans: "" + settings.fontFamily + "", sans-serif !important; " +
|
||||
"--font-serif: "" + settings.fontFamily + "", serif !important; " +
|
||||
"--font-mono: "" + settings.fontFamily + "", monospace !important; " +
|
||||
"} * { font-family: "" + settings.fontFamily + "", sans-serif !important; }";
|
||||
}
|
||||
let styleNode = document.getElementById('dynamic-theme-style');
|
||||
if (!styleNode) { styleNode = document.createElement('style'); styleNode.id = 'dynamic-theme-style'; document.head.appendChild(styleNode); }
|
||||
styleNode.innerHTML = css;
|
||||
}
|
||||
});
|
||||
// Ping parent window that we are ready
|
||||
window.parent.postMessage({ type: 'IFRAME_READY' }, '*');
|
||||
|
||||
</body>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -30,39 +30,56 @@
|
|||
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
<script>
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'UPDATE_APPEARANCE') {
|
||||
const { primaryColor, backgroundColor, fontFamily } = event.data.settings;
|
||||
const root = document.documentElement;
|
||||
const style = root.style;
|
||||
|
||||
if (primaryColor) {
|
||||
style.setProperty('--primary', primaryColor);
|
||||
style.setProperty('--color-primary', primaryColor);
|
||||
style.setProperty('--color-tech-primary', primaryColor);
|
||||
style.setProperty('--color-seo-primary', primaryColor);
|
||||
style.setProperty('--color-finance-primary', primaryColor);
|
||||
style.setProperty('--color-recipe-primary', primaryColor);
|
||||
style.setProperty('--color-health-primary', primaryColor);
|
||||
style.setProperty('--color-corporate-primary', primaryColor);
|
||||
const settings = event.data.settings;
|
||||
if (!settings) return;
|
||||
let css = '';
|
||||
if (settings.primaryColor) {
|
||||
css += "
|
||||
:root { " +
|
||||
"--color-brand-primary: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-blue: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-gold: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-600: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-600: " + settings.primaryColor + " !important; " +
|
||||
"} " +
|
||||
".text-brand-blue, .text-blue-600, .group-hover\:text-blue-600:hover, .text-brand-gold, .text-emerald-600, .text-blue-500, .text-emerald-500 { color: " + settings.primaryColor + " !important; } " +
|
||||
".bg-brand-blue, .bg-blue-600, .hover\:bg-blue-500:hover, .bg-brand-gold, .bg-emerald-600, .bg-blue-500, .bg-emerald-500 { background-color: " + settings.primaryColor + " !important; } " +
|
||||
".border-brand-blue, .border-blue-600, .focus\:border-blue-600:focus, .border-brand-gold, .border-emerald-600, .border-blue-500, .border-emerald-500 { border-color: " + settings.primaryColor + " !important; } " +
|
||||
".fill-blue-600, .fill-emerald-600 { fill: " + settings.primaryColor + " !important; }";
|
||||
}
|
||||
if (backgroundColor) {
|
||||
style.setProperty('--background', backgroundColor);
|
||||
style.setProperty('--color-bg', backgroundColor);
|
||||
style.setProperty('--color-tech-surface', backgroundColor);
|
||||
style.setProperty('--color-seo-surface', backgroundColor);
|
||||
style.backgroundColor = backgroundColor;
|
||||
if (settings.backgroundColor) {
|
||||
css += "
|
||||
:root { --color-brand-bg: " + settings.backgroundColor + " !important; } body { background-color: " + settings.backgroundColor + " !important; }";
|
||||
}
|
||||
if (fontFamily) {
|
||||
const fontString = '"' + fontFamily + '", sans-serif';
|
||||
style.setProperty('--font-family', fontString);
|
||||
style.setProperty('--font-sans', fontString);
|
||||
style.fontFamily = fontString;
|
||||
if (settings.fontFamily) {
|
||||
const fontLink = document.getElementById('dynamic-font');
|
||||
const fontName = settings.fontFamily.replace(/ /g, '+');
|
||||
const fontUrl = 'https://fonts.googleapis.com/css2?family=' + fontName + ':wght@300;400;500;600;700&display=swap';
|
||||
if (fontLink) { fontLink.href = fontUrl; } else {
|
||||
const link = document.createElement('link'); link.id = 'dynamic-font'; link.rel = 'stylesheet'; link.href = fontUrl; document.head.appendChild(link);
|
||||
}
|
||||
css += "
|
||||
:root { " +
|
||||
"--font-sans: "" + settings.fontFamily + "", sans-serif !important; " +
|
||||
"--font-serif: "" + settings.fontFamily + "", serif !important; " +
|
||||
"--font-mono: "" + settings.fontFamily + "", monospace !important; " +
|
||||
"} * { font-family: "" + settings.fontFamily + "", sans-serif !important; }";
|
||||
}
|
||||
let styleNode = document.getElementById('dynamic-theme-style');
|
||||
if (!styleNode) { styleNode = document.createElement('style'); styleNode.id = 'dynamic-theme-style'; document.head.appendChild(styleNode); }
|
||||
styleNode.innerHTML = css;
|
||||
}
|
||||
});
|
||||
// Ping parent window that we are ready
|
||||
window.parent.postMessage({ type: 'IFRAME_READY' }, '*');
|
||||
|
||||
</body>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -30,39 +30,56 @@
|
|||
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
<script>
|
||||
<!-- Theme Auto-Updater injected by autoblogia -->
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'UPDATE_APPEARANCE') {
|
||||
const { primaryColor, backgroundColor, fontFamily } = event.data.settings;
|
||||
const root = document.documentElement;
|
||||
const style = root.style;
|
||||
|
||||
if (primaryColor) {
|
||||
style.setProperty('--primary', primaryColor);
|
||||
style.setProperty('--color-primary', primaryColor);
|
||||
style.setProperty('--color-tech-primary', primaryColor);
|
||||
style.setProperty('--color-seo-primary', primaryColor);
|
||||
style.setProperty('--color-finance-primary', primaryColor);
|
||||
style.setProperty('--color-recipe-primary', primaryColor);
|
||||
style.setProperty('--color-health-primary', primaryColor);
|
||||
style.setProperty('--color-corporate-primary', primaryColor);
|
||||
const settings = event.data.settings;
|
||||
if (!settings) return;
|
||||
let css = '';
|
||||
if (settings.primaryColor) {
|
||||
css += "
|
||||
:root { " +
|
||||
"--color-brand-primary: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-blue: " + settings.primaryColor + " !important; " +
|
||||
"--color-brand-gold: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-blue-600: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-500: " + settings.primaryColor + " !important; " +
|
||||
"--color-emerald-600: " + settings.primaryColor + " !important; " +
|
||||
"} " +
|
||||
".text-brand-blue, .text-blue-600, .group-hover\:text-blue-600:hover, .text-brand-gold, .text-emerald-600, .text-blue-500, .text-emerald-500 { color: " + settings.primaryColor + " !important; } " +
|
||||
".bg-brand-blue, .bg-blue-600, .hover\:bg-blue-500:hover, .bg-brand-gold, .bg-emerald-600, .bg-blue-500, .bg-emerald-500 { background-color: " + settings.primaryColor + " !important; } " +
|
||||
".border-brand-blue, .border-blue-600, .focus\:border-blue-600:focus, .border-brand-gold, .border-emerald-600, .border-blue-500, .border-emerald-500 { border-color: " + settings.primaryColor + " !important; } " +
|
||||
".fill-blue-600, .fill-emerald-600 { fill: " + settings.primaryColor + " !important; }";
|
||||
}
|
||||
if (backgroundColor) {
|
||||
style.setProperty('--background', backgroundColor);
|
||||
style.setProperty('--color-bg', backgroundColor);
|
||||
style.setProperty('--color-tech-surface', backgroundColor);
|
||||
style.setProperty('--color-seo-surface', backgroundColor);
|
||||
style.backgroundColor = backgroundColor;
|
||||
if (settings.backgroundColor) {
|
||||
css += "
|
||||
:root { --color-brand-bg: " + settings.backgroundColor + " !important; } body { background-color: " + settings.backgroundColor + " !important; }";
|
||||
}
|
||||
if (fontFamily) {
|
||||
const fontString = '"' + fontFamily + '", sans-serif';
|
||||
style.setProperty('--font-family', fontString);
|
||||
style.setProperty('--font-sans', fontString);
|
||||
style.fontFamily = fontString;
|
||||
if (settings.fontFamily) {
|
||||
const fontLink = document.getElementById('dynamic-font');
|
||||
const fontName = settings.fontFamily.replace(/ /g, '+');
|
||||
const fontUrl = 'https://fonts.googleapis.com/css2?family=' + fontName + ':wght@300;400;500;600;700&display=swap';
|
||||
if (fontLink) { fontLink.href = fontUrl; } else {
|
||||
const link = document.createElement('link'); link.id = 'dynamic-font'; link.rel = 'stylesheet'; link.href = fontUrl; document.head.appendChild(link);
|
||||
}
|
||||
css += "
|
||||
:root { " +
|
||||
"--font-sans: "" + settings.fontFamily + "", sans-serif !important; " +
|
||||
"--font-serif: "" + settings.fontFamily + "", serif !important; " +
|
||||
"--font-mono: "" + settings.fontFamily + "", monospace !important; " +
|
||||
"} * { font-family: "" + settings.fontFamily + "", sans-serif !important; }";
|
||||
}
|
||||
let styleNode = document.getElementById('dynamic-theme-style');
|
||||
if (!styleNode) { styleNode = document.createElement('style'); styleNode.id = 'dynamic-theme-style'; document.head.appendChild(styleNode); }
|
||||
styleNode.innerHTML = css;
|
||||
}
|
||||
});
|
||||
// Ping parent window that we are ready
|
||||
window.parent.postMessage({ type: 'IFRAME_READY' }, '*');
|
||||
|
||||
</body>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue