refactor: remove playerdata from scoreinfo
This commit is contained in:
parent
f2e45d1803
commit
565e28a70d
1 changed files with 8 additions and 45 deletions
|
@ -1,38 +1,14 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||||
|
|
||||||
import { console } from './utils'
|
|
||||||
|
|
||||||
// run at document-start
|
|
||||||
export const ugappJsStore: Record<string, any> | null = (() => {
|
|
||||||
try {
|
|
||||||
const l = document.body.children as HTMLCollectionOf<HTMLElement>
|
|
||||||
const el = [...l].find(e => Object.keys(e.dataset).length > 0) as HTMLDivElement
|
|
||||||
const json = Object.values(el.dataset)[0] as string
|
|
||||||
return JSON.parse(json)
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
const IPNS_KEY = 'QmSdXtvzC8v8iTTZuj5cVmiugnzbR1QATYRcGix4bBsioP'
|
const IPNS_KEY = 'QmSdXtvzC8v8iTTZuj5cVmiugnzbR1QATYRcGix4bBsioP'
|
||||||
const RADIX = 20
|
const RADIX = 20
|
||||||
|
|
||||||
export const scoreinfo = {
|
export const scoreinfo = {
|
||||||
|
|
||||||
get playerdata (): any {
|
|
||||||
// @ts-ignore
|
|
||||||
return ugappJsStore.store.page.data.score
|
|
||||||
},
|
|
||||||
|
|
||||||
get id (this: typeof scoreinfo): number {
|
get id (this: typeof scoreinfo): number {
|
||||||
try {
|
const el = document.querySelector("meta[property='al:ios:url']") as HTMLMetaElement
|
||||||
return this.playerdata.id
|
const m = el.content.match(/(\d+)$/) as RegExpMatchArray
|
||||||
} catch {
|
return +m[1]
|
||||||
const el = document.querySelector("meta[property='al:ios:url']") as HTMLMetaElement
|
|
||||||
const m = el.content.match(/(\d+)$/) as RegExpMatchArray
|
|
||||||
return +m[1]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get idLastDigit (this: typeof scoreinfo): number {
|
get idLastDigit (this: typeof scoreinfo): number {
|
||||||
|
@ -40,12 +16,8 @@ export const scoreinfo = {
|
||||||
},
|
},
|
||||||
|
|
||||||
get title (this: typeof scoreinfo): string {
|
get title (this: typeof scoreinfo): string {
|
||||||
try {
|
const el = document.querySelector("meta[property='og:title']") as HTMLMetaElement
|
||||||
return this.playerdata.title
|
return el.content
|
||||||
} catch {
|
|
||||||
const el = document.querySelector("meta[property='og:title']") as HTMLMetaElement
|
|
||||||
return el.content
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get fileName (this: typeof scoreinfo): string {
|
get fileName (this: typeof scoreinfo): string {
|
||||||
|
@ -53,21 +25,12 @@ export const scoreinfo = {
|
||||||
},
|
},
|
||||||
|
|
||||||
get pageCount (this: typeof scoreinfo): number {
|
get pageCount (this: typeof scoreinfo): number {
|
||||||
try {
|
return document.querySelectorAll('.gXB83').length
|
||||||
return this.playerdata.pages_count
|
|
||||||
} catch {
|
|
||||||
return document.querySelectorAll('.gXB83').length
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get baseUrl (this: typeof scoreinfo): string {
|
get baseUrl (this: typeof scoreinfo): string {
|
||||||
let thumbnailUrl: string
|
const el = document.querySelector("meta[property='og:image']") as HTMLMetaElement
|
||||||
try {
|
const thumbnailUrl = el.content
|
||||||
thumbnailUrl = this.playerdata.thumbnails.original
|
|
||||||
} catch {
|
|
||||||
const el = document.querySelector("meta[property='og:image']") as HTMLMetaElement
|
|
||||||
thumbnailUrl = el.content
|
|
||||||
}
|
|
||||||
|
|
||||||
const { origin, pathname } = new URL(thumbnailUrl)
|
const { origin, pathname } = new URL(thumbnailUrl)
|
||||||
// remove the last part
|
// remove the last part
|
||||||
|
|
Loading…
Reference in a new issue