您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Press F2 to scroll to an empty text box and focus it
当前为
- // ==UserScript==
- // @name Scroll to empty text box
- // @namespace http://tampermonkey.net/
- // @version 0.2.0
- // @description Press F2 to scroll to an empty text box and focus it
- // @author Valacar
- // @match *://*/*
- // @grant none
- // ==/UserScript==
- (function() {
- "use strict";
- // custom key. note: anything besides function keys may not work.
- // key code list: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code#Code_values
- const config = {
- key: "F2"
- };
- function findEmptyInput() {
- const inputs =
- document.querySelectorAll('textarea:not([readonly]),input[type="text"]:not([readonly])');
- for (let input of inputs) {
- if (input.value === "") {
- return input;
- }
- }
- }
- addEventListener("keydown", e => {
- if (e.defaultPrevented) {
- return;
- }
- if (e.code === config.key) {
- const emptyInput = findEmptyInput();
- if (emptyInput) {
- //console.debug(emptyInput);
- emptyInput.scrollIntoView({
- behavior: "smooth",
- block: "center",
- inline: "nearest"
- });
- emptyInput.focus();
- }
- }
- });
- })();