ESJ Zone:修复无法点击的章节

修复因作者设定错误或网页设计问题等原因而无法点击的章节链接。

  1. // ==UserScript==
  2. // @name ESJ Zone: Repair Non-clickable Chapters
  3. // @name:zh-TW ESJ Zone:修復無法點擊的章節
  4. // @name:zh-CN ESJ Zone:修复无法点击的章节
  5. // @description Repair chapter links that were not-clickable due to for example, author misconfigured or by-designed.
  6. // @description:zh-TW 修復因作者設定錯誤或網頁設計問題等原因而無法點擊的章節連結。
  7. // @description:zh-CN 修复因作者设定错误或网页设计问题等原因而无法点击的章节链接。
  8. // @icon https://icons.duckduckgo.com/ip3/www.esjzone.cc.ico
  9. // @author Jason Kwok
  10. // @namespace https://jasonhk.dev/
  11. // @version 1.0.3
  12. // @license MIT
  13. // @match https://www.esjzone.cc/
  14. // @match https://www.esjzone.cc/update
  15. // @match https://www.esjzone.cc/update/
  16. // @match https://www.esjzone.cc/list
  17. // @match https://www.esjzone.cc/list/
  18. // @match https://www.esjzone.cc/list-*
  19. // @match https://www.esjzone.cc/tags/*
  20. // @match https://www.esjzone.cc/tags-*
  21. // @match https://www.esjzone.cc/my/favorite
  22. // @match https://www.esjzone.cc/my/favorite/*
  23. // @match https://www.esjzone.me/
  24. // @match https://www.esjzone.me/update
  25. // @match https://www.esjzone.me/update/
  26. // @match https://www.esjzone.me/list
  27. // @match https://www.esjzone.me/list/
  28. // @match https://www.esjzone.me/list-*
  29. // @match https://www.esjzone.me/tags/*
  30. // @match https://www.esjzone.me/tags-*
  31. // @match https://www.esjzone.me/my/favorite
  32. // @match https://www.esjzone.me/my/favorite/*
  33. // @run-at document-end
  34. // @grant none
  35. // @require https://update.greasyfork.org/scripts/482311/1296481/queue.js
  36. // @supportURL https://greasyfork.org/scripts/487645/feedback
  37. // ==/UserScript==
  38.  
  39. let translateText;
  40. if (GM.info.scriptHandler === "Greasemonkey")
  41. {
  42. translateText = window.eval("getCookie(targetEncodingCookie)") ? window.eval("translateText") : ((text) => text);
  43. }
  44. else
  45. {
  46. translateText = getCookie(targetEncodingCookie) ? window.translateText : ((text) => (text));
  47. }
  48.  
  49. async function findChapterUrl(novelUrl, chapterName)
  50. {
  51. const response = await fetch(novelUrl);
  52. if (response.status === 200)
  53. {
  54. const html = await response.text();
  55. const parser = new DOMParser();
  56. const page = parser.parseFromString(html, "text/html");
  57.  
  58. return Array.from(page.querySelectorAll("#chapterList a"))
  59. .reverse()
  60. .find((chapter) => (translateText(chapter.innerText.trim()) === chapterName))?.href ?? null;
  61. }
  62. }
  63.  
  64. let repaired = 0;
  65.  
  66. const queue = new Queue({ autostart: true, concurrency: 4 });
  67. queue.addEventListener("error", (event) => console.error(event.detail.error));
  68. queue.addEventListener("end", () => console.info(`Repaired ${repaired} URL(s).`));
  69.  
  70. const pathname = location.pathname;
  71. if (pathname === "/my/favorite" || pathname.startsWith("/my/favorite/"))
  72. {
  73. const novels = document.querySelectorAll(".product-item");
  74. for (const novel of novels)
  75. {
  76. const chapterWrapper = novel.querySelector(".book-ep div:nth-child(2)");
  77. const chapter = chapterWrapper.childNodes[0]?.splitText(5);
  78. if (chapter instanceof Text)
  79. {
  80. queue.push(async () =>
  81. {
  82. const url = await findChapterUrl(novel.querySelector(".product-title a").href, chapter.data);
  83. if (url)
  84. {
  85. const link = document.createElement("a");
  86. link.href = url;
  87.  
  88. link.append(chapter);
  89. chapterWrapper.append(link);
  90.  
  91. repaired++;
  92. }
  93. });
  94. }
  95. }
  96. }
  97. else
  98. {
  99. const novels = document.querySelectorAll(".card");
  100. for (const novel of novels)
  101. {
  102. const chapterWrapper = novel.querySelector(".card-ep");
  103. const chapter = chapterWrapper.childNodes[0];
  104. if (chapter instanceof Text)
  105. {
  106. queue.push(async () =>
  107. {
  108. const url = await findChapterUrl(novel.querySelector(".card-title a").href, chapter.data);
  109. if (url)
  110. {
  111. const link = document.createElement("a");
  112. link.href = url;
  113.  
  114. link.append(chapter);
  115. chapterWrapper.append(link);
  116.  
  117. repaired++;
  118. }
  119. });
  120. }
  121. }
  122. }