键盘翻页 Keyboard flip

使用键盘方向键左右翻页

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         键盘翻页 Keyboard flip
// @namespace    https://www.cnachen.com/
// @version      0.1
// @description  使用键盘方向键左右翻页
// @author       cnachen
// @license      MIT
// @match        https://yande.re/post*
// @match        https://konachan.com/post*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('keyup', function(e){
        // 获取当前焦点元素
        var activeElement = document.activeElement;
        // 判断是否在输入框或文本区域中
        if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA' || activeElement.isContentEditable) {
            return; // 如果聚焦在输入框或可编辑区域,则不执行跳转
        }
        if(e.keyCode == 37){
            // 后退
            document.querySelector('a.previous_page').click();
        } else if(e.keyCode == 39){
            // 前进
            document.querySelector('a.next_page').click();
        }
    });
})();