presence.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import { Assets } from 'premid'
  2. const presence = new Presence({
  3. clientId: '619219701146583080',
  4. })
  5. const browsingTimestamp = Math.floor(Date.now() / 1000)
  6. presence.on('UpdateData', async () => {
  7. const presenceData: PresenceData = {
  8. largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/E/eBay/assets/logo.png',
  9. startTimestamp: browsingTimestamp,
  10. }
  11. const [, page] = location.pathname.split('/')
  12. if (location.hostname.startsWith('www.')) {
  13. if (!page) {
  14. presenceData.details = 'Viewing the'
  15. presenceData.state = 'Homepage'
  16. }
  17. else {
  18. switch (page) {
  19. case 'itm': {
  20. presenceData.details = document
  21. .querySelector('#itemTitle')
  22. ?.textContent
  23. ?.replace(
  24. document.querySelector('#itemTitle > span')?.textContent ?? '',
  25. '',
  26. )
  27. presenceData.buttons = [
  28. { label: 'View Item', url: location.href },
  29. {
  30. label: 'View Seller',
  31. url: document.querySelector<HTMLAnchorElement>('.mbg > a')?.href ?? '',
  32. },
  33. ]
  34. if (document.querySelector('#vi-cdown_timeLeft')) {
  35. delete presenceData.startTimestamp
  36. presenceData.state = document.querySelector('#vi-cdown_timeLeft')?.textContent
  37. }
  38. break
  39. }
  40. case 'sch': {
  41. if (location.pathname.includes('/i.html')) {
  42. presenceData.details = `Searching: ${
  43. document.querySelector(
  44. '.srp-controls__count-heading .BOLD:nth-child(2)',
  45. )?.textContent
  46. }`
  47. presenceData.state = `${
  48. document.querySelector('.srp-controls__count-heading .BOLD')
  49. ?.textContent
  50. } Results`
  51. presenceData.smallImageKey = Assets.Search
  52. }
  53. else if (location.pathname.includes('/m.html')) {
  54. const seller = document.querySelector('.mbid') as HTMLAnchorElement
  55. presenceData.details = 'Viewing listed products of:'
  56. presenceData.state = seller.textContent
  57. presenceData.buttons = [
  58. { label: 'View List', url: location.href },
  59. {
  60. label: 'View Seller',
  61. url: seller.href,
  62. },
  63. ]
  64. }
  65. break
  66. }
  67. case 'usr': {
  68. presenceData.details = 'User:'
  69. presenceData.state = document
  70. .querySelector('.mbg-id')
  71. ?.textContent
  72. ?.replace(
  73. document.querySelector('.mbg-id > span')?.textContent ?? '',
  74. '',
  75. )
  76. presenceData.buttons = [{ label: 'View User', url: location.href }]
  77. break
  78. }
  79. default:
  80. if (location.pathname.includes('/myb/')) {
  81. presenceData.details = 'Viewing their:'
  82. presenceData.state = document.querySelector(
  83. '#top-nav > div.topTitle > h1 > span.page-name',
  84. )?.textContent
  85. }
  86. else if (
  87. location.pathname.includes('/sns')
  88. || location.pathname.includes('/b/Stores-Hub/')
  89. ) {
  90. presenceData.details = 'Viewing stores'
  91. }
  92. else if (location.pathname.includes('/sl/')) {
  93. presenceData.details = 'eBay Sell'
  94. presenceData.state = 'Listing an item'
  95. }
  96. else if (location.pathname.includes('/b/')) {
  97. presenceData.details = 'Viewing category:'
  98. presenceData.state = document.querySelector(
  99. '.b-pageheader__text',
  100. )?.textContent
  101. }
  102. else if (location.pathname.includes('/help/')) {
  103. presenceData.details = 'eBay Help'
  104. }
  105. else if (location.pathname.includes('/deals')) {
  106. presenceData.details = 'Viewing the latest'
  107. presenceData.state = 'eBay deals'
  108. }
  109. else if (location.pathname.includes('/allcategories')) {
  110. presenceData.details = 'Viewing all categories'
  111. }
  112. }
  113. }
  114. }
  115. else if (page === 'str') {
  116. presenceData.details = 'eBay Store'
  117. presenceData.state = document.querySelector(
  118. '.str-billboard__title',
  119. )?.textContent
  120. presenceData.buttons = [{ label: 'View Store', url: location.href }]
  121. }
  122. else if (location.hostname.startsWith('mesg.')) {
  123. if (location.pathname.includes('/ViewMessageDetail/')) {
  124. presenceData.details = 'eBay Messages'
  125. presenceData.state = 'Viewing a message'
  126. }
  127. else if (location.pathname.includes('/ViewMessages/')) {
  128. presenceData.details = 'Browsing through'
  129. presenceData.state = 'eBay Messages'
  130. }
  131. else {
  132. presenceData.details = 'eBay Messages'
  133. }
  134. }
  135. else if (location.hostname.startsWith('ocsnext.')) {
  136. presenceData.details = 'eBay Customer Support'
  137. }
  138. else if (location.hostname.includes('developer.')) {
  139. presenceData.details = 'eBay Developer Program'
  140. }
  141. else if (location.hostname.startsWith('resolutioncenter.')) {
  142. presenceData.details = 'eBay Resolution Center'
  143. }
  144. else if (location.hostname.startsWith('my.')) {
  145. presenceData.details = 'Viewing their eBay'
  146. }
  147. else if (location.hostname.startsWith('login.')) {
  148. presenceData.details = 'eBay Login'
  149. }
  150. else if (location.hostname.startsWith('signin.')) {
  151. presenceData.details = 'eBay Login'
  152. }
  153. else if (location.hostname.startsWith('pages.')) {
  154. if (location.hash !== '') {
  155. presenceData.details = 'Viewing the sitemap'
  156. presenceData.state = location.hash
  157. }
  158. else if (location.pathname.includes('sitemap.html')) {
  159. presenceData.details = 'Viewing the sitemap'
  160. }
  161. else if (location.pathname.includes('seller-center')) {
  162. presenceData.details = 'Viewing the seller center'
  163. }
  164. }
  165. else if (location.hostname.startsWith('community.')) {
  166. if (document.querySelector('.lia-message-subject')) {
  167. presenceData.details = 'eBay Forum, Viewing:'
  168. presenceData.state = document.querySelector(
  169. '.lia-message-subject',
  170. )?.textContent
  171. presenceData.buttons = [
  172. { label: 'View Post', url: location.href },
  173. {
  174. label: 'View Author',
  175. url: document.querySelector<HTMLAnchorElement>(
  176. '.lia-component-message-view-widget-author-username > a',
  177. )?.href ?? '',
  178. },
  179. ]
  180. }
  181. else if (location.pathname.includes('/user/')) {
  182. presenceData.details = 'eBay Forum Author:'
  183. presenceData.state = document.querySelector(
  184. '.lia-user-name-link',
  185. )?.textContent
  186. presenceData.buttons = [{ label: 'View Author', url: location.href }]
  187. }
  188. else if (location.pathname.includes('/searchpage/')) {
  189. presenceData.details = 'eBay Forum Search:'
  190. presenceData.state = (
  191. document.querySelector('.lia-search-input-message') as HTMLInputElement
  192. )?.value
  193. }
  194. else {
  195. presenceData.details = 'eBay Forum'
  196. }
  197. }
  198. const showButtons = await presence.getSetting<boolean>('buttons')
  199. if (!showButtons)
  200. delete presenceData.buttons
  201. if (presenceData.details)
  202. presence.setActivity(presenceData)
  203. else presence.setActivity()
  204. })