presence.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const presence = new Presence({
  2. clientId: "630101652380188692",
  3. });
  4. presence.on("UpdateData", () => {
  5. const presenceData: PresenceData = {
  6. largeImageKey:
  7. "https://cdn.rcd.gg/PreMiD/websites/G/Glitch/assets/logo.png",
  8. };
  9. if (window.location.href.includes(".glitch.me")) {
  10. presenceData.details = "Viewing a webpage";
  11. presenceData.state = window.location.hostname;
  12. } else if (window.location.href.includes("status.glitch.com"))
  13. presenceData.details = "https://status.glitch.com";
  14. else if (window.location.href.includes("support.glitch.com")) {
  15. if (window.location.pathname.toLowerCase() === "/") {
  16. presenceData.details = "Viewing support topics";
  17. presenceData.state = "Latest topics";
  18. } else if (window.location.pathname.toLowerCase() === "/latest") {
  19. presenceData.details = "Viewing support topics";
  20. presenceData.state = "Latest topics";
  21. } else if (window.location.pathname.toLowerCase() === "/new") {
  22. presenceData.details = "Viewing support topics";
  23. presenceData.state = "New topics";
  24. } else if (window.location.pathname.toLowerCase() === "/unread") {
  25. presenceData.details = "Viewing support topics";
  26. presenceData.state = "Unread topics";
  27. } else if (window.location.pathname.toLowerCase() === "/top") {
  28. presenceData.details = "Viewing support topics";
  29. presenceData.state = "Top topics";
  30. } else if (window.location.pathname.toLowerCase() === "/categories") {
  31. presenceData.details = "Viewing support topics";
  32. presenceData.state = "Categories";
  33. } else if (
  34. window.location.href.toLowerCase().includes("support.glitch.com/t/")
  35. ) {
  36. presenceData.details = "Viewing a topic:";
  37. presenceData.state = document.title;
  38. } else if (
  39. window.location.href.toLowerCase().includes("support.glitch.com/u/")
  40. ) {
  41. presenceData.details = "Viewing a user profile:";
  42. presenceData.state = document.querySelector(
  43. "body > section > div > div > div > section > section > div > div > div > div > h2 "
  44. ).textContent;
  45. }
  46. } else {
  47. presenceData.details = "Viewing a page:";
  48. if (window.location.pathname.toLowerCase() === "/")
  49. presenceData.state = "Homepage";
  50. else if (window.location.pathname.toLowerCase().includes("/questions")) {
  51. presenceData.details = "Viewing a page:";
  52. presenceData.state = "Questions";
  53. } else if (window.location.pathname.toLowerCase().includes("/create")) {
  54. presenceData.details = "Viewing a page:";
  55. presenceData.state = "Create";
  56. } else if (window.location.pathname.toLowerCase().includes("/about")) {
  57. presenceData.details = "Viewing a page:";
  58. presenceData.state = "About";
  59. } else if (window.location.pathname.toLowerCase().includes("/culture")) {
  60. presenceData.details = "Viewing a page:";
  61. presenceData.state = "Blog & Culture";
  62. } else if (window.location.pathname.toLowerCase().includes("/help")) {
  63. presenceData.details = "Viewing a page:";
  64. presenceData.state = "Help & FAQ";
  65. } else if (window.location.pathname.toLowerCase().includes("/legal")) {
  66. presenceData.details = "Viewing a page:";
  67. presenceData.state = "Legal";
  68. } else if (window.location.pathname.toLowerCase().includes("edit")) {
  69. presenceData.details = "Editing a project:";
  70. presenceData.state = document.querySelector(
  71. "body > div > div > header > nav > button > div > span"
  72. ).textContent;
  73. } else if (window.location.pathname.toLowerCase().includes("~")) {
  74. presenceData.details = "Viewing a project:";
  75. presenceData.state = window.location.pathname.replace("/", "");
  76. } else if (window.location.pathname.toLowerCase().includes("@")) {
  77. presenceData.details = "Viewing a team or user:";
  78. presenceData.state = window.location.pathname.replace("/", "");
  79. } else delete presenceData.details;
  80. }
  81. if (presenceData.details) presence.setActivity(presenceData);
  82. else presence.setActivity();
  83. });