您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Simple keyboard shortcuts for arbitrary sites.
当前为
// ==UserScript== // @name SimpleShortcuts // @namespace com.gmail.fujifruity.greasemonkey // @version 0.3 // @description Simple keyboard shortcuts for arbitrary sites. // @author fujifruity // @include http://*/* // @include https://*/* // @grant none // @license MIT // ==/UserScript== { 'use strict'; const log = (...msg) => console.log("SimpleShortcuts:", ...msg) class Website { constructor(urlHead, shortcuts) { this.urlHead = urlHead; this.shortcuts = shortcuts; } } class Shortcut { constructor(key, action) { this.key = key; this.action = action; } } const websites = [ new Website( "https://www.amazon.com", [new Shortcut('/', () => document.getElementById('twotabsearchtextbox').focus())] ), new Website( "https://www.google.com", [ new Shortcut('/', () => { document.getElementsByClassName('gLFyf gsfi')[0].focus() }), new Shortcut('n', () => { document.getElementById('pnnext').click() }) ] ) ] window.addEventListener('keydown', event => { const isInput = ["INPUT", "TEXTAREA"].includes(event.target.tagName) if (isInput) return const website = websites.find(w => location.href.startsWith(w.urlHead)) const shortcut = website?.shortcuts?.find(s => s.key == event.key) if (shortcut) { shortcut.action() event.preventDefault() log(event) } }) log("shortcuts set") }