presence.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const presence = new Presence({
  2. clientId: "648494004870184981",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. let title: string;
  6. presence.on("UpdateData", async () => {
  7. const presenceData: PresenceData = {
  8. largeImageKey:
  9. "https://cdn.rcd.gg/PreMiD/websites/0-9/4gamers/assets/logo.png",
  10. };
  11. if (document.location.hostname === "www.4gamers.com.tw") {
  12. if (document.location.pathname === "/") {
  13. presenceData.startTimestamp = browsingTimestamp;
  14. presenceData.details = "Viewing home page";
  15. } else if (document.location.pathname.includes("/new")) {
  16. title = document.querySelectorAll(".news-header-title")[0].textContent;
  17. presenceData.details = title;
  18. presenceData.state = `Category: ${
  19. document.querySelectorAll(".news-header-category")[0].textContent
  20. }`;
  21. } else if (document.location.pathname.includes("magazine")) {
  22. title = document.querySelectorAll(".magazine-content-title")[0]
  23. .textContent;
  24. presenceData.details = title;
  25. presenceData.state = `Publish Date: ${
  26. document.querySelectorAll(".magazine-content-time")[0].textContent
  27. }`;
  28. } else if (document.location.pathname.includes("tournament"))
  29. presenceData.details = "賽事專欄";
  30. }
  31. if (!presenceData.details) {
  32. presenceData.startTimestamp = browsingTimestamp;
  33. presence.setActivity(presenceData);
  34. } else presence.setActivity(presenceData);
  35. });