presence.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const presence = new Presence({
  2. clientId: "630570838084812801",
  3. });
  4. const enum Assets {
  5. Logo = "https://cdn.rcd.gg/PreMiD/websites/W/wikiHow/assets/logo.png",
  6. }
  7. presence.on("UpdateData", async () => {
  8. const path = document.location.pathname,
  9. topic = document.querySelector("#section_0"),
  10. category = document.querySelector("#article > div.wh_block > h1");
  11. if (topic && topic.textContent !== "") {
  12. const author =
  13. document.querySelector("#sp_expert_name") ||
  14. document.querySelector("#sp_expert_team"),
  15. date = document.querySelector("#expert_coauthor > p");
  16. return presence.setActivity({
  17. details: topic.textContent,
  18. state: `by ${
  19. author && author.textContent !== "" ? author.textContent : "unknown"
  20. }${
  21. date && date.textContent !== ""
  22. ? ` (${date.textContent.replace("Updated: ", "")})`
  23. : ""
  24. } `,
  25. largeImageKey: Assets.Logo,
  26. smallImageKey: Assets.Logo,
  27. smallImageText: decodeURIComponent(document.location.href),
  28. startTimestamp: Math.floor(Date.now() / 1000),
  29. });
  30. }
  31. if (category && category.textContent !== "") {
  32. return presence.setActivity({
  33. details: "Viewing a category:",
  34. state: category.textContent,
  35. largeImageKey:
  36. "https://cdn.rcd.gg/PreMiD/websites/W/wikiHow/assets/logo.png",
  37. smallImageKey: Assets.Logo,
  38. smallImageText: decodeURIComponent(document.location.href),
  39. startTimestamp: Math.floor(Date.now() / 1000),
  40. });
  41. }
  42. if (path === "/index.php") {
  43. // Note that I (EGGSY) didn't work on this part, I don't know if it's working on the main site but I'm sure it doesn't work on Spanish version.
  44. const newTopic = document.querySelectorAll(".firstHeading")[0]
  45. ? document.querySelectorAll(".firstHeading")[0].textContent
  46. : null;
  47. return presence.setActivity({
  48. details: "Editing/Writing How to",
  49. state: `Topic: ${newTopic ?? "Unknown."} `,
  50. largeImageKey:
  51. "https://cdn.rcd.gg/PreMiD/websites/W/wikiHow/assets/logo.png",
  52. smallImageKey: Assets.Logo,
  53. smallImageText: decodeURIComponent(document.location.href),
  54. startTimestamp: Math.floor(Date.now() / 1000),
  55. });
  56. }
  57. if (path === "/wikiHowTo") {
  58. const searching = document.location.search
  59. .replace("?search=", "")
  60. .split("+")
  61. .join(" ");
  62. return presence.setActivity({
  63. details: "Searching for:",
  64. state: `${searching[0].toUpperCase() + searching.slice(1).toLowerCase()}`,
  65. largeImageKey:
  66. "https://cdn.rcd.gg/PreMiD/websites/W/wikiHow/assets/logo.png",
  67. smallImageKey: Assets.Logo,
  68. smallImageText: "Searching...",
  69. startTimestamp: Math.floor(Date.now() / 1000),
  70. });
  71. }
  72. return presence.setActivity({
  73. details: "Viewing a page:",
  74. state: "Homepage",
  75. largeImageKey:
  76. "https://cdn.rcd.gg/PreMiD/websites/W/wikiHow/assets/logo.png",
  77. smallImageKey: Assets.Logo,
  78. startTimestamp: Math.floor(Date.now() / 1000),
  79. });
  80. });