presence.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. const presence = new Presence({
  2. clientId: '812085870382809128',
  3. })
  4. const time = Math.floor(Date.now() / 1000)
  5. enum ActivityAssets {
  6. Logo = 'https://cdn.rcd.gg/PreMiD/websites/R/Riot%20Games/assets/logo.png',
  7. Valorant = 'https://cdn.rcd.gg/PreMiD/websites/R/Riot%20Games/assets/0.png',
  8. Lol = 'https://cdn.rcd.gg/PreMiD/websites/R/Riot%20Games/assets/1.png',
  9. Tft = 'https://cdn.rcd.gg/PreMiD/websites/R/Riot%20Games/assets/2.png',
  10. Wildrift = 'https://cdn.rcd.gg/PreMiD/websites/R/Riot%20Games/assets/3.png',
  11. Lor = 'https://cdn.rcd.gg/PreMiD/websites/R/Riot%20Games/assets/4.png',
  12. }
  13. presence.on('UpdateData', async () => {
  14. const path = location.href
  15. .replace(/\/?$/, '/')
  16. .replace(`https://${location.hostname}`, '')
  17. .replace('?', '/')
  18. let presenceData: PresenceData = {
  19. largeImageKey: ActivityAssets.Logo,
  20. startTimestamp: time,
  21. }
  22. if (location.hostname === 'riotgames.com' || location.hostname === 'www.riotgames.com') {
  23. const statics: {
  24. [name: string]: PresenceData
  25. } = {
  26. '/': {
  27. details: 'Idling...',
  28. },
  29. '/who-we-are/': {
  30. details: 'Looking at:',
  31. state: 'Who we are | Riot Games',
  32. },
  33. '/work-with-us/': {
  34. details: 'Looking at:',
  35. state: 'Work with us! | Riot Games',
  36. },
  37. '/news/': {
  38. details: 'Looking at News:',
  39. state: `${
  40. Array.from(document.querySelectorAll('div')).find(c =>
  41. c.className?.includes('style__Title'),
  42. )?.textContent
  43. } | Riot Games`,
  44. },
  45. '/category/': {
  46. details: 'Browsing Store:',
  47. state: `${document.querySelector('h1')?.textContent} | Riot Merch`,
  48. },
  49. '/product/': {
  50. details: 'Looking at Product:',
  51. state: `${document.querySelector('h1')?.textContent} | Riot Merch`,
  52. },
  53. '/account/': {
  54. details: 'Looking at Account:',
  55. state: `${document.querySelector('h1')?.textContent} | Riot Merch`,
  56. },
  57. '/cart/': {
  58. details: 'Looking at Cart:',
  59. state: `${document.querySelector('h1')?.textContent} | Riot Merch`,
  60. },
  61. }
  62. for (const [k, v] of Object.entries(statics)) {
  63. if (path.match(k)) {
  64. presenceData.largeImageKey = ActivityAssets.Logo
  65. presenceData = { ...presenceData, ...v } as PresenceData
  66. }
  67. }
  68. }
  69. else {
  70. switch (location.hostname) {
  71. case 'teamfighttactics.leagueoflegends.com': {
  72. const statics: {
  73. [name: string]: PresenceData
  74. } = {
  75. '/': {
  76. details: 'Idling...',
  77. },
  78. '/news/': {
  79. details: 'Looking at News:',
  80. state: `${
  81. Array.from(document.querySelectorAll('div')).find(c =>
  82. c.className?.includes('style__Title'),
  83. )?.textContent
  84. } | TfT`,
  85. },
  86. '/set-overview/': {
  87. details: 'Looking at:',
  88. state: 'Set-Overview | TfT',
  89. },
  90. }
  91. for (const [k, v] of Object.entries(statics)) {
  92. if (path.match(k)) {
  93. presenceData.largeImageKey = ActivityAssets.Tft
  94. presenceData = { ...presenceData, ...v } as PresenceData
  95. }
  96. }
  97. break
  98. }
  99. case 'wildrift.leagueoflegends.com': {
  100. const statics: {
  101. [name: string]: PresenceData
  102. } = {
  103. '/': {
  104. details: 'Idling...',
  105. },
  106. '/news/': {
  107. details: 'Looking at News:',
  108. state: `${
  109. document.querySelector('h1')?.textContent
  110. } | LoL: Wild Rift`,
  111. },
  112. '/game-overview/': {
  113. details: 'Looking at:',
  114. state: 'Game-Overview | LoL:Wild Rift',
  115. },
  116. '/champions/': {
  117. details: 'Looking at Champion:',
  118. state: `${
  119. document.querySelector('h3')?.textContent
  120. } | LoL: Wild Rift`,
  121. },
  122. }
  123. for (const [k, v] of Object.entries(statics)) {
  124. if (path.match(k)) {
  125. presenceData.largeImageKey = ActivityAssets.Wildrift
  126. presenceData = { ...presenceData, ...v } as PresenceData
  127. }
  128. }
  129. break
  130. }
  131. case 'playvalorant.com': {
  132. const statics: {
  133. [name: string]: PresenceData
  134. } = {
  135. '/': {
  136. details: 'Idling...',
  137. },
  138. '/news/': {
  139. details: 'Looking at News:',
  140. state: `${document.querySelector('h2')?.textContent} | VALORANT`,
  141. },
  142. '/maps/': {
  143. details: 'Looking at:',
  144. state: 'Maps | VALORANT',
  145. },
  146. '/agents/': {
  147. details: 'Looking at:',
  148. state: `${
  149. document.querySelector(
  150. '.slick-slide.slick-active.slick-center.slick-current > div > div > h2',
  151. )?.textContent
  152. } | VALORANT`, // ENTER HEADER
  153. },
  154. '/media/': {
  155. details: 'Browsing Media',
  156. state: 'VALORANT',
  157. },
  158. '/leaderboards/': {
  159. details: 'Browsing Leaderboards:',
  160. state: 'VALORANT',
  161. },
  162. '/specs/': {
  163. details: 'Looking at:',
  164. state: 'Specs | VALORANT',
  165. },
  166. '/arsenal/': {
  167. details: 'Looking at:',
  168. state: 'Arsenal | VALORANT',
  169. },
  170. }
  171. for (const [k, v] of Object.entries(statics)) {
  172. if (path.match(k)) {
  173. presenceData.largeImageKey = ActivityAssets.Valorant
  174. presenceData = { ...presenceData, ...v } as PresenceData
  175. }
  176. }
  177. break
  178. }
  179. default:
  180. if (location.hostname === 'leagueoflegends.com' || location.hostname === 'www.leagueoflegends.com') {
  181. const statics: {
  182. [name: string]: PresenceData
  183. } = {
  184. '/': {
  185. details: 'Idling...',
  186. },
  187. '/how-to-play/': {
  188. details: 'Looking at:',
  189. state: 'How to Play! | LoL',
  190. },
  191. '/champions/': {
  192. details: 'Looking at Champion:',
  193. state: `${document.querySelector('strong')?.textContent} | LoL`,
  194. },
  195. '/champion/': {
  196. details: 'Looking at Champion:',
  197. state: `${
  198. Array.from(document.querySelectorAll('span')).find(c =>
  199. c.className?.includes('title'),
  200. )?.textContent
  201. } | LoL`,
  202. },
  203. '/news/': {
  204. details: 'Looking at News:',
  205. state: `${
  206. Array.from(document.querySelectorAll('div')).find(c =>
  207. c.className?.includes('style__Title'),
  208. )?.textContent
  209. } | LoL`,
  210. },
  211. '/news/tags/patch-notes/': {
  212. details: 'Looking at:',
  213. state: 'Patch notes Overview | LoL',
  214. },
  215. '/featured/': {
  216. details: 'Looking at:',
  217. state: 'League Displays | LoL',
  218. },
  219. '/story/': {
  220. details: 'Reading Story:',
  221. state: `${document.querySelector('h1')?.textContent} | LoL`,
  222. },
  223. '/regions/': {
  224. details: 'Looking at Region:',
  225. state: `${
  226. Array.from(document.querySelectorAll('span')).find(c =>
  227. c.className?.includes('title'),
  228. )?.textContent
  229. } | LoL`,
  230. },
  231. '/comic/': {
  232. details: 'LoL - Reading comic:',
  233. state: `${document.querySelector('h1')?.textContent} | LoL`,
  234. },
  235. '/kda/': {
  236. details: 'Alt Universe:',
  237. state: 'K/DA | LoL',
  238. },
  239. '/star-guardian/': {
  240. details: 'Alt Universe:',
  241. state: 'Star Guardians | LoL',
  242. },
  243. '/odyssey/': {
  244. details: 'Alt Universe:',
  245. state: 'Odyssey | LoL',
  246. },
  247. '/explore/': {
  248. details: 'Searching through:',
  249. state: 'Everything League | LoL',
  250. },
  251. }
  252. for (const [k, v] of Object.entries(statics)) {
  253. if (path.match(k)) {
  254. presenceData.largeImageKey = ActivityAssets.Lol
  255. presenceData = { ...presenceData, ...v } as PresenceData
  256. }
  257. }
  258. }
  259. else if (location.hostname === 'playruneterra.com' || location.hostname === 'www.playruneterra.com') {
  260. const statics: {
  261. [name: string]: PresenceData
  262. } = {
  263. '/': {
  264. details: 'Idling...',
  265. },
  266. '/news/': {
  267. details: 'Looking at news:',
  268. state: `${
  269. Array.from(document.querySelectorAll('div')).find(c =>
  270. c.className?.includes('style__Title'),
  271. )?.textContent
  272. } | LoR`,
  273. },
  274. '/news/competitive/': {
  275. details: 'Tournaments:',
  276. state: `${document.querySelector('h1')?.textContent} | LoR`,
  277. },
  278. }
  279. for (const [k, v] of Object.entries(statics)) {
  280. if (path.match(k)) {
  281. presenceData.largeImageKey = ActivityAssets.Lor
  282. presenceData = { ...presenceData, ...v } as PresenceData
  283. }
  284. }
  285. }
  286. }
  287. }
  288. if (presenceData.details)
  289. presence.setActivity(presenceData)
  290. else presence.setActivity()
  291. })