presence.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const presence = new Presence({
  2. clientId: "928142086446923798",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. const enum Assets {
  6. Logo = "https://cdn.rcd.gg/PreMiD/websites/V/VGMdb/assets/logo.png",
  7. }
  8. presence.on("UpdateData", async () => {
  9. const presenceData: PresenceData = {
  10. largeImageKey: Assets.Logo,
  11. startTimestamp: browsingTimestamp,
  12. },
  13. cover = await presence.getSetting<boolean>("cover"),
  14. shortTitle = document.title.match(/(.*) -/)[1],
  15. { pathname } = document.location;
  16. if (pathname.startsWith("/album")) {
  17. presenceData.details = document.querySelector<HTMLSpanElement>(
  18. "#innermain > h1 > span"
  19. ).textContent;
  20. presenceData.state =
  21. document.querySelector<HTMLDivElement>("#coverart").title;
  22. if (cover) {
  23. if (
  24. document.querySelector<HTMLMetaElement>("meta[property='og:image']")
  25. ) {
  26. presenceData.largeImageKey = document.querySelector<HTMLMetaElement>(
  27. "meta[property='og:image']"
  28. ).content;
  29. presenceData.smallImageKey = Assets.Logo;
  30. } else presenceData.largeImageKey = Assets.Logo;
  31. }
  32. presenceData.buttons = [{ label: "View Album", url: document.URL }];
  33. } else if (pathname.startsWith("/artist")) {
  34. presenceData.details = "Viewing an artist:";
  35. presenceData.state = shortTitle;
  36. if (cover) {
  37. if (document.querySelector<HTMLAnchorElement>("#leftfloat > div > a")) {
  38. presenceData.largeImageKey = document.querySelector<HTMLAnchorElement>(
  39. "#leftfloat > div > a"
  40. ).href;
  41. presenceData.smallImageKey = Assets.Logo;
  42. } else if (
  43. document.querySelector<HTMLAnchorElement>("#innermain > div > a")
  44. ) {
  45. presenceData.largeImageKey = document.querySelector<HTMLAnchorElement>(
  46. "#innermain > div > a"
  47. ).href;
  48. presenceData.smallImageKey = Assets.Logo;
  49. } else {
  50. presenceData.largeImageKey =
  51. "https://cdn.rcd.gg/PreMiD/websites/V/VGMdb/assets/logo.png";
  52. }
  53. }
  54. presenceData.buttons = [{ label: "View Artist", url: document.URL }];
  55. } else if (pathname.startsWith("/org") || pathname.startsWith("/product")) {
  56. if (pathname.startsWith("/org")) {
  57. presenceData.details = "Viewing a label/organization:";
  58. presenceData.buttons = [{ label: "View Label/Org", url: document.URL }];
  59. } else if (pathname.startsWith("/product")) {
  60. presenceData.details = "Viewing a product:";
  61. presenceData.buttons = [{ label: "View Product", url: document.URL }];
  62. }
  63. presenceData.state = shortTitle;
  64. if (cover) {
  65. if (document.querySelector<HTMLAnchorElement>("#innermain > div > a")) {
  66. presenceData.largeImageKey = document.querySelector<HTMLAnchorElement>(
  67. "#innermain > div > a"
  68. ).href;
  69. presenceData.smallImageKey = Assets.Logo;
  70. } else {
  71. presenceData.largeImageKey =
  72. "https://cdn.rcd.gg/PreMiD/websites/V/VGMdb/assets/logo.png";
  73. }
  74. }
  75. } else if (pathname.startsWith("/event")) {
  76. presenceData.details = "Viewing an event:";
  77. presenceData.state = shortTitle;
  78. } else if (pathname.startsWith("/db")) {
  79. presenceData.details = "Searching the database";
  80. if (pathname.includes("albums")) presenceData.state = "Browsing albums";
  81. else if (pathname.includes("artists"))
  82. presenceData.state = "Browsing artists";
  83. else if (pathname.includes("org"))
  84. presenceData.state = "Browsing labels & organizations";
  85. else if (pathname.includes("product"))
  86. presenceData.state = "Browsing products";
  87. else if (pathname.includes("marketplace"))
  88. presenceData.state = "Browsing the marketplace";
  89. } else if (pathname.startsWith("/search"))
  90. presenceData.details = "Searching...";
  91. else if (
  92. pathname.startsWith("/forums") &&
  93. (pathname.includes("forumdisplay") || pathname.includes("showthread"))
  94. ) {
  95. if (pathname.includes("forumdisplay"))
  96. presenceData.details = "Viewing a forum:";
  97. else if (pathname.includes("showthread"))
  98. presenceData.details = "Viewing a thread:";
  99. else presenceData.details = "Browsing the forum";
  100. presenceData.state = shortTitle;
  101. }
  102. presence.setActivity(presenceData);
  103. });