presence.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. const presence = new Presence({
  2. clientId: "702467872315670529",
  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/T/TrueAchievements/assets/logo.png",
  9. };
  10. presenceData.startTimestamp = browsingTimestamp;
  11. if (document.location.pathname.includes("/gamer/")) {
  12. const user = document.querySelector(".tabs > ul > li").textContent;
  13. if (document.location.pathname.includes("/gamecollection")) {
  14. presenceData.details = `Viewing ${user}'s`;
  15. presenceData.state = "Game Collection";
  16. } else if (document.location.pathname.includes("/achievements")) {
  17. presenceData.details = `Viewing ${user}'s`;
  18. presenceData.state = "Achievements";
  19. } else if (document.location.pathname.includes("/goals")) {
  20. presenceData.details = `Viewing ${user}'s`;
  21. presenceData.state = "Goals";
  22. } else if (document.location.pathname.includes("/blog")) {
  23. presenceData.details = `Viewing ${user}'s`;
  24. presenceData.state = "Blog";
  25. } else if (document.location.pathname.includes("/stats")) {
  26. presenceData.details = `Viewing ${user}'s`;
  27. presenceData.state = "Statistics";
  28. } else {
  29. presenceData.details = "Viewing profile of:";
  30. presenceData.state = user;
  31. }
  32. } else if (document.location.pathname.includes("/game/")) {
  33. if (document.location.pathname.includes("/achievements")) {
  34. presenceData.details = "Viewing Achievements of game:";
  35. presenceData.state = document.querySelector(
  36. "div.panel-header.w > h3 > a"
  37. ).textContent;
  38. } else if (document.location.pathname.includes("/forum")) {
  39. presenceData.details = "Viewing Forums of game:";
  40. presenceData.state = document.title.replace(" Forum", "");
  41. } else if (document.location.pathname.includes("/walkthrough")) {
  42. presenceData.details = "Viewing Walkthrough of game:";
  43. presenceData.state = document
  44. .querySelector(".pagetitle")
  45. .textContent.replace(" Walkthrough", "");
  46. } else if (document.location.pathname.includes("/reviews")) {
  47. presenceData.details = "Viewing Reviews of game:";
  48. presenceData.state = document
  49. .querySelector(".pagetitle")
  50. .textContent.replace(" Reviews", "");
  51. } else if (document.location.pathname.includes("/scores")) {
  52. presenceData.details = "Viewing Top Scores of game:";
  53. presenceData.state = document
  54. .querySelector(".pagetitle")
  55. .textContent.replace("Top Scores For ", "");
  56. } else if (document.location.pathname.includes("/gamers")) {
  57. presenceData.details = "Viewing Gamers of game:";
  58. presenceData.state = document.querySelector(
  59. "div.panel-header.w > h3 > a"
  60. ).textContent;
  61. } else {
  62. presenceData.details = "Viewing game:";
  63. presenceData.state = document.querySelector(".info").textContent.trim();
  64. }
  65. } else if (
  66. document.querySelector(".pagetitle") &&
  67. document.querySelector(".pagetitle").textContent === "Achievement Details"
  68. ) {
  69. presenceData.details = "Viewing acheievement:";
  70. presenceData.state = document.querySelector(".title").textContent;
  71. presenceData.smallImageKey = Assets.Reading;
  72. presenceData.smallImageText = `Game: ${
  73. document.querySelector("div.panel-header.w > h3 > a").textContent
  74. }`;
  75. } else {
  76. switch (document.location.pathname) {
  77. case "/news":
  78. case "/news.aspx": {
  79. presenceData.details = "Viewing the latest news";
  80. break;
  81. }
  82. case "/xbox-one/news": {
  83. presenceData.details = "Viewing the latest Xbox One news";
  84. break;
  85. }
  86. case "/xbox-one/games": {
  87. presenceData.details = "Viewing the latest Xbox One games";
  88. break;
  89. }
  90. case "/xbox-one/prices": {
  91. presenceData.details = "Viewing the latest Xbox One prices";
  92. break;
  93. }
  94. case "/xbox-360/news": {
  95. presenceData.details = "Viewing the latest Xbox 360 news";
  96. break;
  97. }
  98. case "/xbox-360/games": {
  99. presenceData.details = "Viewing the latest Xbox 360 games";
  100. break;
  101. }
  102. case "/xbox-360/prices": {
  103. presenceData.details = "Viewing the latest Xbox 360 prices";
  104. break;
  105. }
  106. case "/windows/news": {
  107. presenceData.details = "Viewing the latest Windows news";
  108. break;
  109. }
  110. case "/windows/games": {
  111. presenceData.details = "Viewing the latest Windows games";
  112. break;
  113. }
  114. case "/windows/prices": {
  115. presenceData.details = "Viewing the latest Windows prices";
  116. break;
  117. }
  118. case "/id-at-xbox/news": {
  119. presenceData.details = "Viewing the latest ID@Xbox news";
  120. break;
  121. }
  122. case "/id-at-xbox/games": {
  123. presenceData.details = "Viewing the latest ID@Xbox games";
  124. break;
  125. }
  126. case "/xbox-series-x/news": {
  127. presenceData.details = "Viewing the latest Xbox Series X news";
  128. break;
  129. }
  130. case "/xbox-series-x/games": {
  131. presenceData.details = "Viewing the latest Xbox Series X games";
  132. break;
  133. }
  134. case "/xbox-game-pass/news": {
  135. presenceData.details = "Viewing the latest Xbox Game Pass news";
  136. break;
  137. }
  138. case "/xbox-game-pass/games": {
  139. presenceData.details = "Viewing the latest Xbox Game Pass games";
  140. break;
  141. }
  142. case "/xbox-quests": {
  143. presenceData.details = "Viewing the latest Xbox Game Pass quests";
  144. break;
  145. }
  146. case "/ea-access/news": {
  147. presenceData.details = "Viewing the latest EA Access news";
  148. break;
  149. }
  150. case "/ea-access/games": {
  151. presenceData.details = "Viewing the latest EA Access games";
  152. break;
  153. }
  154. case "/xbox-game-pass-pc/news": {
  155. presenceData.details = "Viewing the latest Xbox Game Pass for PC news";
  156. break;
  157. }
  158. case "/xbox-game-pass-pc/games": {
  159. presenceData.details = "Viewing the latest Xbox Game Pass for PC games";
  160. break;
  161. }
  162. case "/videos": {
  163. presenceData.details = "Viewing the latest videos";
  164. break;
  165. }
  166. default:
  167. if (document.querySelector(".newsitem > header > h1")) {
  168. presenceData.details = "Reading article:";
  169. presenceData.state = document.querySelector(
  170. ".newsitem > header > h1"
  171. ).textContent;
  172. presenceData.smallImageKey = Assets.Reading;
  173. } else {
  174. switch (document.location.pathname) {
  175. case "/suggestnews.aspx": {
  176. presenceData.details = "Suggesting new news";
  177. presenceData.smallImageKey = Assets.Writing;
  178. break;
  179. }
  180. case "/news/community": {
  181. presenceData.details = "Viewing the latest community news";
  182. break;
  183. }
  184. case "/news/tags/podcast": {
  185. presenceData.details = "Viewing the latest podcasts";
  186. break;
  187. }
  188. case "/siteupdates": {
  189. presenceData.details = "Viewing the latest site updates";
  190. break;
  191. }
  192. case "/games.aspx": {
  193. presenceData.details = "Viewing all games";
  194. break;
  195. }
  196. case "/xbox-achievements.aspx": {
  197. presenceData.details = "Viewing all achievements";
  198. break;
  199. }
  200. case "/solutions-required.aspx": {
  201. presenceData.details = "Viewing all achievements";
  202. presenceData.state = "that require guides";
  203. break;
  204. }
  205. case "/sitereviews.aspx": {
  206. presenceData.details = "Viewing site reviews";
  207. break;
  208. }
  209. case "/solutions": {
  210. presenceData.details = "Viewing achievement solutions";
  211. break;
  212. }
  213. case "/xbox-live.aspx": {
  214. presenceData.details = "Viewing Xbox Live status";
  215. break;
  216. }
  217. case "/challenges.aspx": {
  218. presenceData.details = "Viewing the Challanges Hub";
  219. break;
  220. }
  221. case "/gamingsessions.aspx": {
  222. presenceData.details = "Viewing the Gaming Sessions";
  223. break;
  224. }
  225. default:
  226. if (
  227. document.location.pathname.includes("/viewcomment.aspx") &&
  228. document.querySelector(".pagetitle") &&
  229. document.querySelector(".pagetitle").textContent ===
  230. "View Solution"
  231. ) {
  232. presenceData.details = "Viewing solution for achievement:";
  233. presenceData.state =
  234. document.querySelector(".title").textContent;
  235. presenceData.smallImageKey = Assets.Reading;
  236. presenceData.smallImageText = `Game: ${
  237. document.querySelector("div.panel-header.w > h3 > a")
  238. .textContent
  239. }`;
  240. } else {
  241. switch (document.location.pathname) {
  242. case "/serieslist.aspx": {
  243. presenceData.details = "Viewing Game Series";
  244. break;
  245. }
  246. case "/popularachievements.aspx": {
  247. presenceData.details = "Viewing popular achievements";
  248. break;
  249. }
  250. case "/walkthroughs.aspx": {
  251. presenceData.details =
  252. "Viewing Xbox Walkthroughs and Guides";
  253. break;
  254. }
  255. case "/reviews.aspx": {
  256. presenceData.details = "Viewing user reviews";
  257. break;
  258. }
  259. case "/gamereleases.aspx": {
  260. presenceData.details = "Viewing upcoming releases";
  261. break;
  262. }
  263. case "/searchresults.aspx": {
  264. presenceData.details = "Searching for:";
  265. presenceData.state =
  266. document.querySelector<HTMLInputElement>(
  267. "#txtSearchFor"
  268. ).value;
  269. presenceData.smallImageKey = Assets.Search;
  270. break;
  271. }
  272. default:
  273. if (document.location.pathname.includes("/products")) {
  274. if (document.location.pathname.includes("/latest"))
  275. presenceData.details = "Viewing the latest products";
  276. else if (
  277. document.location.pathname.includes("/xbox-sales")
  278. )
  279. presenceData.details = "Viewing Xbox sales";
  280. else if (document.querySelector(".pagetitle")) {
  281. presenceData.details = "Viewing prices for:";
  282. presenceData.state = document
  283. .querySelector(".pagetitle")
  284. .textContent.replace("Best price for ", "")
  285. .trim();
  286. }
  287. } else if (document.location.pathname.includes("/forum/")) {
  288. presenceData.smallImageKey = Assets.Reading;
  289. if (
  290. document.location.pathname.includes("/viewthreads.aspx")
  291. ) {
  292. presenceData.details =
  293. "Forums - Viewing their recent threads";
  294. } else if (
  295. document.location.pathname.includes("/forums.aspx")
  296. )
  297. presenceData.details = "Browsing the forums...";
  298. else if (
  299. document.location.pathname.includes("/viewboard.aspx")
  300. ) {
  301. presenceData.details = "Forums - Viewing board:";
  302. presenceData.state =
  303. document.querySelector(".pagetitle").textContent;
  304. } else if (
  305. document.location.pathname.includes("/newthreads.aspx")
  306. )
  307. presenceData.details = "Forums - Viewing new threads";
  308. else if (
  309. document.location.pathname.includes("/viewthread.aspx")
  310. ) {
  311. presenceData.details = "Forums - Reading thread:";
  312. presenceData.state = document.querySelector(
  313. "#oMessageThread > div:nth-child(2) > h1"
  314. ).textContent;
  315. } else if (
  316. document.location.pathname.includes("/search.aspx")
  317. ) {
  318. presenceData.details = "Forums - Searching for:";
  319. presenceData.state =
  320. document.querySelector<HTMLInputElement>(
  321. "#txtSearchFor"
  322. ).value;
  323. presenceData.smallImageKey = Assets.Search;
  324. }
  325. } else if (
  326. document.location.pathname.includes("/leaderboard")
  327. )
  328. presenceData.details = "Viewing the leaderboards";
  329. else if (
  330. document.location.pathname.includes(
  331. "/userleaderboards.aspx"
  332. )
  333. ) {
  334. presenceData.details =
  335. "Viewing user created leaderboards";
  336. } else if (
  337. document.location.pathname.includes("/TAPlaylist")
  338. ) {
  339. if (document.location.pathname.includes("/forum")) {
  340. presenceData.details =
  341. "Viewing TA Playlist forum posts";
  342. } else if (document.location.pathname.includes("/stats"))
  343. presenceData.details = "Viewing TA Playlist statistics";
  344. else if (document.location.pathname.includes("/clips"))
  345. presenceData.details = "Viewing TA Playlist clips";
  346. else if (document.location.pathname.includes("/history"))
  347. presenceData.details = "Viewing TA Playlist history";
  348. else if (
  349. document.querySelector(
  350. ".community-playlist > div.header > div > h1"
  351. ) !== null
  352. ) {
  353. presenceData.details = "Viewing:";
  354. presenceData.state = document.querySelector(
  355. ".community-playlist > div.header > div > h1"
  356. ).textContent;
  357. } else presenceData.details = "TA Playlist - Browsing...";
  358. } else if (document.location.pathname === "/")
  359. presenceData.details = "Browsing...";
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. if (presenceData.details) presence.setActivity(presenceData);
  367. else presence.setActivity();
  368. });