presence.ts 1.1 KB

1234567891011121314151617181920212223242526272829
  1. const presence = new Presence({
  2. clientId: "613393646330576931",
  3. });
  4. presence.on("UpdateData", async () => {
  5. const presenceData: PresenceData = {
  6. largeImageKey:
  7. "https://cdn.rcd.gg/PreMiD/websites/N/NPM%20Package%20Registry/assets/logo.png",
  8. };
  9. if (document.location.pathname === "/")
  10. presenceData.details = "Viewing the homepage";
  11. else if (document.location.pathname.startsWith("/search")) {
  12. presenceData.details = "Searching...";
  13. presenceData.state = document.location.search.substr(3);
  14. } else if (document.location.pathname.startsWith("/package/")) {
  15. presenceData.details = "Viewing a package";
  16. presenceData.state = "Fetching...";
  17. if (document.location.pathname.split("/").length === 4) {
  18. presenceData.state = `${document.location.pathname.split("/")[2]}/${
  19. document.location.pathname.split("/")[3]
  20. }`;
  21. } else presenceData.state = document.location.pathname.split("/")[2];
  22. } else if (document.location.pathname.startsWith("/~")) {
  23. presenceData.details = "Viewing a profile...";
  24. presenceData.state = document.location.pathname.substr(3);
  25. }
  26. presence.setActivity(presenceData);
  27. });