Skip half-chapters

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

  1. // ==UserScript==
  2. // @name Skip half-chapters
  3. // @namespace http://tampermonkey.net/
  4. // @description Changes "Next chapter" button to the next full chapter if present
  5. // @author You
  6. // @match https://chapmanganato.to/*
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=chapmanganato.to
  8. // @grant none
  9. // @version 1.3
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14. const buttons = document.querySelectorAll(".navi-change-chapter-btn-next");
  15. console.log(buttons);
  16. const fullChapterName = document.querySelector(
  17. ".navi-change-chapter",
  18. ).value;
  19. const num = fullChapterName.includes(":")
  20. ? fullChapterName.split(":")[0].replace("Chapter ", "")
  21. : fullChapterName.replace("Chapter ", "");
  22.  
  23. if (num.includes("-") || num.includes(".")) {
  24. console.warn("Current chapter is half chapter, skipping");
  25. return;
  26. }
  27.  
  28. const currentChapter = parseInt(num);
  29. const chapters = [
  30. ...document.querySelectorAll(".navi-change-chapter option"),
  31. ];
  32. let nextChapterExists = false;
  33. for (const option of chapters) {
  34. if (option.getAttribute("data-c") !== (currentChapter + 1).toString())
  35. continue;
  36. const fullNextChapterName = option.value;
  37. const nextNum = fullNextChapterName.includes(":")
  38. ? fullNextChapterName.split(":")[0].replace("Chapter ", "")
  39. : fullNextChapterName.replace("Chapter ", "");
  40. if (nextNum.includes(".") || nextNum.includes("-")) continue;
  41. nextChapterExists = true;
  42. break;
  43. }
  44. if (!nextChapterExists) {
  45. console.warn("No next chapter, exiting");
  46. return;
  47. }
  48.  
  49. const nextUrl = location.href.replace(
  50. /\/chapter-(.+)/,
  51. `/chapter-${currentChapter + 1}`,
  52. );
  53. console.log("Next chapter url", nextUrl);
  54.  
  55. for (const button of buttons) {
  56. button.href = nextUrl;
  57. button.innerHTML = "NEXT CHAPTER (FULL) <i></i>";
  58. }
  59. })();