Files
weval-l99/v138_copy_url.py
2026-04-24 04:38:58 +02:00

60 lines
2.3 KiB
Python

#!/usr/bin/env python3
import sys
src, dst = sys.argv[1], sys.argv[2]
with open(src, "r", encoding="utf-8") as f:
c = f.read()
if "V138-COPY-URL" in c:
print("ALREADY", file=sys.stderr)
sys.exit(0)
# Exact anchor from actual file
old = '<input type="text" id="dash-search" placeholder="Rechercher... (Cmd/Ctrl+K)" style="flex:1;min-width:200px;padding:6px 10px;background:var(--bg3);color:var(--ac);border:1px solid var(--bd);border-radius:4px;font-size:11px">'
new = old + '''
<!-- V138-COPY-URL: share current filtered view -->
<button id="v138-copy-btn" onclick="__v138CopyShareURL()" style="padding:6px 10px;background:var(--bg3);border:1px solid var(--bd);border-radius:4px;color:var(--mu);cursor:pointer;font-size:11px;transition:all 0.15s" onmouseover="this.style.color='var(--ac)';this.style.borderColor='var(--vl)'" onmouseout="this.style.color='var(--mu)';this.style.borderColor='var(--bd)'" title="Copier URL partageable (sort + filtre + pins dans le hash)">&#128279; Share</button>'''
if old not in c:
print("anchor still missing", file=sys.stderr)
# Show what IS there around dash-search
idx = c.find('id="dash-search"')
if idx >= 0:
print("Context:", repr(c[max(0,idx-30):idx+250]), file=sys.stderr)
sys.exit(1)
c = c.replace(old, new, 1)
# Add JS function
marker = "/* V137-REFRESH: manual refresh with spin animation */"
js_add = '''/* V138-COPY-URL: copy current URL with hash state to clipboard */
async function __v138CopyShareURL(){
const url = window.location.href;
const btn = document.getElementById('v138-copy-btn');
try {
await navigator.clipboard.writeText(url);
if (btn) {
const orig = btn.innerHTML;
btn.innerHTML = '&#10004; Copied!';
btn.style.color = '#10b981';
btn.style.borderColor = '#10b981';
setTimeout(() => { btn.innerHTML = orig; btn.style.color = ''; btn.style.borderColor = ''; }, 1500);
}
} catch (err) {
if (btn) {
btn.innerHTML = '&#10007; Error';
btn.style.color = '#ef4444';
setTimeout(() => { btn.innerHTML = '&#128279; Share'; btn.style.color = ''; }, 1500);
}
}
}
''' + marker
if marker in c:
c = c.replace(marker, js_add, 1)
with open(dst, "w", encoding="utf-8") as f:
f.write(c)
print(f"OK size={len(c)}", file=sys.stderr)