presence.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. const presence = new Presence({
  2. clientId: "850295838361649153",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. const enum Assets {
  6. Logo = "https://cdn.rcd.gg/PreMiD/websites/B/Backpack.tf/assets/logo.png",
  7. }
  8. presence.on("UpdateData", async () => {
  9. const presenceData: PresenceData = {
  10. largeImageKey: Assets.Logo,
  11. startTimestamp: browsingTimestamp,
  12. };
  13. if (document.location.pathname === "/")
  14. presenceData.details = "Viewing Main page";
  15. else if (document.location.pathname.includes("/overview/")) {
  16. presenceData.largeImageKey = (
  17. document.querySelector(
  18. "head > meta[property='og:image']"
  19. ) as HTMLMetaElement
  20. ).content;
  21. presenceData.smallImageKey = Assets.Logo;
  22. presenceData.details = "Viewing item stats:";
  23. presenceData.state = (
  24. document.querySelector(
  25. "#page-content > div:nth-child(1) > div.stats-body > div > h1"
  26. ) as HTMLHeadingElement
  27. ).textContent;
  28. presenceData.buttons = [
  29. {
  30. label: "View the Stats",
  31. url: document.URL,
  32. },
  33. ];
  34. } else if (document.location.pathname.includes("/stats/")) {
  35. if (
  36. document.location.pathname.includes(
  37. "Unique/Mann%20Co.%20Supply%20Crate%20Key"
  38. )
  39. ) {
  40. presenceData.details = "Viewing Key price:";
  41. presenceData.state = `${
  42. (
  43. document.querySelector(
  44. "#page-content > div.row > div.col-md-8.stats-panel.stats-header-panel > div.stats-body > div.stats-subheader > div.price-boxes > a:nth-child(1) > div.text > div.textContent"
  45. ) as HTMLDivElement
  46. ).textContent
  47. } | ${
  48. (
  49. document.querySelector(
  50. "#page-content > div.row > div.col-md-8.stats-panel.stats-header-panel > div.stats-body > div.stats-subheader > div.price-boxes > a:nth-child(2) > div.text > div.textContent"
  51. ) as HTMLDivElement
  52. ).textContent
  53. }`;
  54. } else if (document.location.pathname.includes("Unique/Earbuds")) {
  55. presenceData.details = "Viewing Earbuds price:";
  56. presenceData.state = `${
  57. (
  58. document.querySelector(
  59. "#page-content > div.row > div.col-md-8.stats-panel.stats-header-panel > div.stats-body > div.stats-subheader > div.price-boxes > a:nth-child(1) > div.text > div.textContent"
  60. ) as HTMLDivElement
  61. ).textContent
  62. } | ${
  63. (
  64. document.querySelector(
  65. "#page-content > div.row > div.col-md-8.stats-panel.stats-header-panel > div.stats-body > div.stats-subheader > div.price-boxes > a:nth-child(2) > div.text > div.textContent"
  66. ) as HTMLDivElement
  67. ).textContent
  68. }`;
  69. } else if (document.location.pathname === "/stats") {
  70. presenceData.details = "Browsing through:";
  71. presenceData.state = "Team Fortress 2 Items";
  72. } else {
  73. presenceData.details = "Viewing item:";
  74. presenceData.smallImageKey = Assets.Logo;
  75. presenceData.smallImageText = "Backpack.tf Item stats";
  76. presenceData.largeImageKey = (
  77. document.querySelector(
  78. "head > meta[property='og:image']"
  79. ) as HTMLMetaElement
  80. ).content;
  81. presenceData.buttons = [
  82. {
  83. label: "View the Item",
  84. url: document.URL,
  85. },
  86. ];
  87. presenceData.state = (
  88. document.querySelector(
  89. "#page-content > div.row > div.col-md-8.stats-panel.stats-header-panel > div.stats-body > div.stats-header > div.stats-header-item > div.stats-header-title"
  90. ) as HTMLDivElement
  91. ).textContent;
  92. }
  93. } else if (document.location.pathname.includes("/category")) {
  94. presenceData.details = "Browsing through Team Fortress 2 Items";
  95. if (document.location.pathname === "/category/slots")
  96. presenceData.state = "Items by Slot";
  97. else if (document.location.pathname.includes("/slot/")) {
  98. presenceData.details = "Viewing item:";
  99. presenceData.state = document.querySelector(
  100. "#page-content > div > div.stats-body > div.stats-header > p"
  101. ).textContent;
  102. } else if (document.location.pathname === "/category/classes")
  103. presenceData.state = "Items by Class";
  104. else if (document.location.pathname.includes("/class/")) {
  105. presenceData.details = "Viewing item:";
  106. presenceData.state = document.querySelector(
  107. "#page-content > div > div.stats-body > div.stats-header > p"
  108. ).textContent;
  109. } else presenceData.details = "This page doesn't exist you know :/";
  110. } else if (document.location.pathname.includes("/u/")) {
  111. presenceData.details = "Viewing a profile page:";
  112. presenceData.smallImageKey = Assets.Logo;
  113. presenceData.largeImageKey = (
  114. document.querySelector(
  115. "#page-content > div.panel.panel-main.user-panel- > div.panel-body > div > div.information > div.avatar-container > a > img"
  116. ) as HTMLImageElement
  117. ).src;
  118. presenceData.state = (
  119. document.querySelector(
  120. "head > meta[property='og:title']"
  121. ) as HTMLMetaElement
  122. ).content;
  123. presenceData.buttons = [
  124. {
  125. label: "View the Profile",
  126. url: document.URL,
  127. },
  128. ];
  129. } else if (document.location.pathname.includes("/profiles/")) {
  130. presenceData.details = "Viewing a profile page:";
  131. presenceData.smallImageKey = Assets.Logo;
  132. presenceData.largeImageKey = (
  133. document.querySelector(
  134. "#page-content > div.panel.panel-main.user-panel- > div.panel-body > div > div.information > div.avatar-container > a > img"
  135. ) as HTMLImageElement
  136. ).src;
  137. presenceData.state = (
  138. document.querySelector(
  139. "head > meta[property='og:title']"
  140. ) as HTMLMetaElement
  141. ).content;
  142. presenceData.buttons = [
  143. {
  144. label: "View the Profile",
  145. url: document.URL,
  146. },
  147. ];
  148. } else if (document.location.pathname.includes("/friends/")) {
  149. presenceData.details = "Viewing a profile page:";
  150. presenceData.smallImageKey = Assets.Logo;
  151. presenceData.largeImageKey = (
  152. document.querySelector(
  153. "#page-content > div.panel.panel-main.user-panel- > div.panel-body > div > div.information > div.avatar-container > a > img"
  154. ) as HTMLImageElement
  155. ).src;
  156. presenceData.state = (
  157. document.querySelector(
  158. "head > meta[property='og:title']"
  159. ) as HTMLMetaElement
  160. ).content;
  161. presenceData.buttons = [
  162. {
  163. label: "View the Profile",
  164. url: document.URL,
  165. },
  166. ];
  167. } else if (document.location.pathname.includes("/unusual/")) {
  168. presenceData.details = "Viewing Unusual Pricelist:";
  169. presenceData.state = (
  170. document.querySelector("head > title") as HTMLHeadElement
  171. ).textContent;
  172. } else if (document.location.pathname.includes("/effect/")) {
  173. presenceData.details = "Viewing Unusual Effects Pricelist:";
  174. presenceData.state = (
  175. document.querySelector("head > title") as HTMLHeadElement
  176. ).textContent;
  177. } else if (document.location.pathname.includes("/item/")) {
  178. presenceData.details = `Viewing ${
  179. (
  180. document.querySelector(
  181. "#page-content > div > div > div > div.panel-heading > span:nth-child(1)"
  182. ) as HTMLSpanElement
  183. ).textContent
  184. }:`;
  185. presenceData.state = (
  186. document.querySelector(
  187. "#page-content > div > div > div > div.panel-body > div > div.item-wrapper > div.item-text > h2"
  188. ) as HTMLHeadingElement
  189. ).textContent;
  190. } else if (document.location.pathname.includes("/settings")) {
  191. presenceData.details = "Viewing a page:";
  192. presenceData.state = "Settings";
  193. } else if (document.location.pathname.includes("/alerts")) {
  194. presenceData.details = "Viewing a page:";
  195. presenceData.state = "Alerts";
  196. } else if (document.location.pathname.includes("/notifications")) {
  197. presenceData.details = "Viewing a page:";
  198. presenceData.state = "Notifications";
  199. } else if (document.location.pathname.includes("/connections")) {
  200. presenceData.details = "Viewing a page:";
  201. presenceData.state = "Connections";
  202. } else if (document.location.pathname.includes("/payments")) {
  203. presenceData.details = "Viewing a page:";
  204. presenceData.state = "Payment History";
  205. } else if (document.location.pathname.includes("/award-tickets")) {
  206. presenceData.details = "Viewing a page:";
  207. presenceData.state = "Tickets";
  208. } else if (document.location.pathname.includes("/donate"))
  209. presenceData.details = "Viewing Donation page";
  210. else if (document.location.pathname.includes("/premium/subscribe"))
  211. presenceData.details = "Viewing Premium subscription";
  212. else if (document.location.pathname.includes("/premium/search"))
  213. presenceData.details = "Using the Premium Search";
  214. else if (document.location.pathname.includes("/pricelist")) {
  215. presenceData.details = "Viewing Community Pricelist";
  216. presenceData.state = "Pricegrid view";
  217. } else if (document.location.pathname.includes("/spreadsheet")) {
  218. presenceData.details = "Viewing Community Pricelist";
  219. presenceData.state = "Spreadsheet view";
  220. } else if (document.location.pathname.includes("/vote"))
  221. presenceData.details = "Browsing Suggestions";
  222. else if (document.location.pathname.includes("/latest"))
  223. presenceData.details = "Viewing the Latest Price Updates";
  224. else if (document.location.pathname.includes("/unusuals")) {
  225. presenceData.details = "Viewing Unusual Pricelist";
  226. presenceData.state = "Browsing by Item";
  227. } else if (document.location.pathname.includes("/effects")) {
  228. presenceData.details = "Viewing Unusual Pricelist";
  229. presenceData.state = "Browse by Effect";
  230. } else if (document.location.pathname.includes("/market")) {
  231. presenceData.details = "Searching through:";
  232. presenceData.state = "Steam Community Market Pricelist";
  233. } else if (document.location.pathname.includes("/classifieds")) {
  234. presenceData.details = "Searching through:";
  235. presenceData.state = "Classified Listings";
  236. presenceData.buttons = [
  237. {
  238. label: "View the Classifieds",
  239. url: document.URL,
  240. },
  241. ];
  242. } else if (document.location.pathname.includes("/suggestion/")) {
  243. presenceData.details = "Searching through:";
  244. presenceData.state = "Price Suggestions";
  245. presenceData.buttons = [
  246. {
  247. label: "View the Suggestions",
  248. url: document.URL,
  249. },
  250. ];
  251. } else if (document.location.pathname.includes("/about")) {
  252. presenceData.details = "Viewing page:";
  253. presenceData.state = "About backpack.tf";
  254. } else if (document.location.pathname.includes("/issues")) {
  255. presenceData.details = "Viewing page:";
  256. presenceData.state = "Issue tracker";
  257. } else if (document.location.pathname.includes("/calculator"))
  258. presenceData.details = "Useing Calculator";
  259. else if (document.location.pathname.includes("/top/backpacks"))
  260. presenceData.details = "Viewing Top Backpacks";
  261. else if (document.location.pathname.includes("/top/donators"))
  262. presenceData.details = "Viewing Top Donators";
  263. else if (document.location.pathname.includes("/top/generous"))
  264. presenceData.details = "Viewing Top Gifters";
  265. else if (document.location.pathname.includes("/top/contributors"))
  266. presenceData.details = "Viewing Top Contributors";
  267. else if (document.location.pathname.includes("/developer"))
  268. presenceData.details = "Viewing Develoapers page";
  269. else if (document.location.pathname.includes("/help"))
  270. presenceData.details = "Viewing help center";
  271. else if (document.location.pathname.includes("/rules"))
  272. presenceData.details = "Reading rules";
  273. else if (document.location.pathname.includes("/servers"))
  274. presenceData.details = "Viewing servers with backpack.tf plugin";
  275. else if (document.location.pathname.includes("/top/accurate"))
  276. presenceData.details = "Viewing The Most Accurate Users";
  277. if (presenceData.details) presence.setActivity(presenceData);
  278. else presence.setActivity();
  279. });