revert noiz.py state (first pywebview experiment with working zoom)

This commit is contained in:
Armin 2026-07-07 02:00:19 +02:00
commit 55b92ab42f
2 changed files with 46 additions and 5 deletions

28
noiz.py
View file

@ -1,8 +1,26 @@
#!/usr/bin/env python3
import webview
webview.create_window(
"noiz://",
"./index.html"
)
webview.start()
def inject_zoom_shortcuts(window):
window.evaluate_js(
"""
document.addEventListener('keydown', function(e) {
if (!e.ctrlKey) return;
var key = e.key;
if (key === '=' || key === '+' || key === '-') {
e.preventDefault();
var cur = parseFloat(document.body.style.zoom) || 1;
if (key === '-') {
document.body.style.zoom = Math.max(0.25, +(cur - 0.1).toFixed(2));
} else {
document.body.style.zoom = Math.min(3, +(cur + 0.1).toFixed(2));
}
} else if (key === '0') {
e.preventDefault();
document.body.style.zoom = 1;
}
});
"""
)
window = webview.create_window("noiz://", "https://bsd.pm/noiz/", zoomable=True)
webview.start(inject_zoom_shortcuts, window)