跳转到内容

User:PexEric/QuickNav.js

维基百科,自由的百科全书

这是本页的一个历史版本,由PexEric留言 | 贡献2022年10月25日 (二) 15:31 ([InPageEdit] 没有编辑摘要)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
let lastPressed = -1;

window.addEventListener("keydown", event => {
	if (event.key === "\\") {
		if (new Date().getTime() - lastPressed < 1000) {
			let input = document.createElement("input", { id: "searchInput" });
			document.body.appendChild(input);

			input.style.border = "none";
			input.style.outline = "none";
			input.style.background = "none";
			input.style.position = "fixed";
			input.style.top = "calc(100% - 100px)";
			input.style.left = "0px";
			input.style.width = "100%";
			input.style.textAlign = "center";
			input.style.zIndex = "5";
			input.style.fontSize = "3em";

			input.focus();
			input.onblur = function() {
				input.remove();
			}

			input.onkeydown = e => {
				if (e.key.toLowerCase() === "enter") {
					location.href = "https://zh.wikipedia.org/wiki/" + input.value;
				}
			}

			input.oninput = e => {
				if (e.data === "\\") {
					input.value = "";
				}
			}
		} else {
			lastPressed = new Date().getTime();
		}
	}
});