Novel Navigation Shortcuts

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

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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