Novel Navigation Shortcuts

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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