嗨皮漫画 方向鍵控制上一話與下一話

使用左右方向鍵控制上一話與下一話的切換

当前为 2025-08-13 提交的版本,查看 最新版本

// ==UserScript==
// @name         嗨皮漫画 方向鍵控制上一話與下一話
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  使用左右方向鍵控制上一話與下一話的切換
// @author       shanlan(ChatGPT o3-mini)
// @match        https://m.happymh.com/mangaread/*
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 過濾掉在輸入框、textarea、contentEditable等可編輯區時的按鍵監聽
    function isEditable(element) {
        return element.tagName === 'INPUT' ||
               element.tagName === 'TEXTAREA' ||
               element.isContentEditable;
    }

    // 根據方向按鍵選擇並導向上一話/下一話的頁面
    function navigateChapter(e) {
        // 若目前焦點在可輸入區,則略過快捷鍵
        if (isEditable(e.target)) return;

        // 37: 左方向鍵 (上一話), 39: 右方向鍵 (下一話)
        let selector = '';
        if (e.keyCode === 37) {
            selector = '.css-1eqkmlz-alink-grey-preChapter';
        } else if (e.keyCode === 39) {
            selector = '.css-1himr83-alink';
        } else {
            return;
        }

        // 尋找按鈕元件
        let button = document.querySelector(selector);
        if (button) {
            // 取得自訂的 data-href 屬性
            let href = button.getAttribute('data-href');
            if (href) {
                window.location.href = href;
            } else {
                // 若未找到 href,則模擬點擊事件
                button.click();
            }
        }
    }

    // 綁定鍵盤事件
    window.addEventListener('keydown', navigateChapter, false);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址