presence.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const presence = new Presence({
  2. clientId: "656826806061498368", //The client ID of the Application created at https://discordapp.com/developers/applications
  3. //Enable use and detection of media key presses
  4. }),
  5. presenceData: PresenceData = {
  6. largeImageKey:
  7. "https://cdn.rcd.gg/PreMiD/websites/T/TryHackMe/assets/logo.png",
  8. },
  9. browsingTimestamp = Math.floor(Date.now() / 1000);
  10. let customData = false;
  11. presence.on("UpdateData", async () => {
  12. customData = false;
  13. presenceData.startTimestamp = browsingTimestamp;
  14. if (document.location.pathname === "/dashboard")
  15. presenceData.details = "Viewing the Dashboard!";
  16. else if (document.location.pathname === "/profile")
  17. presenceData.details = "Viewing their profile!";
  18. else if (document.location.pathname.startsWith("/room")) {
  19. const title = document.querySelector<HTMLElement>("#title");
  20. if (title) {
  21. customData = true;
  22. presence.setActivity({
  23. details: "Completing room:",
  24. state: title.textContent,
  25. largeImageKey:
  26. "https://cdn.rcd.gg/PreMiD/websites/T/TryHackMe/assets/logo.png",
  27. startTimestamp: browsingTimestamp,
  28. });
  29. } else presenceData.details = "Looking at rooms!";
  30. } else if (
  31. document.location.pathname === "/upload" ||
  32. document.location.pathname === "/manage-rooms" ||
  33. document.location.pathname.startsWith("/room/manage") ||
  34. document.location.pathname === "/assign-tasks" ||
  35. document.location.pathname === "/your-material"
  36. ) {
  37. presenceData.details = "Managing a room!";
  38. presenceData.state = `Page: ${document.location.pathname}`;
  39. //presenceData.startTimestamp = browsingTimestamp;
  40. } else if (document.location.pathname === "/leaderboards")
  41. presenceData.details = "Checking the leaderboards!";
  42. else presenceData.details = "Breaking stuff!";
  43. if (!customData) presence.setActivity(presenceData);
  44. });