From f8060aaf0787d4f8f8864e929d5bcf5930b5ed9f Mon Sep 17 00:00:00 2001 From: Xmader Date: Sun, 1 Dec 2019 04:11:40 -0500 Subject: [PATCH] v0.3.2 - PDF cache --- dist/main.js | 12 ++++++++++-- package.json | 2 +- src/main.ts | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/dist/main.js b/dist/main.js index 7bf507f..a376191 100644 --- a/dist/main.js +++ b/dist/main.js @@ -3,7 +3,7 @@ // @namespace https://www.xmader.com/ // @homepageURL https://github.com/Xmader/musescore-downloader/ // @supportURL https://github.com/Xmader/musescore-downloader/issues -// @version 0.3.1 +// @version 0.3.2 // @description 免登录、免 Musescore Pro,下载 musescore.com 上的曲谱 // @author Xmader // @match https://musescore.com/*/* @@ -25973,7 +25973,11 @@ Please pipe the document into a Node stream.\ mixin(ImagesMixin); mixin(OutputDocumentBrowser); + let pdfBlob; const generatePDF = (name) => { + if (pdfBlob) { + return FileSaver(pdfBlob, `${name}.pdf`); + } const scoreImgs = document.querySelectorAll("img[id^=score_]"); const { naturalWidth: width, naturalHeight: height } = scoreImgs[0]; const canvas = document.createElement("canvas"); @@ -26002,8 +26006,12 @@ Please pipe the document into a Node stream.\ height, }); }); + // TODO: webworker // @ts-ignore - return pdf.download(`${name}.pdf`); + return pdf.getBlob().then((blob) => { + pdfBlob = blob; + FileSaver(blob, `${name}.pdf`); + }); }; const getTitle = (scorePlayerData) => { try { diff --git a/package.json b/package.json index 218e102..ec8eef8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "musescore-downloader", - "version": "0.3.1", + "version": "0.3.2", "description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱", "main": "dist/main.js", "repository": { diff --git a/src/main.ts b/src/main.ts index f3e7a3b..efbbcf5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,8 +4,15 @@ import { ScorePlayerData } from "./types" import { waitForDocumentLoaded } from "./utils" import PDFDocument from "pdfkit/lib/document" +import saveAs from "file-saver/dist/FileSaver.js" + +let pdfBlob: Blob const generatePDF = (name?: string) => { + if (pdfBlob) { + return saveAs(pdfBlob, `${name}.pdf`) + } + const scoreImgs: NodeListOf = document.querySelectorAll("img[id^=score_]") const { naturalWidth: width, naturalHeight: height } = scoreImgs[0] @@ -36,14 +43,19 @@ const generatePDF = (name?: string) => { imgDataList.forEach((data) => { pdf.addPage() - pdf.image(data,{ + pdf.image(data, { width, height, }) }) + // TODO: webworker + // @ts-ignore - return pdf.download(`${name}.pdf`) + return pdf.getBlob().then((blob: Blob) => { + pdfBlob = blob + saveAs(blob, `${name}.pdf`) + }) } const getTitle = (scorePlayerData: ScorePlayerData) => {