70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""V125 - Light/dark theme toggle with URL hash persist"""
|
|
path = "/var/www/html/all-ia-hub.html"
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
c = f.read()
|
|
|
|
if "V125-THEME" in c:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# Find current root CSS vars to create light counterpart
|
|
# Looking for ":root {" or body background
|
|
import re
|
|
m = re.search(r':root\s*\{[^}]*\}', c, re.DOTALL)
|
|
if m:
|
|
print("Found :root block:", m.group(0)[:200])
|
|
|
|
# Add theme toggle in header (near h-md or tabs)
|
|
# Look for a good anchor - try putting near tabs
|
|
old_tabs_end = '<button class="tab" data-view="dashboards">DASHBOARDS</button>'
|
|
new_tabs_end = old_tabs_end + '\n <!-- V125-THEME: theme toggle -->\n <button id="theme-toggle" class="tab" onclick="__toggleTheme()" title="Basculer thème" style="margin-left:auto">☀</button>'
|
|
if old_tabs_end in c:
|
|
c = c.replace(old_tabs_end, new_tabs_end, 1)
|
|
|
|
# Add light theme CSS vars (when body.light)
|
|
style_marker = '@keyframes fadeIn{from{opacity:0.4}to{opacity:1}}'
|
|
new_style = style_marker + '''
|
|
/* V125-THEME: light theme override */
|
|
body.light{--bg:#fafafa;--bg2:#f0f0f0;--bg3:#e4e4e7;--ac:#18181b;--mu:#52525b;--bd:#d4d4d8;--vl:#7c3aed;--cy:#0891b2;--gr:#059669;--rd:#dc2626;--dm:#71717a}
|
|
body.light .view h2{color:#7c3aed}
|
|
body.light .tab{background:#e4e4e7;color:#18181b}
|
|
body.light .tab.on{background:#7c3aed;color:#fff}
|
|
body.light #theme-toggle::before{content:\"\\263D\"}
|
|
'''
|
|
if style_marker in c:
|
|
c = c.replace(style_marker, new_style, 1)
|
|
|
|
# Add JS for toggle with URL hash persist (same approach as pins, shareable)
|
|
js_anchor = '// V123-PINS: pin management via URL hash'
|
|
js_new = '''// V125-THEME: theme toggle with URL hash persist
|
|
function __getTheme(){
|
|
return new URLSearchParams(window.location.hash.slice(1)).get('theme') || 'dark';
|
|
}
|
|
function __applyTheme(t){
|
|
document.body.classList.toggle('light', t === 'light');
|
|
const btn = document.getElementById('theme-toggle');
|
|
if (btn) btn.textContent = t === 'light' ? '\\u263E' : '\\u2600';
|
|
}
|
|
function __toggleTheme(){
|
|
const cur = __getTheme();
|
|
const next = cur === 'light' ? 'dark' : 'light';
|
|
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
if (next === 'light') params.set('theme', 'light');
|
|
else params.delete('theme');
|
|
const h = params.toString();
|
|
window.history.replaceState(null, '', window.location.pathname + window.location.search + (h ? '#'+h : ''));
|
|
__applyTheme(next);
|
|
}
|
|
// Apply on load
|
|
setTimeout(() => __applyTheme(__getTheme()), 50);
|
|
|
|
// V123-PINS: pin management via URL hash'''
|
|
|
|
if js_anchor in c:
|
|
c = c.replace(js_anchor, js_new, 1)
|
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(c)
|
|
print(f"PATCHED size={len(c)}")
|