fix: no id attribute at score images (#7)

Google chrome had no id attribute at score images. Fixed by checking the src attribute.
This commit is contained in:
Xmader 2020-02-27 12:11:47 -05:00 committed by GitHub
commit 0baf661c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -15,7 +15,7 @@ const generatePDF = async (imgURLs: string[], imgType: "svg" | "png", name?: str
return saveAs(pdfBlob, `${name}.pdf`)
}
const cachedImg = document.querySelector("img[id^=score_]") as HTMLImageElement
const cachedImg = document.querySelector("img[src*=score_]") as HTMLImageElement
const { naturalWidth: width, naturalHeight: height } = cachedImg
const worker = new PDFWorkerHelper()
@ -31,13 +31,13 @@ const getPagesNumber = (scorePlayerData: ScorePlayerData) => {
try {
return scorePlayerData.json.metadata.pages
} catch (_) {
return document.querySelectorAll("img[id^=score_]").length
return document.querySelectorAll("img[src*=score_]").length
}
}
const getImgType = (): "svg" | "png" => {
try {
const imgE: HTMLImageElement = document.querySelector("img[id^=score_]")
const imgE: HTMLImageElement = document.querySelector("img[src*=score_]")
const { pathname } = new URL(imgE.src)
const imgtype = pathname.match(/\.(\w+)$/)[1]
return imgtype as "svg" | "png"