From c546ebdb83ea3a05b10903fc4bc277085ca7bf15 Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 20 Oct 2020 00:54:53 -0400 Subject: [PATCH] refactor: download individual parts --- src/main.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.ts b/src/main.ts index af3676b..3804fa8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -62,6 +62,7 @@ const main = (): void => { // render the part selection page txt.remove() const fieldset = w.document.createElement('fieldset') + w.document.body.append(fieldset) // part selection for (const excerpt of metadata.excerpts) { @@ -72,8 +73,10 @@ const main = (): void => { e.name = 'score-part' e.type = 'radio' e.alt = partName - e.value = id.toString() e.checked = id === 0 // initially select the first part + e.onclick = () => { + return score.setExcerptId(id) + } const label = w.document.createElement('label') label.innerText = partName @@ -86,17 +89,12 @@ const main = (): void => { const submitBtn = w.document.createElement('input') submitBtn.type = 'submit' submitBtn.value = 'Download PDF' - fieldset.append(submitBtn) - w.document.body.append(fieldset) submitBtn.onclick = async (): Promise => { const checked = fieldset.querySelector('input:checked') as HTMLInputElement - const id = checked.value const partName = checked.alt - await score.setExcerptId(+id) - const data = new Blob([await score.savePdf()]) saveAs(data, `${filename} - ${partName}.pdf`) }