Skip half-chapters

Changes "Next chapter" button to the next full chapter if present

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Skip half-chapters
// @namespace    http://tampermonkey.net/
// @description  Changes "Next chapter" button to the next full chapter if present
// @author       You
// @match        https://chapmanganato.to/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chapmanganato.to
// @grant        none
// @version      1.3
// ==/UserScript==

(function () {
    "use strict";
    const buttons = document.querySelectorAll(".navi-change-chapter-btn-next");
    console.log(buttons);
    const fullChapterName = document.querySelector(
        ".navi-change-chapter",
    ).value;
    const num = fullChapterName.includes(":")
        ? fullChapterName.split(":")[0].replace("Chapter ", "")
        : fullChapterName.replace("Chapter ", "");

    if (num.includes("-") || num.includes(".")) {
        console.warn("Current chapter is half chapter, skipping");
        return;
    }

    const currentChapter = parseInt(num);
    const chapters = [
        ...document.querySelectorAll(".navi-change-chapter option"),
    ];
    let nextChapterExists = false;
    for (const option of chapters) {
        if (option.getAttribute("data-c") !== (currentChapter + 1).toString())
            continue;
        const fullNextChapterName = option.value;
        const nextNum = fullNextChapterName.includes(":")
            ? fullNextChapterName.split(":")[0].replace("Chapter ", "")
            : fullNextChapterName.replace("Chapter ", "");
        if (nextNum.includes(".") || nextNum.includes("-")) continue;
        nextChapterExists = true;
        break;
    }
    if (!nextChapterExists) {
        console.warn("No next chapter, exiting");
        return;
    }

    const nextUrl = location.href.replace(
        /\/chapter-(.+)/,
        `/chapter-${currentChapter + 1}`,
    );
    console.log("Next chapter url", nextUrl);

    for (const button of buttons) {
        button.href = nextUrl;
        button.innerHTML = "NEXT CHAPTER (FULL) <i></i>";
    }
})();