presence.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const presence = new Presence({
  2. clientId: '1327710845546922075',
  3. })
  4. const browsingTimestamp = Math.floor(Date.now() / 1000)
  5. presence.on('UpdateData', async () => {
  6. const presenceData: PresenceData = {
  7. largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/T/Timeguessr/assets/logo.jpeg',
  8. startTimestamp: browsingTimestamp,
  9. }
  10. const privacy = await presence.getSetting<boolean>('privacy')
  11. const { pathname } = document.location
  12. if (!privacy) {
  13. switch (pathname) {
  14. case '/':
  15. presenceData.details = 'Warming up the time machine'
  16. break
  17. case '/privacypolicy':
  18. presenceData.details = 'Reading the fine print of time travel'
  19. break
  20. case '/login':
  21. presenceData.details = 'Logging into the past'
  22. break
  23. case '/createaccount':
  24. presenceData.details = 'Joining the timeguessers'
  25. break
  26. case '/submit':
  27. presenceData.details = 'Contributing to the time vault'
  28. break
  29. case '/game-settings':
  30. presenceData.details = 'Tuning the time machine'
  31. break
  32. case '/account':
  33. presenceData.details = 'Managing their historical identity'
  34. break
  35. case '/friends':
  36. presenceData.details = 'Catching up with fellow guessers'
  37. break
  38. case '/subscriptions':
  39. presenceData.details = 'Supporting the time machine'
  40. break
  41. }
  42. if (/\/round(?:one|two|three|four|five)(?:daily)?/.test(pathname)) {
  43. presenceData.details = 'Pinpointing moments in history'
  44. presenceData.state = `${
  45. document.querySelector('.progressBarText2')?.textContent
  46. } | Score: ${
  47. document.querySelector('#insertScore')?.textContent ?? 0
  48. } | Mode: ${
  49. pathname
  50. .match(/round(one|two|three|four|five)(daily)?/)?.[0]
  51. .includes('daily')
  52. ? 'Daily'
  53. : 'Normal'
  54. }`
  55. }
  56. else if (
  57. pathname === '/roundresults'
  58. || pathname === '/dailyroundresults'
  59. ) {
  60. presenceData.details = `Round results | Total score: ${
  61. document.querySelector('#insertTotal')?.textContent ?? 0
  62. }`
  63. presenceData.state = `Year: ${
  64. document.querySelector('#insertYearScore')?.textContent || '0'
  65. } | Location: ${
  66. document.querySelector('#insertLocationScore')?.textContent || '0'
  67. }`
  68. }
  69. else if (pathname === '/finalscore' || pathname === '/finalscoredaily') {
  70. presenceData.details = 'Guessed all the places and times'
  71. presenceData.state = `Final score: ${
  72. document.querySelector('#totalText')?.textContent
  73. }/50,000`
  74. }
  75. }
  76. else {
  77. presenceData.details = 'Playing timeguessr under the radar'
  78. delete presenceData.state
  79. }
  80. presence.setActivity(presenceData)
  81. })