presence.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const presence = new Presence({
  2. clientId: "698217762660548799",
  3. }),
  4. browsingTimestamp = ~~(Date.now() / 1000);
  5. presence.on("UpdateData", async () => {
  6. const presenceData: PresenceData = {
  7. largeImageKey:
  8. "https://cdn.rcd.gg/PreMiD/websites/M/MangaKakalot/assets/logo.png",
  9. startTimestamp: browsingTimestamp,
  10. };
  11. switch (location.hostname) {
  12. case "mangakakalot.com": {
  13. if (document.location.pathname.includes("/chapter")) {
  14. const [title, chapterNum] = document
  15. .querySelector("div.info-top-chapter > h2")
  16. .textContent.split("Chapter");
  17. presenceData.details = title;
  18. presenceData.state = `CHAPTER ${chapterNum}`;
  19. presenceData.smallImageKey = Assets.Reading;
  20. } else if (document.location.pathname.includes("/manga_list")) {
  21. const [, genre] = document
  22. .querySelector(".breadcrumb.breadcrumbs > p > span:nth-child(3) > a")
  23. .textContent.split(":");
  24. presenceData.details = "Viewing genre:";
  25. presenceData.state = genre;
  26. } else if (
  27. location.pathname.includes("/manga") ||
  28. location.pathname.includes("/read")
  29. ) {
  30. presenceData.details = "Viewing manga:";
  31. presenceData.state = document.querySelector(
  32. ".manga-info-text > li > h1"
  33. ).textContent;
  34. } else if (location.pathname.includes("/latest"))
  35. presenceData.details = "Viewing the latest mangas";
  36. else if (document.location.pathname.includes("/search")) {
  37. presenceData.details = "Searching for:";
  38. presenceData.state = document
  39. .querySelector(".title.update-title")
  40. .textContent.split(" ")[1]
  41. .replaceAll("_", " ");
  42. presenceData.smallImageKey = Assets.Search;
  43. } else presenceData.details = "Browsing...";
  44. break;
  45. }
  46. case "manganato.com": {
  47. if (location.pathname.includes("/chapter")) {
  48. const [title, chapterNum] = document
  49. .querySelector(".info-top-chapter > h2")
  50. .textContent.split("Chapter");
  51. presenceData.details = title;
  52. presenceData.state = `CHAPTER ${chapterNum}`;
  53. presenceData.smallImageKey = Assets.Reading;
  54. } else if (location.pathname.includes("/manga")) {
  55. presenceData.details = "Viewing manga:";
  56. presenceData.state = document.querySelector(
  57. ".story-info-right > h1"
  58. ).textContent;
  59. } else if (location.pathname.includes("/genre")) {
  60. presenceData.details = "Viewing genre:";
  61. presenceData.state = document
  62. .querySelector(".panel-breadcrumb > a:nth-child(3)")
  63. .textContent.split(":")[1];
  64. } else if (location.pathname.includes("/search")) {
  65. presenceData.details = "Searching for:";
  66. presenceData.state = document
  67. .querySelector(".panel-breadcrumb")
  68. .childNodes[4].textContent.split(":")[1]
  69. .trim()
  70. .replaceAll("_", " ");
  71. presenceData.smallImageKey = Assets.Search;
  72. } else presenceData.details = "Browsing...";
  73. break;
  74. }
  75. }
  76. if (presenceData.details) presence.setActivity(presenceData);
  77. else presence.setActivity();
  78. });