Novel Navigation Shortcuts

使用键盘左右箭头切换章节,回车/空格跳转目录

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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         Novel Navigation Shortcuts
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  使用键盘左右箭头切换章节,回车/空格跳转目录
// @author       Transwarpcom
// @match        *://cn.wa01.com/novel/pagea/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(event) {
        // 处理章节切换
        if (['ArrowLeft', 'ArrowRight'].includes(event.key)) {
            const url = window.location.href;
            const chapterReg = /_(\d+)\.html$/;
            const match = url.match(chapterReg);

            if (match) {
                let chapter = parseInt(match[1], 10);
                chapter += event.key === 'ArrowLeft' ? -1 : 1;

                const newUrl = url.replace(chapterReg, `_${chapter}.html`);
                window.location.href = newUrl;
                event.preventDefault();
            }
        }

        // 处理目录跳转
        if (event.key === 'Enter' || event.key === ' ') {
            const path = window.location.pathname;
            const novelReg = /\/pagea\/(.+?)_\d+\.html$/;
            const match = path.match(novelReg);

            if (match) {
                const novelId = match[1];
                window.location.href = `https://cn.ttkan.co/novel/chapters/${novelId}`;
                event.preventDefault();
            }
        }
    });
})();