presence.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const presence = new Presence({
  2. clientId: "909694033251688449",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. presence.on("UpdateData", async () => {
  6. const buttons = await presence.getSetting<boolean>("buttons"),
  7. time = await presence.getSetting<boolean>("timestamps"),
  8. presenceData: PresenceData = {
  9. details: "Page not Supported",
  10. largeImageKey:
  11. "https://cdn.rcd.gg/PreMiD/websites/K/Komikcast/assets/logo.png",
  12. startTimestamp: browsingTimestamp,
  13. };
  14. if (document.location.href === "https://komikcast.com")
  15. presenceData.details = "Viewing Homepage";
  16. else if (document.location.pathname.endsWith("/daftar-komik/"))
  17. presenceData.details = "Viewing Komikcast Manga List";
  18. else if (document.location.pathname.endsWith("/pasang-iklan/"))
  19. presenceData.details = "Contact Komikcast";
  20. else if (document.location.pathname.endsWith("/project-list/"))
  21. presenceData.details = "Viewing Komikcast Project List";
  22. else if (document.location.pathname.endsWith("/bookmark/"))
  23. presenceData.details = "Viewing Bookmark";
  24. else if (document.location.pathname.endsWith("/download-aplikasi-komikcast/"))
  25. presenceData.details = "Download APK Komikcast";
  26. else if (document.location.pathname.startsWith("/komik/")) {
  27. presenceData.state = document
  28. .querySelector(".komik_info-content-body-title")
  29. .textContent.replace(/\t|\n/g, "");
  30. const type = document
  31. .querySelector(".komik_info-content-info-type b")
  32. .textContent.replace("Type:", "Comics");
  33. presenceData.details = `Viewing ${type}`;
  34. if (buttons) {
  35. presenceData.buttons = [
  36. {
  37. label: `View ${type}`,
  38. url: document.location.href,
  39. },
  40. ];
  41. }
  42. } else if (document.location.pathname.startsWith("/chapter/")) {
  43. const chapter = document.location.pathname
  44. .match(/chapter-\d+/)[0]
  45. .replace("c", "C")
  46. .replace("-", " ");
  47. presenceData.details = document
  48. .querySelector("div.chapter_headpost h1")
  49. .textContent.replace(/\t|\n/g, "")
  50. .replace(/Chapter \d+/, "");
  51. presenceData.state = chapter;
  52. if (buttons) {
  53. presenceData.buttons = [
  54. {
  55. label: "View Comic",
  56. url: document.location.href
  57. .replace("chapter", "komik")
  58. .replace(/-chapter-\d+/, "")
  59. .replace(/#\d+/, ""),
  60. },
  61. {
  62. label: chapter,
  63. url: document.location.href.replace(/#\d+/, ""),
  64. },
  65. ];
  66. }
  67. } else if (document.location.href.includes("?s=")) {
  68. presenceData.state = document
  69. .querySelector("div.list-update-search-header h1")
  70. .textContent.replace("SEARCH", "")
  71. .replace(/\t|\n/g, "");
  72. presenceData.smallImageKey = Assets.Search;
  73. presenceData.details = "Doing:";
  74. }
  75. if (!time) {
  76. delete presenceData.startTimestamp;
  77. delete presenceData.endTimestamp;
  78. }
  79. presence.setActivity(presenceData);
  80. });