presence.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. const presence = new Presence({
  2. clientId: "823408394098311178",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. const enum Assets {
  6. Key = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/0.png",
  7. Slide = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/1.png",
  8. Catch = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/2.png",
  9. Taiko = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/3.png",
  10. Ring = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/4.png",
  11. Pad = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/5.png",
  12. User = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/6.png",
  13. Skin = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/7.png",
  14. Talk = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/8.png",
  15. Gameplay = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/9.png",
  16. Home = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/10.png",
  17. Leaderboard = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/11.png",
  18. Song = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/12.png",
  19. Charting = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/13.png",
  20. Inventory = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/14.png",
  21. Resource = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/15.png",
  22. Feedback = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/16.png",
  23. Notification = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/17.png",
  24. Wiki = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/18.png",
  25. Store = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/19.png",
  26. Discuss = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/20.png",
  27. Malody = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/21.png",
  28. Jail = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/22.png",
  29. Livem = "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/23.png",
  30. }
  31. presence.on("UpdateData", async () => {
  32. const privacy = await presence.getSetting<boolean>("privacy"),
  33. presenceData: PresenceData = {
  34. largeImageKey:
  35. "https://cdn.rcd.gg/PreMiD/websites/M/Mugzone/assets/logo.png",
  36. startTimestamp: browsingTimestamp,
  37. };
  38. if (privacy) presenceData.details = "Browsing Malody Website";
  39. else if (document.location.pathname === "/")
  40. presenceData.details = "Malody Main Page";
  41. else if (document.location.pathname === "/index") {
  42. presenceData.smallImageKey = Assets.Home;
  43. presenceData.details = "Viewing Home Page";
  44. } else if (document.location.pathname.endsWith("/chart")) {
  45. presenceData.smallImageKey = Assets.Store;
  46. presenceData.details = "Browsing Chart Store";
  47. } else if (document.location.pathname.startsWith("/page/all/player")) {
  48. presenceData.smallImageKey = Assets.Leaderboard;
  49. presenceData.details = "Viewing Leaderboard";
  50. if (document.location.href.endsWith("?from=0&mode=0")) {
  51. presenceData.smallImageKey = Assets.Key;
  52. presenceData.smallImageText = "KeyMode";
  53. presenceData.state = "Key Mode";
  54. } else if (document.location.href.endsWith("?from=0&mode=3")) {
  55. presenceData.smallImageKey = Assets.Catch;
  56. presenceData.smallImageText = "CatchMode";
  57. presenceData.state = "Catch Mode";
  58. } else if (document.location.href.endsWith("?from=0&mode=4")) {
  59. presenceData.smallImageKey = Assets.Pad;
  60. presenceData.smallImageText = "PadMode";
  61. presenceData.state = "Pad mode";
  62. } else if (document.location.href.endsWith("?from=0&mode=5")) {
  63. presenceData.smallImageKey = Assets.Taiko;
  64. presenceData.smallImageText = "TaikoMode";
  65. presenceData.state = "Taiko Mode";
  66. } else if (document.location.href.endsWith("?from=0&mode=6")) {
  67. presenceData.smallImageKey = Assets.Ring;
  68. presenceData.smallImageText = "RingMode";
  69. presenceData.state = "Ring Mode";
  70. } else if (document.location.href.endsWith("?from=0&mode=7")) {
  71. presenceData.smallImageKey = Assets.Slide;
  72. presenceData.smallImageText = "SlideMode";
  73. presenceData.state = "Slide Mode";
  74. } else if (document.location.pathname.endsWith("/player")) {
  75. presenceData.smallImageKey = Assets.Key;
  76. presenceData.smallImageText = "KeyMode";
  77. presenceData.state = "Key Mode";
  78. }
  79. } else if (document.location.href.includes("/song")) {
  80. presenceData.smallImageKey = Assets.Song;
  81. presenceData.details = "Viewing a song";
  82. presenceData.state = document.querySelector(
  83. "#content > div.song_title.g_rblock > div.right > h2.textfix.title"
  84. ).textContent;
  85. presenceData.buttons = [
  86. {
  87. label: "View Song",
  88. url: document.URL,
  89. },
  90. ];
  91. } else if (document.location.href.includes("/chart")) {
  92. presenceData.smallImageKey = Assets.Song;
  93. presenceData.details = document.querySelector(
  94. "#content > div.song_title.g_rblock > div.right > h2.textfix.title"
  95. ).textContent;
  96. presenceData.state = document.querySelector(
  97. "#content > div.song_title.g_rblock > div.right > h2.mode > span:nth-child(2)"
  98. ).textContent;
  99. presenceData.buttons = [
  100. {
  101. label: "View Chart",
  102. url: document.URL,
  103. },
  104. ];
  105. } else if (document.location.pathname.startsWith("/store")) {
  106. if (document.location.pathname.endsWith("/skin")) {
  107. presenceData.smallImageKey = Assets.Skin;
  108. presenceData.details = "Browsing Skin Store";
  109. } else if (document.location.pathname.includes("/skin/detail")) {
  110. presenceData.smallImageKey = Assets.Skin;
  111. presenceData.details = "Viewing a skin:";
  112. presenceData.state = document.querySelector(
  113. "#content > div.song_title.g_rblock > div.right > h2.textfix.title"
  114. ).textContent;
  115. presenceData.buttons = [
  116. {
  117. label: "View Skin",
  118. url: document.URL,
  119. },
  120. ];
  121. } else if (document.location.pathname.endsWith("/all")) {
  122. presenceData.smallImageKey = Assets.Store;
  123. presenceData.details = "Browsing Item Store";
  124. } else if (document.location.pathname.endsWith("/my")) {
  125. presenceData.smallImageKey = Assets.Inventory;
  126. presenceData.details = "Viewing Inventory";
  127. }
  128. } else if (document.location.pathname.startsWith("/talk")) {
  129. if (document.location.pathname.includes("/topic")) {
  130. presenceData.smallImageKey = Assets.Talk;
  131. presenceData.details = `Viewing topic: ${
  132. document.querySelector("#chead > div > a").textContent
  133. }`;
  134. presenceData.state = document.querySelector(
  135. "#g_talk > div.g_talk_title > p > span"
  136. ).textContent;
  137. } else if (document.location.pathname.includes("/user")) {
  138. if (document.location.pathname.endsWith("/user")) {
  139. presenceData.smallImageKey = Assets.Talk;
  140. presenceData.details = "Checking Inbox";
  141. } else if (document.location.pathname.endsWith("/notify")) {
  142. presenceData.smallImageKey = Assets.Notification;
  143. presenceData.details = "Viewing Notification";
  144. }
  145. } else if (document.location.pathname.includes("/group")) {
  146. presenceData.details = "Viewing Discussion Page";
  147. if (document.location.href.endsWith("/1")) {
  148. presenceData.smallImageKey = Assets.Gameplay;
  149. presenceData.state = "Gameplay Disscussion";
  150. } else if (document.location.href.endsWith("/2")) {
  151. presenceData.smallImageKey = Assets.Charting;
  152. presenceData.state = "Chart Discussion";
  153. } else if (document.location.href.endsWith("/3")) {
  154. presenceData.smallImageKey = Assets.Resource;
  155. presenceData.state = "Skin & Resource";
  156. } else if (document.location.href.endsWith("/4")) {
  157. presenceData.smallImageKey = Assets.Feedback;
  158. presenceData.state = "Feedback";
  159. }
  160. }
  161. } else if (document.location.pathname.startsWith("/accounts")) {
  162. if (document.location.pathname.includes("/login"))
  163. presenceData.details = "Logging in";
  164. else if (document.location.pathname.endsWith("/accounts/limit")) {
  165. presenceData.smallImageKey = Assets.Jail;
  166. presenceData.details = "Visiting the Jail";
  167. presenceData.state = "What Is This Place Anyway?";
  168. presenceData.buttons = [
  169. {
  170. label: `Go with ${
  171. document.querySelector("#header > div > a:nth-child(4) > b")
  172. .textContent
  173. }`,
  174. url: document.URL,
  175. },
  176. ];
  177. } else if (document.location.pathname.includes("/user")) {
  178. if (
  179. document.querySelector(
  180. "#content > div.user_head.g_rblock > div.right > p.name > span"
  181. ).textContent ===
  182. document.querySelector("#header > div > a:nth-child(4) > b").textContent
  183. ) {
  184. const top = Math.min(
  185. +document
  186. .querySelector(
  187. "#content > div.body > div.panel > div.rank.g_rblock > div:nth-child(1) > div > p.rank"
  188. )
  189. .textContent.replace("#", ""),
  190. +document
  191. .querySelector(
  192. "#content > div.body > div.panel > div.rank.g_rblock > div:nth-child(2) > div > p.rank"
  193. )
  194. .textContent.replace("#", ""),
  195. +document
  196. .querySelector(
  197. "#content > div.body > div.panel > div.rank.g_rblock > div:nth-child(3) > div > p.rank"
  198. )
  199. .textContent.replace("#", ""),
  200. +document
  201. .querySelector(
  202. "#content > div.body > div.panel > div.rank.g_rblock > div:nth-child(4) > div > p.rank"
  203. )
  204. .textContent.replace("#", ""),
  205. +document
  206. .querySelector(
  207. "#content > div.body > div.panel > div.rank.g_rblock > div:nth-child(5) > div > p.rank"
  208. )
  209. .textContent.replace("#", ""),
  210. +document
  211. .querySelector(
  212. "#content > div.body > div.panel > div.rank.g_rblock > div:nth-child(6) > div > p.rank"
  213. )
  214. .textContent.replace("#", "")
  215. );
  216. presenceData.details = `User: ${
  217. document.querySelector(
  218. "#content > div.user_head.g_rblock > div.right > p.name > span"
  219. ).textContent
  220. }`;
  221. presenceData.state = `Best Rank: ${top}`;
  222. presenceData.smallImageKey = Assets.User;
  223. presenceData.buttons = [
  224. {
  225. label: "Visit My Profile!",
  226. url: document.URL,
  227. },
  228. ];
  229. } else {
  230. presenceData.details = "Viewing User: ";
  231. presenceData.state = document.querySelector(
  232. "#content > div.user_head.g_rblock > div.right > p.name > span"
  233. ).textContent;
  234. presenceData.smallImageKey = Assets.User;
  235. }
  236. } else if (document.location.pathname.endsWith("/friend")) {
  237. presenceData.smallImageKey = Assets.User;
  238. presenceData.details = "Viewing Friends List";
  239. } else if (document.location.pathname.includes("/config/profile")) {
  240. presenceData.smallImageKey = Assets.Writing;
  241. presenceData.details = "Editing Profile";
  242. }
  243. } else if (document.location.pathname.includes("/page/userpage/edit/")) {
  244. presenceData.smallImageKey = Assets.Writing;
  245. presenceData.details = `${
  246. document.querySelector("#content > div.g_title").textContent
  247. }profile`;
  248. } else if (document.location.pathname.includes("/page/search")) {
  249. presenceData.smallImageKey = Assets.Search;
  250. presenceData.details = document.querySelector(
  251. "#content > div.g_title"
  252. ).textContent;
  253. } else if (document.location.pathname.includes("/page/all")) {
  254. presenceData.smallImageKey = Assets.Viewing;
  255. presenceData.details = "Viewing All Pages";
  256. } else if (document.location.pathname.includes("/page/latest")) {
  257. presenceData.smallImageKey = Assets.Viewing;
  258. presenceData.details = "Viewing Recent Changes";
  259. presenceData.state = "Pages";
  260. } else if (document.location.pathname.includes("/page/create")) {
  261. presenceData.smallImageKey = Assets.Writing;
  262. presenceData.details = "Creating a New Page";
  263. } else if (document.location.href.includes("/page/create?type=6")) {
  264. presenceData.smallImageKey = Assets.Writing;
  265. presenceData.details = "Creating a Template";
  266. } else if (document.location.pathname.startsWith("/wiki")) {
  267. presenceData.smallImageKey = Assets.Wiki;
  268. presenceData.details = "Viewing Wiki";
  269. presenceData.state = document.querySelector(
  270. "#content > div.wiki_title.g_rblock > div.title"
  271. ).textContent;
  272. }
  273. presence.setActivity(presenceData);
  274. });