presence.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const presence = new Presence({
  2. clientId: "670612134878773297",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. presence.on("UpdateData", () => {
  6. const presenceData: PresenceData = {
  7. largeImageKey: "https://cdn.rcd.gg/PreMiD/websites/C/Canva/assets/logo.png",
  8. startTimestamp: browsingTimestamp,
  9. };
  10. if (document.location.pathname === "/")
  11. presenceData.details = "In the Homepage";
  12. else if (document.location.pathname.startsWith("/folder")) {
  13. if (document.location.pathname.startsWith("/folder/all-designs"))
  14. presenceData.details = "Browsing his designs";
  15. else if (document.location.pathname.startsWith("/folder/uploads")) {
  16. presenceData.details = "Browsing the photos he";
  17. presenceData.state = "uploaded";
  18. } else if (document.location.pathname.startsWith("/folder/purchased")) {
  19. presenceData.details = "Browsing the photos he";
  20. presenceData.state = "purchased";
  21. } else if (document.location.pathname.startsWith("/folder/likes")) {
  22. presenceData.details = "Browsing the photos he";
  23. presenceData.state = "likes";
  24. } else if (document.location.pathname.startsWith("/folder/shared")) {
  25. presenceData.details = "Browsing the designs and";
  26. presenceData.state = "photos shared with him";
  27. } else if (document.location.pathname.startsWith("/folder/trash"))
  28. presenceData.details = "Browsing the trash";
  29. else if (document.location.pathname === "/folder/")
  30. presenceData.details = "Browsing his folders";
  31. else if (document.location.pathname === "/folder")
  32. presenceData.details = "Browsing the folders";
  33. else {
  34. presenceData.details = "Browsing the folder: ";
  35. presenceData.state = document
  36. .querySelector("head > title")
  37. .textContent.replace(" - Canva", "");
  38. }
  39. } else if (document.location.pathname.startsWith("/templates/")) {
  40. if (document.location.pathname.startsWith("/templates/search/"))
  41. presenceData.details = "Searching templates";
  42. else presenceData.details = "Browsing the templates";
  43. } else if (document.location.pathname.startsWith("/photos/")) {
  44. if (document.location.pathname.startsWith("/photos/search/")) {
  45. presenceData.details = "Searching photos of:";
  46. [presenceData.state] = document
  47. .querySelector("head > title")
  48. .textContent.split(" - ");
  49. } else presenceData.details = "Browsing the photos";
  50. } else if (document.location.pathname.startsWith("/brand"))
  51. presenceData.details = "Editing his brand";
  52. else if (document.location.pathname.startsWith("/teams")) {
  53. if (document.location.pathname.startsWith("/teams/designs"))
  54. presenceData.details = "Browsing the team designs";
  55. else if (document.location.pathname.startsWith("/teams/folders"))
  56. presenceData.details = "Browsing the team folders";
  57. else if (document.location.pathname.startsWith("/teams/members")) {
  58. presenceData.details = "Viewing the team";
  59. presenceData.state = "members";
  60. } else if (document.location.pathname.startsWith("/teams/groups"))
  61. presenceData.details = "Viewing the team groups";
  62. else if (document.location.pathname.startsWith("/teams/create"))
  63. presenceData.details = "Creating a new group";
  64. else presenceData.details = "Browsing the team info";
  65. } else if (document.location.pathname.startsWith("/groups/")) {
  66. if (document.location.pathname.endsWith("/designs")) {
  67. presenceData.details = "Browsing the group";
  68. presenceData.state = "designs";
  69. } else if (document.location.pathname.endsWith("/folders"))
  70. presenceData.details = "Browsing the group folders";
  71. else if (document.location.pathname.endsWith("/members")) {
  72. presenceData.details = "Viewing the group";
  73. presenceData.state = "members";
  74. } else presenceData.details = "Browsing the group info";
  75. } else if (document.location.pathname.startsWith("/account")) {
  76. if (document.location.pathname.startsWith("/account/information"))
  77. presenceData.details = "In the account settings";
  78. else if (document.location.pathname.startsWith("/account/billing"))
  79. presenceData.details = "In the billing settings";
  80. else if (document.location.pathname.startsWith("/account/print-orders"))
  81. presenceData.details = "Viewing his Print Orders";
  82. else presenceData.details = "In the account settings";
  83. } else if (document.location.pathname.startsWith("/rewards"))
  84. presenceData.details = "Inviting friends";
  85. else if (document.location.pathname.startsWith("/design/")) {
  86. if (document.location.pathname.endsWith("/edit")) {
  87. presenceData.details = "Editing the design:";
  88. presenceData.smallImageKey =
  89. "https://cdn.rcd.gg/PreMiD/websites/C/Canva/assets/0.png";
  90. presenceData.smallImageText = "Editing";
  91. presenceData.state = document.querySelector("head > title").textContent;
  92. } else if (document.location.pathname.endsWith("/view")) {
  93. presenceData.details = "Watching the design:";
  94. presenceData.state = document.querySelector("head > title").textContent;
  95. } else presenceData.details = "Viewing a design";
  96. } else presenceData.details = "Browsing...";
  97. if (presenceData.details) presence.setActivity(presenceData);
  98. else presence.setActivity();
  99. });