presence.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const presence = new Presence({
  2. clientId: "628269030901547037",
  3. });
  4. const enum Assets {
  5. Logo = "https://cdn.rcd.gg/PreMiD/websites/W/Webtekno/assets/logo.png",
  6. Video = "https://cdn.rcd.gg/PreMiD/websites/W/Webtekno/assets/0.png",
  7. Post = "https://cdn.rcd.gg/PreMiD/websites/W/Webtekno/assets/1.png",
  8. Star = "https://cdn.rcd.gg/PreMiD/websites/W/Webtekno/assets/2.png",
  9. }
  10. const pages: { [key: string]: string } = {
  11. "/": "Ana Sayfa",
  12. "/haber": "Haberler",
  13. "/video": "Videolar",
  14. "/en-cok-okunanlar": "En Çok Okunan Gönderiler",
  15. "/en-cok-paylasilanlar": "En Çok Paylaşılan Gönderiler",
  16. "/en-cok-izlenenler": "En Çok İzlenilen Videolar",
  17. "/ara": "Bir şeyler arıyor...",
  18. "/uye/favorilerim": "Favorilerim",
  19. "/hakkimizda": "Hakkımızda",
  20. "/yazarlar": "Yazarlar",
  21. "/odullerimiz": "Ödüllerimiz",
  22. "/kunye": "Künye",
  23. "/gizlilik": "Gizlilik",
  24. "/iletisim": "İletişim",
  25. },
  26. smallImageKey: { [key: string]: string } = {
  27. "/ara": Assets.Search,
  28. "/video": Assets.Video,
  29. "/uye/favorilerim": Assets.Star,
  30. };
  31. presence.on("UpdateData", async () => {
  32. const page = document.location.pathname,
  33. title = document.querySelector(
  34. "body > div.wt-container > div.global-container.container > div.content > div.news.content-detail-page > article > div.content-title > h1"
  35. ),
  36. videoTitle = document.querySelector(
  37. "body > div.wt-container > div.video-showcase > div > div.video-showcase__content__title > h1"
  38. );
  39. if (page.includes("/yazar/")) {
  40. const author = document.querySelector(
  41. "body > div.wt-container > div.global-container.container > div.content > div.content-author > div.content-author__detail > a > span"
  42. );
  43. presence.setActivity({
  44. largeImageKey: Assets.Logo,
  45. details: "Bir yazara göz atıyor:",
  46. state:
  47. author && author.textContent !== "" ? author.textContent : "Belirsiz",
  48. startTimestamp: Math.floor(Date.now() / 1000),
  49. });
  50. } else if (title && title.textContent !== "") {
  51. presence.setActivity({
  52. largeImageKey: Assets.Logo,
  53. details: `${title.textContent}`,
  54. state: `Yazar: ${
  55. document.querySelector(
  56. "body > div.wt-container > div.global-container.container > div.content > div.news.content-detail-page > article > div.content-info.clearfix > div.content-author > span:nth-child(1) > a"
  57. )
  58. ? document.querySelector(
  59. "body > div.wt-container > div.global-container.container > div.content > div.news.content-detail-page > article > div.content-info.clearfix > div.content-author > span:nth-child(1) > a"
  60. ).textContent
  61. : "Belirsiz"
  62. } (${
  63. document.querySelector(
  64. "body > div.wt-container > div.global-container.container > div.content > div.news.content-detail-page > article > div.content-info.clearfix > div.content-author > time"
  65. )
  66. ? document.querySelector(
  67. "body > div.wt-container > div.global-container.container > div.content > div.news.content-detail-page > article > div.content-info.clearfix > div.content-author > time"
  68. ).textContent
  69. : "Belirsiz Süre"
  70. })`,
  71. smallImageKey: Assets.Post,
  72. smallImageText: "Bir gönderi okuyor...",
  73. startTimestamp: Math.floor(Date.now() / 1000),
  74. });
  75. } else if (videoTitle && videoTitle.textContent !== "") {
  76. presence.setActivity({
  77. largeImageKey: Assets.Logo,
  78. details: `${videoTitle.textContent}`,
  79. state: `Yazar: ${
  80. document.querySelector(
  81. "body > div.wt-container > div.global-container.container > div.content > article > div.content-info > span:nth-child(1) > a"
  82. )
  83. ? document.querySelector(
  84. "body > div.wt-container > div.global-container.container > div.content > article > div.content-info > span:nth-child(1) > a"
  85. ).textContent
  86. : "Belirsiz"
  87. } (${
  88. document.querySelector(
  89. "body > div.wt-container > div.global-container.container > div.content > article > div.content-info > time"
  90. )
  91. ? document.querySelector(
  92. "body > div.wt-container > div.global-container.container > div.content > article > div.content-info > time"
  93. ).textContent
  94. : "Belirsiz Süre"
  95. })`,
  96. smallImageKey: Assets.Video,
  97. smallImageText: "Bir video gönderi okuyor...",
  98. startTimestamp: Math.floor(Date.now() / 1000),
  99. });
  100. } else {
  101. presence.setActivity({
  102. largeImageKey: Assets.Logo,
  103. details: "Bir sayfaya göz atıyor:",
  104. state: pages[page] || pages[page.slice(0, -1)] || "Ana Sayfa",
  105. smallImageKey: smallImageKey[page] || smallImageKey[page.slice(0, -1)],
  106. startTimestamp: Math.floor(Date.now() / 1000),
  107. });
  108. }
  109. });