2020-10-01 15:55:38 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
2020-05-18 22:44:45 +00:00
|
|
|
|
2020-11-12 07:54:49 +00:00
|
|
|
const IPNS_KEY = 'QmSdXtvzC8v8iTTZuj5cVmiugnzbR1QATYRcGix4bBsioP'
|
2020-11-14 22:44:25 +00:00
|
|
|
const RADIX = 20
|
2020-11-12 07:54:49 +00:00
|
|
|
|
2020-11-24 07:29:37 +00:00
|
|
|
export abstract class ScoreInfo {
|
|
|
|
abstract id: number;
|
|
|
|
abstract title: string;
|
2020-05-18 22:44:45 +00:00
|
|
|
|
2020-11-24 07:59:19 +00:00
|
|
|
public store = new Map<symbol, any>();
|
|
|
|
|
2020-11-24 07:29:37 +00:00
|
|
|
get idLastDigit (): number {
|
|
|
|
return (+this.id) % RADIX
|
|
|
|
}
|
|
|
|
|
|
|
|
get fileName (): string {
|
|
|
|
return this.title.replace(/[\s<>:{}"/\\|?*~.\0\cA-\cZ]+/g, '_')
|
|
|
|
}
|
|
|
|
|
|
|
|
get msczIpfsRef (): string {
|
|
|
|
return `/ipns/${IPNS_KEY}/${this.idLastDigit}/${this.id}.mscz`
|
|
|
|
}
|
|
|
|
|
|
|
|
get msczCidUrl (): string {
|
|
|
|
return `https://ipfs.infura.io:5001/api/v0/block/stat?arg=${this.msczIpfsRef}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ScoreInfoInPage extends ScoreInfo {
|
|
|
|
constructor (private document: Document) { super() }
|
|
|
|
|
|
|
|
get id (): number {
|
|
|
|
const el = this.document.querySelector("meta[property='al:ios:url']") as HTMLMetaElement
|
2020-11-24 06:24:34 +00:00
|
|
|
const m = el.content.match(/(\d+)$/) as RegExpMatchArray
|
|
|
|
return +m[1]
|
2020-11-24 07:29:37 +00:00
|
|
|
}
|
2020-05-18 22:44:45 +00:00
|
|
|
|
2020-11-24 07:29:37 +00:00
|
|
|
get title (): string {
|
|
|
|
const el = this.document.querySelector("meta[property='og:title']") as HTMLMetaElement
|
2020-11-24 06:24:34 +00:00
|
|
|
return el.content
|
2020-11-24 07:29:37 +00:00
|
|
|
}
|
2020-11-24 08:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export abstract class SheetInfo {
|
|
|
|
abstract pageCount: number;
|
|
|
|
abstract thumbnailUrl: string;
|
|
|
|
|
|
|
|
get imgType (): 'svg' | 'png' {
|
|
|
|
const thumbnail = this.thumbnailUrl
|
|
|
|
const imgtype = thumbnail.match(/\.(\w+)$/)![1]
|
|
|
|
return imgtype as 'svg' | 'png'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SheetInfoInPage extends SheetInfo {
|
|
|
|
constructor (private document: Document) { super() }
|
2020-05-18 22:44:45 +00:00
|
|
|
|
2020-11-24 07:29:37 +00:00
|
|
|
get pageCount (): number {
|
|
|
|
return this.document.querySelectorAll('.gXB83').length
|
|
|
|
}
|
2020-05-18 22:44:45 +00:00
|
|
|
|
2020-11-24 07:29:37 +00:00
|
|
|
get thumbnailUrl (): string {
|
2020-11-24 07:10:56 +00:00
|
|
|
// url to the image of the first page
|
2020-11-24 07:31:31 +00:00
|
|
|
const el = this.document.querySelector('link[as=image]') as HTMLLinkElement
|
|
|
|
const url = el.href
|
2020-11-24 07:10:56 +00:00
|
|
|
return url.split('@')[0]
|
2020-11-24 07:29:37 +00:00
|
|
|
}
|
2020-05-18 22:44:45 +00:00
|
|
|
}
|