presence.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. const presence = new Presence({
  2. clientId: "1002734097719894067",
  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/M/Merriam-Webster/assets/0.png",
  9. startTimestamp: browsingTimestamp,
  10. },
  11. { pathname, href } = window.location;
  12. if (pathname === "/") presenceData.details = "Browsing the dictionary";
  13. else if (document.location.pathname.startsWith("/dictionary/")) {
  14. const word = document.querySelector(
  15. "#left-content > div:nth-child(2) > div:nth-child(1) > h1"
  16. ).textContent;
  17. presenceData.details = "Viewing definitions";
  18. presenceData.state = `${
  19. word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
  20. }`;
  21. presenceData.buttons = [
  22. {
  23. label: "View Page",
  24. url: href,
  25. },
  26. ];
  27. } else if (document.location.pathname.startsWith("/word-games/")) {
  28. presenceData.details = "Playing a word game";
  29. presenceData.state = document.querySelector(
  30. '[class="play-title"]'
  31. ).textContent;
  32. presenceData.buttons = [
  33. {
  34. label: "Play",
  35. url: href,
  36. },
  37. ];
  38. } else if (document.location.pathname.startsWith("/word-of-the-day")) {
  39. presenceData.details = "Viewing the word of the day";
  40. presenceData.state = document.querySelector(
  41. '[class="word-and-pronunciation"]'
  42. ).firstElementChild.textContent;
  43. presenceData.buttons = [
  44. {
  45. label: "View Page",
  46. url: href,
  47. },
  48. ];
  49. } else if (document.location.pathname.startsWith("/words-at-play/")) {
  50. presenceData.details = "Reading post";
  51. presenceData.state =
  52. document.querySelector('[class="title-lg"]').textContent;
  53. presenceData.buttons = [
  54. {
  55. label: "View Post",
  56. url: href,
  57. },
  58. ];
  59. } else if (document.location.pathname.startsWith("/reviews/")) {
  60. presenceData.details = "Reading a review";
  61. presenceData.state = document.querySelector(
  62. '[class="text-center"]'
  63. ).textContent;
  64. presenceData.buttons = [
  65. {
  66. label: "View Review",
  67. url: href,
  68. },
  69. ];
  70. } else if (document.location.pathname.startsWith("/video/")) {
  71. presenceData.details = "Watching a video";
  72. presenceData.state = `${
  73. document.querySelector(
  74. "body > div.outer-container > div > div.full-cnt.clearfix.bg-white.padding-lr-0p8em > main > div > div > div.play-text-content > h1"
  75. ).textContent
  76. }`;
  77. presenceData.buttons = [
  78. {
  79. label: "Watch Video",
  80. url: href,
  81. },
  82. ];
  83. } else if (document.location.pathname.startsWith("/thesaurus/")) {
  84. const word = document.querySelector(
  85. "#left-content > div.row.entry-header.thesaurus > div:nth-child(1) > h1"
  86. ).textContent;
  87. presenceData.details = "Viewing synonyms";
  88. presenceData.state = `${
  89. word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
  90. }`;
  91. presenceData.buttons = [
  92. {
  93. label: "View Page",
  94. url: href,
  95. },
  96. ];
  97. } else if (document.location.pathname.startsWith("/help/")) {
  98. presenceData.details = "Viewing the help page";
  99. presenceData.state = `${
  100. document.querySelector("#static_pg_container > section > h2").textContent
  101. }`;
  102. presenceData.buttons = [
  103. {
  104. label: "View Page",
  105. url: href,
  106. },
  107. ];
  108. } else if (document.location.pathname.startsWith("/vocabulary/")) {
  109. presenceData.details = "Viewing vocabulary learning lists";
  110. presenceData.state = `${document
  111. .querySelector("meta[name='og:title']")
  112. .getAttribute("content")}`;
  113. presenceData.buttons = [
  114. {
  115. label: "View Page",
  116. url: href,
  117. },
  118. ];
  119. } else if (document.location.pathname.startsWith("/browse/legal/")) {
  120. presenceData.details = "Browsing the law dictionary";
  121. presenceData.state = `${
  122. document.querySelector(
  123. "body > div.outer-container > div > div.main-wrapper.clearfix > div.univ-title-container > h1"
  124. ).textContent
  125. }`;
  126. presenceData.buttons = [
  127. {
  128. label: "View Page",
  129. url: href,
  130. },
  131. ];
  132. } else if (document.location.pathname.startsWith("/browse/medical/")) {
  133. presenceData.details = "Browsing the medical dictionary";
  134. presenceData.state = `${
  135. document.querySelector(
  136. "body > div.outer-container > div > div.main-wrapper.clearfix > div.univ-title-container > h1"
  137. ).textContent
  138. }`;
  139. presenceData.buttons = [
  140. {
  141. label: "View Page",
  142. url: href,
  143. },
  144. ];
  145. } else if (document.location.pathname.startsWith("/legal/")) {
  146. presenceData.details = "Viewing legal definition";
  147. presenceData.state = `${
  148. document.querySelector(
  149. "#left-content > div.row.entry-header.long-headword > div:nth-child(1) > h1 > span"
  150. ).textContent
  151. }`;
  152. presenceData.buttons = [
  153. {
  154. label: "View Page",
  155. url: href,
  156. },
  157. ];
  158. } else if (document.location.pathname.startsWith("/medical/")) {
  159. const word = document.querySelector(
  160. "#left-content > div.row.entry-header.long-headword > div:nth-child(1) > h1 > span"
  161. ).textContent;
  162. presenceData.details = "Viewing medical definition";
  163. presenceData.state = `${
  164. word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
  165. }`;
  166. presenceData.buttons = [
  167. {
  168. label: "View Page",
  169. url: href,
  170. },
  171. ];
  172. } else if (document.location.pathname.startsWith("/about-us/")) {
  173. presenceData.details = "Viewing the about page";
  174. presenceData.state = `${
  175. document.querySelector(
  176. "body > div.outer-container > div > div.main-wrapper.clearfix > div.univ-title-container > h1"
  177. ).textContent
  178. }`;
  179. presenceData.buttons = [
  180. {
  181. label: "View Page",
  182. url: href,
  183. },
  184. ];
  185. } else {
  186. switch (pathname) {
  187. case "/word-games": {
  188. presenceData.details = "Browsing games and quizzes";
  189. break;
  190. }
  191. case "/words-at-play": {
  192. presenceData.details = "Browsing words at play";
  193. break;
  194. }
  195. case "/reviews": {
  196. presenceData.details = "Browsing reviews";
  197. break;
  198. }
  199. case "/video": {
  200. presenceData.details = "Browsing videos";
  201. break;
  202. }
  203. case "/thesaurus": {
  204. presenceData.details = "Browsing the thesaurus";
  205. break;
  206. }
  207. case "/legal": {
  208. presenceData.details = "Browsing the law dictionary";
  209. break;
  210. }
  211. case "/medical": {
  212. presenceData.details = "Browsing the medical dictionary";
  213. break;
  214. }
  215. case "/login": {
  216. presenceData.details = "Logging in";
  217. break;
  218. }
  219. case "/register": {
  220. presenceData.details = "Signing up";
  221. break;
  222. }
  223. case "/settings": {
  224. presenceData.details = "Managing their account details";
  225. break;
  226. }
  227. case "/recents": {
  228. presenceData.details = "Viewing their recent lookups";
  229. break;
  230. }
  231. case "/saved-words": {
  232. presenceData.details = "Viewing their saved words";
  233. break;
  234. }
  235. case "/help": {
  236. presenceData.details = "Viewing the help page";
  237. break;
  238. }
  239. case "/advertising": {
  240. presenceData.details = "Viewing advertisement info";
  241. break;
  242. }
  243. case "/contact-us": {
  244. presenceData.details = "Viewing the contact us page";
  245. break;
  246. }
  247. case "/about-us": {
  248. presenceData.details = "Viewing the about page";
  249. break;
  250. }
  251. }
  252. }
  253. presence.setActivity(presenceData);
  254. });