presence.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const presence = new Presence({
  2. clientId: '811198714726449183',
  3. })
  4. const browsingTimestamp = Math.floor(Date.now() / 1000)
  5. enum ActivityAssets {
  6. Logo = 'https://cdn.rcd.gg/PreMiD/websites/D/Destiny%20Item%20Manager/assets/logo.png',
  7. GuardianWarlock = 'https://cdn.rcd.gg/PreMiD/websites/D/Destiny%20Item%20Manager/assets/0.png',
  8. GuardianTitan = 'https://cdn.rcd.gg/PreMiD/websites/D/Destiny%20Item%20Manager/assets/1.png',
  9. GuardianHunter = 'https://cdn.rcd.gg/PreMiD/websites/D/Destiny%20Item%20Manager/assets/2.png',
  10. }
  11. presence.on('UpdateData', async () => {
  12. const presenceData: PresenceData = {
  13. largeImageKey: ActivityAssets.Logo,
  14. startTimestamp: browsingTimestamp,
  15. }
  16. if (window.location.host === 'destinyitemmanager.com') {
  17. presenceData.details = 'Browsing...'
  18. }
  19. else if (window.location.host.startsWith('app')) {
  20. if (window.location.pathname.includes('inventory')) {
  21. const guardian = document
  22. .querySelector(
  23. '#content > div.inventory-container.destiny2 > div > div.store-row.store-header > div:nth-child(1) > div:nth-child(1) > div > div._2mo8C > div._1zQrq > div.ohqoA > div.FZBlR',
  24. )
  25. ?.textContent
  26. ?.trim()
  27. presenceData.details = 'Inventory'
  28. presenceData.state = guardian
  29. presenceData.smallImageText = `${guardian} - ${document
  30. .querySelector(
  31. '#content > div.inventory-container.destiny2 > div > div.store-row.store-header > div:nth-child(1) > div:nth-child(1) > div > div._2mo8C > div._1zQrq > div.ohqoA > div._1FuuK',
  32. )
  33. ?.textContent
  34. ?.trim()}`
  35. switch (guardian) {
  36. case 'Titan': {
  37. presenceData.smallImageKey = ActivityAssets.GuardianTitan
  38. break
  39. }
  40. case 'Warlock': {
  41. presenceData.smallImageKey = ActivityAssets.GuardianWarlock
  42. break
  43. }
  44. case 'Hunter': {
  45. presenceData.smallImageKey = ActivityAssets.GuardianHunter
  46. break
  47. }
  48. }
  49. }
  50. else if (window.location.pathname.includes('progress')) {
  51. presenceData.details = 'Progress'
  52. }
  53. else if (window.location.pathname.includes('vendors')) {
  54. presenceData.details = 'Vendors'
  55. }
  56. else if (window.location.pathname.includes('records')) {
  57. presenceData.details = 'Records'
  58. }
  59. else if (window.location.pathname.includes('optimizer')) {
  60. presenceData.details = 'Loadout Optimizer'
  61. }
  62. else if (window.location.pathname.includes('organizer')) {
  63. presenceData.details = 'Organizer'
  64. }
  65. else if (window.location.pathname.includes('settings')) {
  66. presenceData.details = 'Settings'
  67. }
  68. else if (window.location.pathname.includes('about')) {
  69. presenceData.details = 'About'
  70. }
  71. else if (window.location.pathname.includes('whats-new')) {
  72. presenceData.details = 'DIM Changes'
  73. }
  74. }
  75. else {
  76. presenceData.details = 'Browsing...'
  77. }
  78. presence.setActivity(presenceData)
  79. })