presence.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const enum Assets {
  2. Logo = "https://cdn.rcd.gg/PreMiD/websites/V/v0/assets/logo.png",
  3. }
  4. const presence = new Presence({ clientId: "1160993221854380132" }),
  5. presenceData: PresenceData = {
  6. largeImageKey: Assets.Logo,
  7. startTimestamp: Math.floor(Date.now() / 1000),
  8. };
  9. presence.on("UpdateData", async () => {
  10. switch (
  11. document.location.pathname.endsWith("/") &&
  12. document.location.pathname.length > 1
  13. ? document.location.pathname.slice(
  14. 0,
  15. document.location.pathname.length - 1
  16. )
  17. : document.location.pathname
  18. ) {
  19. case "/":
  20. presenceData.details = "Viewing homepage";
  21. presenceData.largeImageKey = Assets.Logo;
  22. delete presenceData.smallImageKey;
  23. break;
  24. case `/r/${document.location.pathname.split("/")[2]}`:
  25. presenceData.details = "Prompting a template";
  26. presenceData.state = `User prompt: "${document
  27. .querySelector("span.text-sm.line-clamp-1.text-ellipsis.text-left")
  28. .textContent.slice(0, 50)}"`;
  29. delete presenceData.buttons;
  30. break;
  31. case `/t/${document.location.pathname.split("/")[2]}`:
  32. presenceData.details = `Viewing a template by @${
  33. document
  34. .querySelector<HTMLAnchorElement>("a.flex-none")
  35. .href.split("/")[3]
  36. }`;
  37. presenceData.state = `"${document
  38. .querySelector(
  39. "h1.md\\:max-w-xs.lg\\:max-w-sm.text-sm.line-clamp-1.text-ellipsis.animate-in.fade-in-5.text-gray-1000"
  40. )
  41. .textContent.slice(0, 50)}"`;
  42. presenceData.buttons = [
  43. {
  44. label: "View template",
  45. url: document.location.href,
  46. },
  47. ];
  48. break;
  49. case `/${document.location.pathname.split("/")[1]}`:
  50. presenceData.details = `Viewing @${
  51. document.location.pathname.split("/")[1]
  52. } profile`;
  53. presenceData.largeImageKey = document.querySelector<HTMLImageElement>(
  54. "img.rounded-full.h-12.w-12"
  55. ).src;
  56. presenceData.smallImageKey = Assets.Logo;
  57. presenceData.buttons = [
  58. {
  59. label: "View profile",
  60. url: document.location.href,
  61. },
  62. ];
  63. break;
  64. }
  65. presence.setActivity(presenceData);
  66. });