presence.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const presence = new Presence({
  2. clientId: '997455719840370729',
  3. })
  4. const browsingTimestamp = Math.floor(Date.now() / 1000)
  5. presence.on('UpdateData', async () => {
  6. const presenceData: PresenceData = {
  7. startTimestamp: browsingTimestamp,
  8. largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/S/Serializd/assets/0.png',
  9. }
  10. if (document.location.pathname === '/') {
  11. presenceData.details = 'Viewing the home page'
  12. }
  13. else if (document.location.pathname.includes('popular')) {
  14. presenceData.details = 'Viewing Popular Shows'
  15. }
  16. else if (document.location.pathname.includes('upcoming')) {
  17. presenceData.details = 'Viewing upcoming episodes'
  18. }
  19. else if (document.location.pathname.includes('signup')) {
  20. presenceData.details = 'Making a new account'
  21. }
  22. else if (document.location.pathname.includes('settings')) {
  23. presenceData.details = 'Editing their profile/account settings'
  24. }
  25. else if (document.location.pathname.includes('login')) {
  26. presenceData.details = 'Logging in'
  27. }
  28. else if (document.location.pathname.startsWith('/reviews/')) {
  29. if (document.location.pathname.endsWith('trending')) {
  30. presenceData.details = 'Viewing trending reviews'
  31. }
  32. else if (document.location.pathname.endsWith('friends')) {
  33. presenceData.details = 'Viewing their friend activity'
  34. }
  35. else {
  36. presenceData.details = `Viewing reviews of ${
  37. document.querySelector('.subheading')?.textContent
  38. }`
  39. }
  40. }
  41. else if (document.location.pathname.includes('review')) {
  42. presenceData.details = `Viewing a review for ${
  43. document.querySelector('.subheading')?.textContent
  44. }`
  45. }
  46. else if (document.location.pathname.includes('user')) {
  47. presenceData.details = `Viewing ${
  48. document.querySelector('.heading')?.textContent
  49. }'s Profile`
  50. }
  51. else if (document.location.pathname.includes('season')) {
  52. presenceData.largeImageKey = `${
  53. document.querySelector<HTMLImageElement>('.sticky-top-fixed-header > img')
  54. ?.src
  55. }`
  56. presenceData.details = 'Viewing Season:'
  57. presenceData.state = `${
  58. document.querySelector('.heading span')?.textContent
  59. }`
  60. }
  61. else if (document.location.pathname.includes('show')) {
  62. presenceData.largeImageKey = `${
  63. document.querySelector<HTMLImageElement>('.show-image')?.src
  64. }`
  65. presenceData.details = `Viewing ${
  66. document.querySelector('.heading span')?.textContent
  67. }`
  68. presenceData.state = `With ${
  69. document.querySelectorAll('.show-stats-icon-container span')[2]
  70. ?.textContent
  71. } reviews`
  72. }
  73. else if (document.location.pathname.includes('search')) {
  74. presenceData.details = `Searching for ${
  75. document.querySelector<HTMLInputElement>(
  76. 'input.search-page-search-input.form-control',
  77. )?.value
  78. }`
  79. }
  80. if (presenceData.details)
  81. presence.setActivity(presenceData)
  82. else presence.setActivity()
  83. })