45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""V120 - Keyboard shortcut Cmd+K/Ctrl+K to focus search when DASHBOARDS tab active"""
|
|
path = "/var/www/html/all-ia-hub.html"
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
c = f.read()
|
|
|
|
if "V120-KEYBOARD" in c:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# Add keyboard listener next to V119 listeners
|
|
marker = "if (sort) sort.addEventListener('change', rerender);"
|
|
addition = marker + '''
|
|
// V120-KEYBOARD: Cmd+K / Ctrl+K focus search when dashboards tab is visible
|
|
document.addEventListener('keydown', (e) => {
|
|
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
|
|
const viewDash = document.getElementById('v-dashboards');
|
|
if (viewDash && viewDash.classList.contains('on')) {
|
|
e.preventDefault();
|
|
const s = document.getElementById('dash-search');
|
|
if (s) { s.focus(); s.select(); }
|
|
}
|
|
}
|
|
if (e.key === 'Escape') {
|
|
const s = document.getElementById('dash-search');
|
|
if (s && document.activeElement === s && s.value) {
|
|
s.value = '';
|
|
s.dispatchEvent(new Event('input'));
|
|
}
|
|
}
|
|
});'''
|
|
|
|
assert marker in c, "marker missing"
|
|
c = c.replace(marker, addition, 1)
|
|
|
|
# Also add visual hint next to search placeholder
|
|
old_placeholder = 'placeholder="Rechercher..."'
|
|
new_placeholder = 'placeholder="Rechercher... (Cmd/Ctrl+K)"'
|
|
if old_placeholder in c:
|
|
c = c.replace(old_placeholder, new_placeholder, 1)
|
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(c)
|
|
print(f"PATCHED size={len(c)}")
|