键盘翻页 Keyboard flip

使用键盘方向键左右翻页

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
        }
    });
})();