presence.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const presence = new Presence({ clientId: "898448802829189172" }),
  2. browsingTimestamp = Math.floor(Date.now() / 1000);
  3. presence.on("UpdateData", async () => {
  4. const presenceData: PresenceData = {
  5. largeImageKey:
  6. "https://cdn.rcd.gg/PreMiD/websites/M/Minehut/assets/logo.png",
  7. startTimestamp: browsingTimestamp,
  8. },
  9. f = document.location.pathname.split("/");
  10. if (document.location.hostname === "minehut.com") {
  11. presenceData.details = "Dashboard";
  12. presenceData.state = "On the dashboard";
  13. if (document.location.pathname.includes("/dashboard")) {
  14. const serverName = document.querySelector(
  15. "#app > div > div.dash-div.fill-height > main > div > div.dash-div.fill-height > div > section > div:nth-child(2) > div.container.container--fluid > div > div > div.row.flex-nowrap > div > div > div > div > div.sc-side.d-flex.flex-column.justify-space-between.align-center.flex-direction-center.col-sm.col-xl-3.col-12 > div > div:nth-child(1) > div"
  16. );
  17. if (serverName) presenceData.state = `Editing ${serverName.textContent}`;
  18. }
  19. if (document.location.pathname.includes("/servers"))
  20. presenceData.state = "Viewing the servers";
  21. } else if (document.location.hostname === "shop.minehut.com") {
  22. const rd = document.querySelector(
  23. "body > div.page > div.container > div > h1"
  24. ),
  25. ok = rd ? !rd.textContent.includes("404") : true;
  26. presenceData.details = "Market";
  27. presenceData.state = "Viewing the Market";
  28. if (document.location.pathname.includes("/collections/") && ok) {
  29. const c = f[f.indexOf("collections") + 1];
  30. if (c) {
  31. presenceData.state = `Viewing collection ${c}`;
  32. presenceData.buttons = [
  33. {
  34. label: `View ${c}`,
  35. url: location.origin + location.pathname,
  36. },
  37. ];
  38. }
  39. }
  40. if (document.location.pathname.includes("/products/") && ok) {
  41. const p = f[f.indexOf("products") + 1];
  42. if (p) {
  43. presenceData.state = `Viewing product ${p}`;
  44. presenceData.buttons = [
  45. {
  46. label: `View ${p}`,
  47. url: location.origin + location.pathname,
  48. },
  49. ];
  50. }
  51. }
  52. if (document.location.pathname.includes("/cart")) {
  53. const priceA = document.querySelector(
  54. "#shopify-section-cart--template > section > div > form > div.cart__footer > div.cart__footer-right > p > span"
  55. );
  56. presenceData.state = `Viewing cart${
  57. priceA ? ` (${priceA.textContent} credits)` : ""
  58. }`;
  59. }
  60. if (document.location.pathname.includes("/pages/wishlist"))
  61. presenceData.state = "Viewing wishlist";
  62. if (document.location.pathname.includes("/search")) {
  63. const s = new URLSearchParams(document.location.search.substring(1)).get(
  64. "q"
  65. );
  66. if (s) {
  67. presenceData.state = `Searching for ${s}...`;
  68. presenceData.smallImageKey = Assets.Search;
  69. presenceData.smallImageText = "Searching...";
  70. }
  71. }
  72. }
  73. if (presenceData.details) presence.setActivity(presenceData);
  74. else presence.setActivity();
  75. });