39512-vm/inject_color.js
2026-04-08 13:05:26 +00:00

31 lines
1.5 KiB
JavaScript

const fs = require('fs');
let file = fs.readFileSync('frontend/src/pages/_app.tsx', 'utf8');
const hookStr = "\n" +
" React.useEffect(() => {\n" +
" // Fetch global settings\n" +
" axios.get('/settings/public').then((res) => {\n" +
" if (res.data && res.data.brandColor) {\n" +
" const color = res.data.brandColor;\n" +
" document.documentElement.style.setProperty('--brand-color', color);\n" +
" const style = document.createElement('style');\n" +
" style.innerHTML = `\n" +
" .bg-blue-600 { background-color: ${color} !important; }\n" +
" .bg-blue-500 { background-color: ${color} !important; }\n" +
" .text-blue-600 { color: ${color} !important; }\n" +
" .text-blue-500 { color: ${color} !important; }\n" +
" .border-blue-600 { border-color: ${color} !important; }\n" +
" .border-blue-500 { border-color: ${color} !important; }\n" +
" .ring-blue-200 { --tw-ring-color: ${color} !important; }\n" +
" .focus:ring-blue-500:focus { --tw-ring-color: ${color} !important; }\n" +
" .focus:border-blue-500:focus { border-color: ${color} !important; }\n" +
" `;\n" +
" document.head.appendChild(style);\n" +
" }\n" +
" }).catch(console.error);\n" +
" }, []);\n";
file = file.replace(/function MyApp\(\{ Component, pageProps \}: AppPropsWithLayout\) {/g, "function MyApp({ Component, pageProps }: AppPropsWithLayout) {" + hookStr);
fs.writeFileSync('frontend/src/pages/_app.tsx', file);