presence.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const presence = new Presence({
  2. clientId: "800702121866559508",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. const enum Assets {
  6. Logo = "https://cdn.rcd.gg/PreMiD/websites/B/Buienalarm/assets/logo.png",
  7. }
  8. presence.on("UpdateData", async () => {
  9. const presenceData: PresenceData = {
  10. largeImageKey: Assets.Logo,
  11. startTimestamp: browsingTimestamp,
  12. },
  13. { pathname } = document.location,
  14. privacy = await presence.getSetting<number>("privacy");
  15. let locationScript: {
  16. name: string | null;
  17. region: string | null;
  18. country: string | null;
  19. },
  20. locationTitle: string;
  21. if (
  22. document
  23. .querySelector("head")
  24. .childNodes[9]?.textContent.includes('country":')
  25. ) {
  26. locationScript = JSON.parse(
  27. document
  28. .querySelector("head")
  29. .childNodes[9].textContent.replace(/(<!-- {2})|( -->)|( HOST: )/gm, "")
  30. );
  31. } else if (
  32. document
  33. .querySelector("head")
  34. .childNodes[10]?.textContent.includes('country":')
  35. ) {
  36. locationScript = JSON.parse(
  37. document
  38. .querySelector("head")
  39. .childNodes[10].textContent.replace(/(<!-- {2})|( -->)|( HOST: )/gm, "")
  40. );
  41. } else locationScript = null;
  42. const search = document.querySelector<HTMLInputElement>(
  43. '[class="input white-text focus"]'
  44. );
  45. if (search?.value) {
  46. if (privacy === 2) {
  47. presenceData.details = "Zoekt naar";
  48. presenceData.state = search.value;
  49. } else presenceData.details = "Aan het zoeken";
  50. presenceData.smallImageKey = Assets.Search;
  51. } else if (locationScript === null) {
  52. if (pathname === "/") presenceData.details = "Bekijkt de home pagina";
  53. else presenceData.details = "Aan het browsen..";
  54. } else {
  55. locationTitle =
  56. privacy === 0
  57. ? `Een locatie in ${locationScript.country}`
  58. : privacy === 1
  59. ? `Een locatie in ${locationScript.region}`
  60. : privacy === 2
  61. ? locationScript.name
  62. : "Een Privé locatie";
  63. presenceData.state = locationTitle;
  64. presenceData.smallImageKey = document
  65. .querySelector('[class="icon left"]')
  66. .getAttribute("src")
  67. .split("weather/")[1]
  68. .replace(".svg", "")
  69. .toLowerCase();
  70. if (
  71. document.querySelector('[class="ip-btn ip-active"]')?.textContent ??
  72. document.querySelector('[class="ip-btn"]')?.textContent !== "❚❚"
  73. )
  74. presenceData.details = "Bekijkt de weersverwachting voor";
  75. else presenceData.details = "Bekijkt de weersgrafiek voor";
  76. }
  77. if (presenceData.details) presence.setActivity(presenceData);
  78. else presence.setActivity();
  79. });