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

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

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

(function() {
    'use strict';
    function isEditable(el) {
        return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable;
    }
    function navigateChapter(e) {
        if (isEditable(e.target)) return;
        var targetButton = null;
        var buttons = document.querySelectorAll('button[data-href]');
        if (e.keyCode === 37) {
            buttons.forEach(function(btn) {
                if (btn.textContent.indexOf("上一话") > -1) {
                    targetButton = btn;
                }
            });
        } else if (e.keyCode === 39) {
            buttons.forEach(function(btn) {
                if (btn.textContent.indexOf("下一话") > -1) {
                    targetButton = btn;
                }
            });
        } else {
            return;
        }
        if (targetButton) {
            var href = targetButton.getAttribute('data-href');
            if (href) {
                window.location.href = href;
            } else {
                targetButton.click();
            }
        }
    }
    window.addEventListener('keydown', navigateChapter, false);
})();