presence.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const presence = new Presence({
  2. clientId: "872421983554502717",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. const enum Assets {
  6. Logo = "https://cdn.rcd.gg/PreMiD/websites/T/Timolia/assets/logo.png",
  7. Minecraft = "https://cdn.rcd.gg/PreMiD/websites/T/Timolia/assets/0.png",
  8. Gitlab = "https://cdn.rcd.gg/PreMiD/websites/T/Timolia/assets/1.png",
  9. }
  10. presence.on("UpdateData", () => {
  11. const presenceData: PresenceData = {
  12. largeImageKey: Assets.Logo,
  13. startTimestamp: browsingTimestamp,
  14. };
  15. switch (document.location.hostname) {
  16. case "www.timolia.de": {
  17. if (document.location.pathname === "/") {
  18. presenceData.details = "Viewing home page";
  19. presenceData.smallImageKey = Assets.Minecraft;
  20. presenceData.smallImageText = `${
  21. document.querySelector("#liveplayercount").textContent
  22. } online players`;
  23. } else if (document.location.pathname.startsWith("/stats")) {
  24. presenceData.details = "Viewing stats from:";
  25. presenceData.state = document.querySelector("#playername").textContent;
  26. } else if (document.location.pathname.includes("/games"))
  27. presenceData.details = "Viewing gamemodes";
  28. else if (document.location.pathname.includes("/account"))
  29. presenceData.details = "Viewing account settings";
  30. break;
  31. }
  32. case "howto.timolia.de": {
  33. presenceData.details = "HowTo - Reading:";
  34. presenceData.state = document.querySelector(
  35. "body > div.md-container > main > div > div.md-content > article > h1"
  36. ).textContent;
  37. break;
  38. }
  39. case "shop.timolia.de": {
  40. presenceData.details = "Shop - Viewing store page";
  41. if (document.location.pathname.startsWith("/checkout")) {
  42. presenceData.details = "Shop - Viewing shopping cart:";
  43. presenceData.state = document.querySelector(
  44. "body > div.sections-wrapper > section > div > div > div.jumbotron > div > div.packages > form > table > tbody > tr > td.col-md-6"
  45. ).textContent;
  46. }
  47. break;
  48. }
  49. case "forum.timolia.de": {
  50. presenceData.details = "Viewing forum start page";
  51. if (document.location.pathname.startsWith("/members")) {
  52. presenceData.details = "Viewing forum profile of:";
  53. presenceData.state = document.querySelector(
  54. "#content > div.pageWidth > div > div > div.mainProfileColumn > div > div > h1 > span"
  55. ).textContent;
  56. } else if (document.location.pathname.startsWith("/threads")) {
  57. presenceData.details = "Viewing thread:";
  58. presenceData.state = document.querySelector(
  59. "#content > div.pageWidth > div > div.titleBar > h1"
  60. ).textContent;
  61. } else if (document.location.pathname.startsWith("/forums")) {
  62. presenceData.details = "Viewing forum:";
  63. presenceData.state = document.querySelector(
  64. "#content > div.pageWidth > div > div.titleBar > h1"
  65. ).textContent;
  66. }
  67. break;
  68. }
  69. default:
  70. if (document.location.hostname.includes("wi.timolia.de"))
  71. presenceData.details = "Viewing Webinterface";
  72. else if (document.location.hostname.includes("gitlab.timolia.de")) {
  73. presenceData.details = "Viewing GitLab Server";
  74. presenceData.smallImageKey = Assets.Gitlab;
  75. }
  76. }
  77. if (presenceData.details) presence.setActivity(presenceData);
  78. else presence.setActivity();
  79. });