42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""V128 - Scroll-to-top floating button visible when scrolled far in dashboards"""
|
|
path = "/var/www/html/all-ia-hub.html"
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
c = f.read()
|
|
|
|
if "V128-SCROLL-TOP" in c:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# Add button inside v-dashboards section (self-contained)
|
|
anchor = '<div id="dash-grid" style="display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:10px"></div>'
|
|
addition = anchor + '''
|
|
<!-- V128-SCROLL-TOP: floating "top" button visible only when scrolled far -->
|
|
<button id="dash-scroll-top" onclick="window.scrollTo({top:0,behavior:'smooth'})" style="position:fixed;bottom:24px;right:24px;background:var(--bg3);color:var(--ac);border:1px solid var(--vl);border-radius:50%;width:44px;height:44px;font-size:18px;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,0.3);display:none;z-index:50;transition:all 0.2s ease" title="Retour haut">↑</button>'''
|
|
|
|
assert anchor in c, "dash-grid anchor missing"
|
|
c = c.replace(anchor, addition, 1)
|
|
|
|
# Add scroll listener in the existing setTimeout block
|
|
marker = "if (search) search.addEventListener('input', rerender);"
|
|
addition2 = marker + '''
|
|
// V128-SCROLL-TOP: toggle button visibility based on scroll
|
|
const scrollBtn = document.getElementById('dash-scroll-top');
|
|
if (scrollBtn) {
|
|
const updateScrollBtn = () => {
|
|
const isDashVisible = document.getElementById('v-dashboards')?.classList.contains('on');
|
|
const scrolledFar = window.scrollY > 400;
|
|
scrollBtn.style.display = (isDashVisible && scrolledFar) ? 'block' : 'none';
|
|
};
|
|
window.addEventListener('scroll', updateScrollBtn, { passive: true });
|
|
// Also hide when switching tabs
|
|
document.querySelectorAll('.tab').forEach(t => t.addEventListener('click', () => setTimeout(updateScrollBtn, 100)));
|
|
}'''
|
|
|
|
if marker in c:
|
|
c = c.replace(marker, addition2, 1)
|
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(c)
|
|
print(f"PATCHED size={len(c)}")
|