(function () { const input = document.getElementById("scan-input"); const form = document.getElementById("scan-search-form"); function showToast(message) { let stack = document.querySelector(".toast-stack"); if (!stack) { stack = document.createElement("div"); stack.className = "toast-stack"; document.body.appendChild(stack); } const toast = document.createElement("div"); toast.className = "toast"; toast.textContent = message; stack.appendChild(toast); setTimeout(function () { toast.remove(); }, 1600); } if (!input || !form) { return; } // Keep focus for barcode scanners that type and send Enter immediately. window.addEventListener("load", function () { input.focus(); }); document.addEventListener("keydown", function (event) { if (event.key === "Escape") { input.value = ""; input.focus(); showToast("已清空搜索词"); } }); form.addEventListener("submit", function () { if (input.value.trim()) { showToast("正在搜索..."); } }); })();