abrechenbarkeit/script.js

46 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-11-03 18:38:21 +01:00
/// <reference lib="dom" />
2024-11-13 14:02:15 +01:00
let idle_timer
function reset_idle() {
if (idle_timer) clearTimeout(idle_timer)
idle_timer = setTimeout(() => {
if (globalThis.location.pathname != "/" || globalThis.location.search != "")
globalThis.location.href = "/"
2024-11-13 14:02:15 +01:00
idle_timer = undefined
}, 30 * 1000)
}
document.addEventListener("DOMContentLoaded", () => {
reset_idle()
})
document.addEventListener("keydown", ev => {
2024-11-13 14:02:15 +01:00
reset_idle()
2024-11-04 16:24:41 +01:00
if (ev.ctrlKey || ev.altKey) return
2024-11-13 14:02:15 +01:00
if (ev.code == "F5" || (ev.ctrlKey && ev.code == "KeyR"))
return globalThis.location.reload() // reimplement reload for electron usage
2024-11-03 18:38:21 +01:00
if (!(document.activeElement instanceof HTMLInputElement)) {
if (ev.code.startsWith("Digit")) {
2024-11-04 16:24:41 +01:00
if (document.forms.buy_product)
return document.forms.buy_product.pcode.value += ev.code.substring(5)
} else if (ev.code == "Enter") {
if (document.forms.buy_product)
return document.forms.buy_product.submit()
if (document.forms.user_creation)
return document.forms.user_creation.submit()
} else if (ev.code.startsWith("Key") || ev.code == "Space") {
if (document.forms.user_creation)
return document.forms.user_creation.create_user.value += ev.key
if (document.forms.buy_product)
return document.forms.buy_product.pcode.value += ev.key
} else if (ev.code == "Backspace") {
if (document.forms.user_creation)
return document.forms.user_creation.create_user.value = ""
2024-11-04 16:24:41 +01:00
} else if (ev.code == "Escape") {
globalThis.location.href = "/"
2024-11-04 16:24:41 +01:00
ev.preventDefault()
}
2024-11-03 18:38:21 +01:00
}
})
2024-11-13 14:02:15 +01:00
document.addEventListener("mousemove", () => reset_idle())
document.addEventListener("mousedown", () => reset_idle())