cct / patch_colors.py
Selinore's picture
Create patch_colors.py
a197a2b verified
Raw History Blame Contribute Delete
2.2 kB
import os
import glob
import re
print("=== Patching Unique Non-colliding Palette ===")
target_dirs = [
"/app/lightrag/api/webui/assets",
"/app/.venv/lib/python3.12/site-packages/lightrag/api/webui/assets",
"/usr/local/lib/python3.12/site-packages/lightrag/api/webui/assets",
"/usr/local/lib/python3.11/site-packages/lightrag/api/webui/assets",
]
js_files = []
for d in target_dirs:
if os.path.exists(d):
js_files.extend(glob.glob(os.path.join(d, "*.js")))
js_files = list(set(js_files))
print(f"Found JS files: {js_files}")
# 绝对一对一替换,每一个目标颜色都是全系统唯一,绝无重复:
color_map = {
# 1. 改变“其他”:独立映射为浅银灰
r"#f4d371": "#B0BEC5", # other -> 纯浅银灰
r"#5D6D7E": "#78909C", # 默认回退色 -> 蓝灰(避免与 other 重合)
# 2. 彻底拆开撞色的 EXTENDED_COLORS,每个颜色独一无二:
r"#2F4F4F": "#FFD700", # 原暗深灰绿 -> 独立明纯金黄!
r"#003366": "#0055FF", # 原深暗蓝 -> 独立高亮宝蓝!
r"#5a2c6d": "#00E5FF", # 原深紫 -> 独立电光天蓝
r"#9b3a31": "#FF6D00", # 原暗红褐 -> 独立明艳鲜橙
r"#0f705d": "#00E676", # 原墨绿 -> 独立荧光翠绿
r"#cd071e": "#FF1744", # 原暗红 -> 独立鲜亮红
}
total_replaces = 0
for js_path in js_files:
try:
with open(js_path, "r", encoding="utf-8") as f:
content = f.read()
changed = False
for old_hex, new_hex in color_map.items():
matches = len(re.findall(old_hex, content, re.IGNORECASE))
if matches > 0:
content = re.sub(old_hex, new_hex, content, flags=re.IGNORECASE)
print(f" 🎯 Replaced {old_hex} -> {new_hex} ({matches} hits) in {os.path.basename(js_path)}")
changed = True
total_replaces += matches
if changed:
with open(js_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"✅ Successfully written to {js_path}")
except Exception as e:
print(f"⚠️ Error: {e}")
print(f"=== Done! Total replacements: {total_replaces} ===")