presence.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const presence = new Presence({
  2. clientId: "808753360152559716",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. presence.on("UpdateData", async () => {
  6. const presenceData: PresenceData = {
  7. largeImageKey:
  8. "https://cdn.rcd.gg/PreMiD/websites/W/Wattpad/assets/logo.png",
  9. };
  10. let story;
  11. const path = document.location.pathname;
  12. if (path === "/home" || path === "/") {
  13. presenceData.details = "Viewing Homepage";
  14. presenceData.startTimestamp = browsingTimestamp;
  15. } else if (path.includes("/stories") || path.includes("/featured")) {
  16. presenceData.details = "Browsing Stories";
  17. presenceData.startTimestamp = browsingTimestamp;
  18. } else if (path.startsWith("/user")) {
  19. presenceData.details = "Viewing User Profile";
  20. presenceData.state = document.querySelector("#alias").textContent;
  21. presenceData.startTimestamp = browsingTimestamp;
  22. } else if (path.includes("/myworks")) {
  23. if (path.endsWith("/myworks")) {
  24. presenceData.details = "Viewing their Stories";
  25. presenceData.startTimestamp = browsingTimestamp;
  26. } else if (path.includes("/write")) {
  27. story = document.querySelector("p.group-title").textContent;
  28. presenceData.details = "Writing a Story";
  29. presenceData.state = story;
  30. presenceData.startTimestamp = browsingTimestamp;
  31. } else if (path.includes("/analytics")) {
  32. story = document.querySelector(".text-left h2").textContent;
  33. presenceData.details = "Viewing Analytics";
  34. presenceData.state = story;
  35. presenceData.startTimestamp = browsingTimestamp;
  36. } else if (path.includes("/new")) {
  37. presenceData.details = "Setting-up a new Story";
  38. presenceData.startTimestamp = browsingTimestamp;
  39. } else {
  40. story = document.querySelector(
  41. "div.works-item-metadata span.h4"
  42. ).textContent;
  43. presenceData.details = "Viewing their Story";
  44. presenceData.state = story;
  45. presenceData.startTimestamp = browsingTimestamp;
  46. }
  47. } else if (path.includes("/story")) {
  48. if (path.endsWith("/rankings")) {
  49. story = document.querySelector("#story-ranking h2").textContent;
  50. presenceData.details = "Viewing Rankings";
  51. presenceData.state = story;
  52. presenceData.startTimestamp = browsingTimestamp;
  53. } else {
  54. story = document.querySelector("head > title").textContent;
  55. presenceData.details = "Viewing a Story";
  56. presenceData.state = story;
  57. presenceData.startTimestamp = browsingTimestamp;
  58. }
  59. } else if (document.location.pathname.split("/")[1].match(/^\d/)) {
  60. story = document.querySelector(
  61. "#funbar-part-details > span > span.info > h2"
  62. ).textContent;
  63. presenceData.details = `Reading ${story}`;
  64. presenceData.state = document.querySelector(
  65. "#funbar-story > div > ul > li.active > a > div"
  66. ).textContent;
  67. presenceData.startTimestamp = browsingTimestamp;
  68. } else if (path.includes("/settings")) {
  69. presenceData.details = "Viewing Settings";
  70. presenceData.startTimestamp = browsingTimestamp;
  71. } else if (path.includes("/inbox")) {
  72. presenceData.details = "Viewing Inbox";
  73. presenceData.startTimestamp = browsingTimestamp;
  74. } else if (path.includes("/notifications")) {
  75. presenceData.details = "Viewing Notifications";
  76. presenceData.startTimestamp = browsingTimestamp;
  77. } else if (path.includes("/newsfeed")) {
  78. presenceData.details = "Viewing Newsfeed";
  79. presenceData.startTimestamp = browsingTimestamp;
  80. } else if (path.includes("/library")) {
  81. presenceData.details = "Viewing Library";
  82. presenceData.startTimestamp = browsingTimestamp;
  83. } else if (path.includes("/archive")) {
  84. presenceData.details = "Viewing Archive";
  85. presenceData.startTimestamp = browsingTimestamp;
  86. } else if (path.includes("/list")) {
  87. presenceData.details = "Viewing Reading Lists";
  88. presenceData.startTimestamp = browsingTimestamp;
  89. } else if (path.includes("/invite-friends")) {
  90. presenceData.details = "Inviting Friends";
  91. presenceData.startTimestamp = browsingTimestamp;
  92. } else if (path.includes("/writers")) {
  93. presenceData.details = "Viewing Writers Resources";
  94. presenceData.startTimestamp = browsingTimestamp;
  95. } else if (path.includes("contests")) {
  96. presenceData.details = "Viewing Writing Contests";
  97. presenceData.startTimestamp = browsingTimestamp;
  98. } else if (path.includes("premium")) {
  99. presenceData.details = "Viewing Premium";
  100. presenceData.startTimestamp = browsingTimestamp;
  101. } else {
  102. presenceData.details = "Somewhere on the site";
  103. presenceData.startTimestamp = browsingTimestamp;
  104. }
  105. presence.setActivity(presenceData);
  106. });