presence.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Assets } from 'premid'
  2. const presence = new Presence({
  3. clientId: '795125406264066099',
  4. })
  5. enum ActivityAssets {
  6. Logo = 'https://cdn.rcd.gg/PreMiD/websites/A/AniChart/assets/logo.png',
  7. }
  8. presence.on('UpdateData', async () => {
  9. const presenceData: PresenceData = {
  10. largeImageKey: ActivityAssets.Logo,
  11. startTimestamp: Math.floor(Date.now() / 1000),
  12. }
  13. const { pathname } = document.location
  14. switch (
  15. pathname.endsWith('/') && pathname.length > 1
  16. ? pathname.slice(0, pathname.length - 1)
  17. : pathname
  18. ) {
  19. case '/airing':
  20. presenceData.details = 'Viewing currently airing anime'
  21. break
  22. case '/archive':
  23. presenceData.details = 'Viewing anime archive'
  24. break
  25. case '/tba':
  26. presenceData.details = 'Viewing TBA anime'
  27. break
  28. case '/settings':
  29. presenceData.details = 'Customizing settings'
  30. break
  31. default: {
  32. if ((document.querySelector('.input') as HTMLInputElement)?.value) {
  33. presenceData.details = 'Searching anime'
  34. presenceData.smallImageKey = Assets.Search
  35. presenceData.state = (
  36. document.querySelector('.input') as HTMLInputElement
  37. ).value
  38. }
  39. else {
  40. presenceData.details = `Viewing ${pathname
  41. .substring(1)
  42. .split('-')
  43. .join(' ')} anime`
  44. }
  45. break
  46. }
  47. }
  48. presence.setActivity(presenceData)
  49. })