Files
drawlogo/_design-test/apply-electron-colors.js

75 lines
3.0 KiB
JavaScript
Raw Permalink 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.
// 甄房换肤 · Electron 桌面外壳 + docs 独立工具页
// 注意:这些文件是「深色外壳」上下文,同一个旧色在这里的含义与 WEB 不同 ——
// 例如 #FFB31A 在 WEB 是警告色(→ #E76500),在外壳里是「品牌浅色」(→ #4D9BF6),
// 所以不能复用 WEB 的映射表,必须单独一套。
// 用法: node _design-test/apply-electron-colors.js (预演)
// node _design-test/apply-electron-colors.js --write (真写)
const fs = require('fs');
const WRITE = process.argv.includes('--write');
const ZF = 'e:/KF_7/ZhenOS-ZF';
const FILES = [
`${ZF}/xiaohuju/resources/splash/splash.html`,
`${ZF}/xiaohuju/resources/offline/offline.html`,
`${ZF}/xiaohuju/resources/blocked/blocked.html`,
`${ZF}/xiaohuju/src/common/constants.js`,
`${ZF}/xiaohuju/src/preload/titlebar.js`,
`${ZF}/docs/财务策算测算器-v2.html`,
`${ZF}/docs/财务策算测算器.html`
];
// 十六进制(大小写不敏感)
const HEX = [
['#ff822d', '#0070F2'], // blocked.html 里的品牌亮色
['#ff7a1a', '#0070F2'], // 品牌亮色 → 交互蓝
['#ff9a4d', '#4D9BF6'],
['#ff8a3d', '#4D9BF6'],
['#ffb31a', '#4D9BF6'], // 外壳里的「品牌浅色」→ 浅蓝(非警告橙)
['#ffc48a', '#A6CFFF'],
['#1a130d', '#071527'], // 最深底 → 甄房最深墨蓝
['#2e241a', '#0C2340'],
['#241c14', '#0A1D35'], // 标题栏底
['#33281d', '#0C2340'],
['#f1e4d2', '#EAF0F6'], // 标题栏符号(暖白 → 冷白)
['#f6ead8', '#F0F4F8'],
['#2a2118', '#131E29'],
['#3a322a', '#556B82'],
['#756a5e', '#5F7590'],
['#d9481c', '#AA0808'],
['#2e9e5b', '#256F3A'],
['#ffb31a', '#4D9BF6']
];
// rgb()/rgba() 三元组(保留 rgb/rgba 前缀与后面的 alpha)
const RGB = [
[/255,\s*122,\s*26/g, '0, 112, 242'],
[/255,\s*130,\s*45/g, '0, 112, 242'],
[/255,\s*179,\s*26/g, '77, 155, 246'],
[/241,\s*228,\s*210/g, '240, 244, 248'], // 暖白带透明
[/58,\s*50,\s*42/g, '12, 35, 64'],
[/26,\s*19,\s*13/g, '7, 21, 39'],
[/42,\s*33,\s*24/g, '19, 30, 41'],
[/51,\s*40,\s*29/g, '12, 35, 64']
];
let grand = 0, touched = 0;
for (const f of FILES) {
if (!fs.existsSync(f)) { console.log(' 跳过(不存在): ' + f.split('/').pop()); continue; }
let txt = fs.readFileSync(f, 'utf8');
const orig = txt;
const hits = [];
for (const [from, to] of HEX) {
const re = new RegExp(from, 'gi');
const n = (txt.match(re) || []).length;
if (n) { txt = txt.replace(re, to); hits.push(from + '→' + to + ' ×' + n); grand += n; }
}
for (const [re, to] of RGB) {
const n = (txt.match(re) || []).length;
if (n) { txt = txt.replace(re, to); hits.push('rgb元组 ×' + n); grand += n; }
}
if (txt !== orig) { touched++; console.log(' ' + f.replace(ZF + '/', '') + '\n ' + hits.join(' ')); }
if (WRITE && txt !== orig) fs.writeFileSync(f, txt);
}
console.log('\n涉及 ' + touched + ' 个文件 / 替换 ' + grand + ' 处 ' + (WRITE ? '(已写入)' : '(预演,加 --write 生效)'));