presence.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const presence = new Presence({
  2. clientId: "635213174144237601",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. let title;
  6. const viewString = "Viewing ",
  7. torrentString = "'s torrents";
  8. presence.on("UpdateData", async () => {
  9. const presenceData: PresenceData = {
  10. largeImageKey:
  11. "https://cdn.rcd.gg/PreMiD/websites/N/Nyaa.si/assets/logo.png",
  12. startTimestamp: browsingTimestamp,
  13. };
  14. if (new URLSearchParams(window.location.search).has("q")) {
  15. presenceData.details = "Searching for:";
  16. presenceData.state = document.querySelector("input").value;
  17. presenceData.smallImageKey = Assets.Search;
  18. } else if (document.location.pathname === "/")
  19. presenceData.details = "Viewing home page";
  20. else if (document.location.pathname.includes("/rules")) {
  21. presenceData.smallImageKey = Assets.Reading;
  22. presenceData.details = "Reading the rules";
  23. } else if (document.location.pathname.includes("/help")) {
  24. presenceData.smallImageKey = Assets.Reading;
  25. presenceData.details = "Reading the help section";
  26. } else if (document.location.pathname.includes("/upload")) {
  27. presenceData.smallImageKey = Assets.Uploading;
  28. presenceData.details = "Uploading a torrent";
  29. } else if (document.location.pathname.includes("/view/")) {
  30. presenceData.details = "Viewing torrent:";
  31. title = document.querySelector("h3.panel-title").textContent.trim();
  32. presenceData.state = title;
  33. } else if (document.location.pathname.includes("/user/")) {
  34. presenceData.details =
  35. viewString +
  36. document.querySelector("body > div > div > h3 > span").textContent +
  37. torrentString;
  38. }
  39. if (presenceData.details) presence.setActivity(presenceData);
  40. else presence.setActivity();
  41. });