Better Links UX for ESJ Zone

Improve the UX of ESJ Zone by tweaking the hyperlinks in the pages.

  1. // ==UserScript==
  2. // @name Better Links UX for ESJ Zone
  3. // @name:zh-TW ESJ Zone:更好的連結體驗
  4. // @description Improve the UX of ESJ Zone by tweaking the hyperlinks in the pages.
  5. // @description:zh-TW 透過調整 ESJ Zone 的超連結來改善使用體驗。
  6. // @icon https://icons.duckduckgo.com/ip3/www.esjzone.cc.ico
  7. // @author Jason Kwok
  8. // @namespace https://jasonhk.dev/
  9. // @version 1.2.2
  10. // @license MIT
  11. // @match https://www.esjzone.cc/detail/*
  12. // @match https://www.esjzone.cc/forum/*
  13. // @run-at document-end
  14. // @grant none
  15. // @supportURL https://greasyfork.org/scripts/449315/feedback
  16. // ==/UserScript==
  17.  
  18. const pathname = location.pathname;
  19.  
  20. if (pathname.startsWith("/detail/"))
  21. {
  22. const chapters = document.querySelectorAll("#chapterList a");
  23. for (const chapter of chapters)
  24. {
  25. chapter.target = "_self";
  26. }
  27. }
  28. else if (pathname.startsWith("/forum/") && !pathname.endsWith(".html"))
  29. {
  30. const observer = new MutationObserver((records) =>
  31. {
  32. for (const record of records)
  33. {
  34. for (const node of record.addedNodes)
  35. {
  36. const link = node.querySelector("a");
  37. if (link) { link.target = "_self"; }
  38. }
  39. }
  40. });
  41.  
  42. observer.observe(document.querySelector(".forum-list > tbody"), { childList: true });
  43. }