From c334d8d12434b9f3b99c752d429e7350f8657deb Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 24 Nov 2020 02:10:56 -0500 Subject: [PATCH] refactor: replace base url with thumbnail url --- src/pdf.ts | 2 +- src/scoreinfo.ts | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pdf.ts b/src/pdf.ts index 0ff0984..ffa7830 100644 --- a/src/pdf.ts +++ b/src/pdf.ts @@ -29,7 +29,7 @@ export const downloadPDF = async (): Promise => { const rs = Array.from({ length: pageCount }).map((_, i) => { if (i === 0) { // The url to the first page is static. We don't need to use API to obtain it. - return scoreinfo.baseUrl + `score_${i}.${imgType}` + return scoreinfo.thumbnailUrl } else { // obtain image urls using the API return getFileUrl('img', i) } diff --git a/src/scoreinfo.ts b/src/scoreinfo.ts index c1b6304..a5eedfc 100644 --- a/src/scoreinfo.ts +++ b/src/scoreinfo.ts @@ -20,13 +20,11 @@ export const scoreinfo = { return document.querySelectorAll('.gXB83').length }, - get baseUrl (this: typeof scoreinfo): string { + get thumbnailUrl (this: typeof scoreinfo): string { + // url to the image of the first page const el = document.querySelector("meta[property='og:image']") as HTMLMetaElement - const thumbnailUrl = el.content - - const { origin, pathname } = new URL(thumbnailUrl) - // remove the last part - return origin + pathname.split('/').slice(0, -1).join('/') + '/' + const url = el.content + return url.split('@')[0] }, get sheetImgType (): 'svg' | 'png' {