fix: scoreinfo
This commit is contained in:
parent
c63b30bc5d
commit
b787158a5d
1 changed files with 29 additions and 10 deletions
|
@ -1,10 +1,15 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||||
|
|
||||||
// run at document-start
|
// run at document-start
|
||||||
export const ugappJsStore = (() => {
|
export const ugappJsStore: Record<string, any> | null = (() => {
|
||||||
const el = document.querySelector('.js-store') as HTMLDivElement
|
try {
|
||||||
const json = el.dataset.content as string
|
const el = document.querySelector('.js-store') as HTMLDivElement
|
||||||
return JSON.parse(json)
|
const json = el.dataset.content as string
|
||||||
|
return JSON.parse(json)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
return null
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
export const scoreinfo = {
|
export const scoreinfo = {
|
||||||
|
@ -15,14 +20,21 @@ export const scoreinfo = {
|
||||||
},
|
},
|
||||||
|
|
||||||
get id (this: typeof scoreinfo): number {
|
get id (this: typeof scoreinfo): number {
|
||||||
return this.playerdata.id
|
try {
|
||||||
|
return this.playerdata.id
|
||||||
|
} catch {
|
||||||
|
const el = document.querySelector("meta[property='al:ios:url']") as HTMLMetaElement
|
||||||
|
const m = el.content.match(/(\d+)$/) as RegExpMatchArray
|
||||||
|
return +m[1]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get title (this: typeof scoreinfo): string {
|
get title (this: typeof scoreinfo): string {
|
||||||
try {
|
try {
|
||||||
return this.playerdata.title
|
return this.playerdata.title
|
||||||
} catch (_) {
|
} catch {
|
||||||
return ''
|
const el = document.querySelector("meta[property='og:title']") as HTMLMetaElement
|
||||||
|
return el.content
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -33,13 +45,20 @@ export const scoreinfo = {
|
||||||
get pageCount (this: typeof scoreinfo): number {
|
get pageCount (this: typeof scoreinfo): number {
|
||||||
try {
|
try {
|
||||||
return this.playerdata.pages_count
|
return this.playerdata.pages_count
|
||||||
} catch (_) {
|
} catch {
|
||||||
return document.querySelectorAll('img[src*=score_]').length
|
return document.querySelectorAll('.gXB83').length
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get baseUrl (this: typeof scoreinfo): string {
|
get baseUrl (this: typeof scoreinfo): string {
|
||||||
const thumbnailUrl = this.playerdata.thumbnails.original
|
let thumbnailUrl: string
|
||||||
|
try {
|
||||||
|
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
|
||||||
return origin + pathname.split('/').slice(0, -1).join('/') + '/'
|
return origin + pathname.split('/').slice(0, -1).join('/') + '/'
|
||||||
|
|
Loading…
Reference in a new issue