您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Jump between pages with keyboard shortcut
当前为
// ==UserScript== // @name EH mpv - Keyboard Page Navigation // @namespace http://fabulous.cupcake.jp.net/ // @version 20190206.1 // @description Jump between pages with keyboard shortcut // @author FabulousCupcake // @match https://exhentai.org/mpv/* // @grant none // @run-at document-end // ==/UserScript== const DEBUG = false; const key = { LETTER_W: 87, LETTER_A: 65, LETTER_S: 83, LETTER_D: 68, ARROW_LEFT: 37, ARROW_UP: 38, ARROW_RIGHT: 39, ARROW_DOWN: 40, } function dlog(msg) { if (!DEBUG) return; console.log(`EHmpv-KPN: ${msg}`); } const getCurrentPageNum = () => { const paneCoords = document.querySelector("#pane_images").getBoundingClientRect(); const x = paneCoords.x + (paneCoords.width / 2) const y = paneCoords.y; const currentElement = document.elementFromPoint(x,y); const currentId = currentElement.id.match(/_(\d+)/)[1]; dlog(`Currently on page ${currentId}`); return parseInt(currentId); } const jumpToPage = num => { const jumpTarget = document.querySelector(`a[name="page${num}"]`); if (!jumpTarget) return; jumpTarget.scrollIntoView(); dlog(`Jumping to page ${num}`); } const jumpForward = () => jumpToPage(getCurrentPageNum() + 1); const jumpBack = () => jumpToPage(getCurrentPageNum() - 1); const insertKeyBinds = () => { window.addEventListener('keydown', e => { const code = e.which || e.charCode || e.keyCode; switch(code) { case key.ARROW_LEFT: case key.ARROW_UP: case key.LETTER_W: case key.LETTER_A: jumpBack(); break; case key.ARROW_RIGHT: case key.ARROW_DOWN: case key.LETTER_S: case key.LETTER_D: jumpForward(); break; default: return; } e.preventDefault(); }); } insertKeyBinds();