presence.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const presence = new Presence({
  2. clientId: "1212508565802192936",
  3. });
  4. // Other default assets can be found at index.d.ts
  5. const enum Assets {
  6. Logo = "https://cdn.rcd.gg/PreMiD/websites/L/Library%20of%20Babel/assets/logo.png",
  7. }
  8. const enum Pages {
  9. homepage = "/",
  10. about = "/about.html",
  11. search = "/search.html",
  12. sRes = "/search.cgi",
  13. book = "/book.cgi",
  14. browse = "/browse.cgi",
  15. bookmark = "/bookmark.cgi",
  16. anglishized = "/anglishize.cgi",
  17. theory = "/theory.html",
  18. images = "/slideshow.html",
  19. imgsearch = "/imagesearch.html",
  20. imgSRes = "/imagesearch.cgi",
  21. coloroscopy = "/coloroscopy.html",
  22. refhex = "/referencehex.html",
  23. }
  24. presence.on("UpdateData", async () => {
  25. if (!document.location.toString()) return;
  26. let base = document.location.pathname;
  27. if (base.includes("theory")) base = "/theory.html";
  28. const title = document.title
  29. .replace("Anglishized", "")
  30. .replace("Theory - ", "")
  31. .replace("Image Search: ", ""),
  32. presenceData: PresenceData = {
  33. largeImageKey: Assets.Logo,
  34. largeImageText: "hex802",
  35. name: "Library of Babel",
  36. type: ActivityType.Watching,
  37. },
  38. pageInp = document.querySelector<HTMLInputElement>("#page")?.value;
  39. switch (base) {
  40. case Pages.homepage:
  41. presenceData.details = "In the lobby (home)";
  42. break;
  43. case Pages.about:
  44. presenceData.details = "Learning about the archives";
  45. break;
  46. case Pages.search:
  47. presenceData.details = "Searching through the archives";
  48. break;
  49. case Pages.imgsearch:
  50. presenceData.details = "Searching through the image archives";
  51. break;
  52. case Pages.imgSRes:
  53. presenceData.details = `Viewing image ${title}`;
  54. break;
  55. case Pages.sRes:
  56. {
  57. presenceData.details = "Searching the archives for:";
  58. presenceData.state =
  59. document.querySelector<HTMLTextAreaElement>("#find").value;
  60. }
  61. break;
  62. case Pages.anglishized:
  63. {
  64. presenceData.details = `Reading ${title.replace(
  65. ` ${pageInp}`,
  66. ""
  67. )} (page ${pageInp})`;
  68. presenceData.details = `Reading ${
  69. document.querySelector(".bookcont > h3")?.textContent
  70. } (page ${pageInp}, Anglishized)`;
  71. }
  72. break;
  73. case Pages.book:
  74. case Pages.bookmark:
  75. presenceData.details = `Reading Bookmark ${title.replace(
  76. ` ${pageInp}`,
  77. ""
  78. )}`;
  79. break;
  80. case Pages.browse:
  81. {
  82. presenceData.details = "Browsing the archives";
  83. const hexVal =
  84. document.querySelector<HTMLTextAreaElement>("#hexer")?.value,
  85. wall = document.querySelector<HTMLSelectElement>("#inside1"),
  86. wallVal = wall?.value?.slice(1),
  87. shelf = document.querySelector<HTMLSelectElement>("#inside2"),
  88. shelfVal = shelf?.value?.slice(1),
  89. vol = document.querySelector<HTMLSelectElement>("#inside3"),
  90. volVal = vol?.value?.slice(1);
  91. presenceData.state = "";
  92. // hex will always be visible
  93. if (hexVal) presenceData.state += `Hex ${hexVal}`;
  94. if (wall?.style.display && wallVal)
  95. presenceData.state += `, Wall ${wallVal}`;
  96. if (shelf?.style.display && shelfVal)
  97. presenceData.state += `, Shelf ${shelfVal}`;
  98. if (vol?.style.display && volVal)
  99. presenceData.state += `, Volume ${volVal}`;
  100. }
  101. break;
  102. case Pages.theory:
  103. case Pages.refhex:
  104. presenceData.details = `Learning about ${title}`;
  105. break;
  106. case Pages.images:
  107. presenceData.details = "Viewing images";
  108. break;
  109. case Pages.coloroscopy:
  110. presenceData.details = "Undergoing coloroscopy";
  111. break;
  112. default:
  113. presenceData.details = "Navigating the site";
  114. break;
  115. }
  116. presence.setActivity(presenceData);
  117. });