noiz/noiz.py

26 lines
941 B
Python
Executable file

#!/usr/bin/env python3
import webview
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)