presence.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const presence = new Presence({
  2. clientId: '700596580218175548',
  3. })
  4. const browsingTimestamp = Math.floor(Date.now() / 1000)
  5. const titulo = document.title
  6. const pesquisaR = titulo.slice(77)
  7. const tituloLength = titulo.length - 3
  8. const obraR = titulo.slice(0, tituloLength)
  9. const capituloR = titulo.slice(tituloLength)
  10. const obraanimeR = titulo.slice(7).slice(0, titulo.length - 18)
  11. const listaR = titulo.slice(54)
  12. const capitulo = document
  13. .querySelector('h2.post-title.entry-title')
  14. ?.textContent
  15. ?.match(/\d+/g) || null
  16. const obra = document.querySelector('h2.post-title.entry-title')?.textContent
  17. const noticia = document.querySelector('h2.post-title.entry-title')?.textContent
  18. presence.on('UpdateData', async () => {
  19. const presenceData: PresenceData = {
  20. largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/A/AnimeXNovel/assets/logo.png',
  21. }
  22. presenceData.startTimestamp = browsingTimestamp
  23. if (document.location.pathname.includes('anime')) {
  24. presenceData.details = obraanimeR
  25. presenceData.state = `Episódio ${capituloR}`
  26. }
  27. else if (document.location.pathname.startsWith('/search')) {
  28. if (document.location.pathname.includes('/search/label/')) {
  29. if (document.location.pathname.includes('/In%C3%ADcio')) {
  30. presenceData.details = 'Página inícial'
  31. }
  32. else {
  33. presenceData.details = 'Vendo a lista de'
  34. presenceData.state = listaR
  35. }
  36. }
  37. else {
  38. presenceData.details = 'Pesquisando...'
  39. presenceData.state = pesquisaR
  40. }
  41. }
  42. else if (document.location.pathname.match('/')) {
  43. if (
  44. capitulo === null
  45. && document.querySelector('div.post-body.entry-content.cl div.ocultar')
  46. !== null
  47. ) {
  48. presenceData.details = 'Vendo página de obra'
  49. presenceData.state = obra
  50. }
  51. else if (
  52. document.querySelector('div.post-body.entry-content.cl div.ocultar')
  53. === null
  54. ) {
  55. presenceData.details = 'Vendo página'
  56. presenceData.state = noticia
  57. }
  58. else {
  59. presenceData.details = obraR
  60. presenceData.state = `Capítulo ${capituloR}`
  61. }
  62. }
  63. if (presenceData.details)
  64. presence.setActivity(presenceData)
  65. else presence.setActivity()
  66. })