app.js
Raw
1// Auto-submit selects marked with data-autosubmit
2document.querySelectorAll("[data-autosubmit]").forEach((el) => {
3 el.addEventListener("change", () => el.closest("form").submit());
4});
5
6// Confirm dialogs: <button data-confirm="Are you sure?">
7document.querySelectorAll("[data-confirm]").forEach((el) => {
8 el.addEventListener("click", (e) => {
9 if (!confirm(el.dataset.confirm)) e.preventDefault();
10 });
11});
12
13// Paste-to-upload: paste an image anywhere on the settings page to fill the avatar input
14document.addEventListener("paste", (e) => {
15 const input = document.querySelector('input[name="avatar"]');
16 if (!input) return;
17 const file = [...(e.clipboardData?.items ?? [])]
18 .find((i) => i.kind === "file" && i.type.startsWith("image/"))
19 ?.getAsFile();
20 if (!file) return;
21 const dt = new DataTransfer();
22 dt.items.add(file);
23 input.files = dt.files;
24 input.closest("form").submit();
25});
26