presence.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const presence = new Presence({
  2. clientId: "864573021762224129",
  3. }),
  4. startTimestamp = Math.floor(Date.now() / 1e3),
  5. whitespaceRegex = /^\s*|\n/gm;
  6. presence.on("UpdateData", () => {
  7. const [, pathCheck, mainPath, namespace] =
  8. window.location.pathname.split("/"),
  9. presenceData: PresenceData = {
  10. largeImageKey:
  11. "https://cdn.rcd.gg/PreMiD/websites/T/TV%20Tropes/assets/logo.png",
  12. startTimestamp,
  13. };
  14. function mainWikiPathDetails(namespace: string) {
  15. if (namespace === "Main") {
  16. presenceData.details = "Viewing a TV Trope";
  17. presenceData.state = document
  18. .querySelector(".entry-title")
  19. .textContent.replace(whitespaceRegex, "");
  20. } else {
  21. const titleElement = document.querySelector(".entry-title");
  22. presenceData.details = "Viewing a page";
  23. presenceData.state = `${titleElement
  24. .querySelector("strong")
  25. .textContent.replace(
  26. / \/ $/,
  27. ""
  28. )} / ${titleElement.childNodes[2].textContent.replace(
  29. whitespaceRegex,
  30. ""
  31. )}`;
  32. }
  33. }
  34. if (pathCheck === "pmwiki") {
  35. switch (mainPath) {
  36. case "pmwiki.php": {
  37. mainWikiPathDetails(namespace);
  38. break;
  39. }
  40. case "profile.php": {
  41. presenceData.details = "Viewing User Profile";
  42. break;
  43. }
  44. case "topics.php": {
  45. presenceData.details = "Browsing the Forum Homepage";
  46. break;
  47. }
  48. case "conversations.php": {
  49. presenceData.details = "Browsing Forum Category";
  50. presenceData.state = document
  51. .querySelector(".entry-title")
  52. .childNodes[2].textContent.replace(whitespaceRegex, "");
  53. break;
  54. }
  55. case "posts.php": {
  56. presenceData.details = "Browsing Forum Post";
  57. presenceData.state = document
  58. .querySelector(".entry-title")
  59. .textContent.replace(whitespaceRegex, "");
  60. break;
  61. }
  62. case "wysiwyg_source_editor.php": {
  63. const searchParams = new URLSearchParams(window.location.search);
  64. presenceData.details = "Editing TV Trope Page";
  65. presenceData.state = `${searchParams.get(
  66. "groupname"
  67. )} / ${searchParams.get("title")}`;
  68. break;
  69. }
  70. case "createconversation.php": {
  71. presenceData.details = "Creating a Forum Post";
  72. break;
  73. }
  74. default: {
  75. presenceData.details = "Browsing TV Tropes";
  76. presenceData.state = document.title;
  77. }
  78. }
  79. } else if (pathCheck) mainWikiPathDetails(pathCheck);
  80. else presenceData.details = "Browsing TV Tropes Homepage";
  81. if (presenceData.details) presence.setActivity(presenceData);
  82. });