presence.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const presence = new Presence({
  2. clientId: "634032819915456552",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. let user: HTMLElement, title: HTMLElement, search: HTMLInputElement;
  6. presence.on("UpdateData", async () => {
  7. const presenceData: PresenceData = {
  8. largeImageKey: "https://cdn.rcd.gg/PreMiD/websites/H/HLTV/assets/logo.png",
  9. };
  10. if (document.location.hostname === "www.hltv.org") {
  11. presenceData.startTimestamp = browsingTimestamp;
  12. if (document.location.pathname.includes("/news/")) {
  13. presenceData.details = "Reading news post:";
  14. title = document.querySelector(
  15. "body > div.bgPadding > div > div.colCon > div.contentCol > article > h1"
  16. );
  17. presenceData.state = title.textContent;
  18. presenceData.smallImageKey = Assets.Reading;
  19. } else if (document.location.pathname.includes("/profile/")) {
  20. title = document.querySelector(
  21. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div.top-info > div > div.info.col > div.headline"
  22. );
  23. presenceData.details = "Viewing profile:";
  24. presenceData.state = title.textContent;
  25. } else if (document.location.pathname.includes("/forums/")) {
  26. if (document.location.pathname.includes("/threads/")) {
  27. title = document.querySelector(
  28. "body > div.bgPadding > div > div.colCon > div.contentCol > div.forumthread > div.standard-box > div.forum-topbar > div.topic"
  29. );
  30. presenceData.details = "Reading forum thread:";
  31. presenceData.state = title.textContent;
  32. presenceData.smallImageKey = Assets.Reading;
  33. } else {
  34. title = document.querySelector(
  35. "body > div.bgPadding > div > div.colCon > div.contentCol > div > span:nth-child(2)"
  36. );
  37. presenceData.details = "Viewing forums category:";
  38. presenceData.state = title.textContent;
  39. }
  40. } else if (document.location.pathname.includes("/forums"))
  41. presenceData.details = "Browsing the forums";
  42. else if (document.location.pathname.includes("/matches/")) {
  43. presenceData.details = "Viewing match:";
  44. title = document.querySelector("head > title");
  45. presenceData.state = title.textContent.replace(" | HLTV.org", "");
  46. } else if (document.location.pathname.includes("/matches"))
  47. presenceData.details = "Viewing the recent matches";
  48. else if (document.location.pathname.includes("/results"))
  49. presenceData.details = "Viewing the results";
  50. else if (document.location.pathname.includes("/events/")) {
  51. presenceData.details = "Viewing event:";
  52. title = document.querySelector(
  53. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div.event-header-component.event-holder.header > a > div > div"
  54. );
  55. presenceData.state = title.textContent;
  56. } else if (document.location.pathname.includes("/events"))
  57. presenceData.details = "Viewing list of events";
  58. else if (document.location.pathname.includes("/player/")) {
  59. title = document.querySelector(
  60. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div.standard-box.profileTopBox.clearfix.flex > div.profile-info-container > div.profile-player-info-container > div.profile-player-info > h1"
  61. );
  62. presenceData.details = "Viewing player:";
  63. presenceData.state = title.textContent;
  64. } else if (document.location.pathname.includes("/team/")) {
  65. title = document.querySelector(
  66. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div.standard-box.profileTopBox.clearfix > div.flex > div.profile-team-container.text-ellipsis > div.profile-team-info > div.profile-team-name.text-ellipsis"
  67. );
  68. presenceData.details = "Viewing team:";
  69. presenceData.state = title.textContent;
  70. } else if (document.location.pathname.includes("/stats/")) {
  71. presenceData.details = "Viewing stats of:";
  72. title = document.querySelector(
  73. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div.playerSummaryStatBox > div.summaryBreakdownContainer > div.summaryShortInfo > h1"
  74. );
  75. presenceData.state = title.textContent;
  76. } else if (document.location.pathname.includes("/stats"))
  77. presenceData.details = "Viewing the stats";
  78. else if (document.location.pathname.includes("/gallery/")) {
  79. presenceData.details = "Viewing gallery:";
  80. title = document.querySelector(
  81. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div.event-header-component.event-holder.header > a > div > div"
  82. );
  83. presenceData.state = title.textContent;
  84. } else if (document.location.pathname.includes("/galleries"))
  85. presenceData.details = "Browsing galleries";
  86. else if (document.location.pathname.includes("/betting"))
  87. presenceData.details = "Viewing betting";
  88. else if (document.location.pathname.includes("/live")) {
  89. title = document.querySelector(
  90. "#LiveApplication > div > div.stats-container.gtSmartphone-only > div > div.team1-stats > div.team.text-ellipsis > span"
  91. );
  92. user = document.querySelector(
  93. "#LiveApplication > div > div.stats-container.gtSmartphone-only > div > div.team2-stats > div.team.text-ellipsis > span"
  94. );
  95. presenceData.details = "Watching live match:";
  96. presenceData.state = `${title.textContent} vs. ${user.textContent}`;
  97. presenceData.smallImageKey = Assets.Live;
  98. } else if (document.location.pathname.includes("/fantasy/")) {
  99. presenceData.details = "Viewing fantasy of:";
  100. title = document.querySelector(
  101. "#fantasy > div > div.fantasy-content > div > div.eventBarFragment > div.countdownContainer > div > div.textBox > h1"
  102. );
  103. presenceData.state = title.textContent;
  104. } else if (document.location.pathname.includes("/fantasy"))
  105. presenceData.details = "Browsing fantasy";
  106. else if (document.location.pathname.includes("/search")) {
  107. search = document.querySelector(
  108. "body > div.bgPadding > div > div.colCon > div.contentCol > div > div:nth-child(2) > div > form > input.searchInput"
  109. );
  110. presenceData.details = "Searching for:";
  111. presenceData.state = search.value;
  112. presenceData.smallImageKey = Assets.Search;
  113. }
  114. }
  115. if (presenceData.details) presence.setActivity(presenceData);
  116. else presence.setActivity();
  117. });