19 lines
494 B
JavaScript
19 lines
494 B
JavaScript
/* app.js — 基础前端交互 */
|
|
|
|
// Ctrl+K 或 / 聚焦搜索框
|
|
document.addEventListener("keydown", function (e) {
|
|
var input = document.querySelector(".nav-search-input");
|
|
if (!input) return;
|
|
|
|
// 忽略在输入框内的按键
|
|
if (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA") return;
|
|
|
|
if ((e.ctrlKey || e.metaKey) && e.key === "k") {
|
|
e.preventDefault();
|
|
input.focus();
|
|
} else if (e.key === "/") {
|
|
e.preventDefault();
|
|
input.focus();
|
|
}
|
|
});
|