This commit is contained in:
Xmader 2021-01-27 14:03:58 -05:00
parent 41f5286d48
commit 06a91b1c2d
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
3 changed files with 21 additions and 18 deletions

35
dist/main.js vendored
View File

@ -5,7 +5,7 @@
// @supportURL https://github.com/Xmader/musescore-downloader/issues // @supportURL https://github.com/Xmader/musescore-downloader/issues
// @updateURL https://msdl.librescore.org/install.user.js // @updateURL https://msdl.librescore.org/install.user.js
// @downloadURL https://msdl.librescore.org/install.user.js // @downloadURL https://msdl.librescore.org/install.user.js
// @version 0.23.7 // @version 0.23.8
// @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱 // @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱
// @author Xmader // @author Xmader
// @match https://musescore.com/*/* // @match https://musescore.com/*/*
@ -26439,7 +26439,7 @@ Please pipe the document into a Node stream.\
}); });
/// <reference lib="webworker" /> /// <reference lib="webworker" />
const getDataURL = (blob) => { const readData = (blob, type) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = () => { reader.onload = () => {
@ -26447,19 +26447,21 @@ Please pipe the document into a Node stream.\
resolve(result); resolve(result);
}; };
reader.onerror = reject; reader.onerror = reject;
reader.readAsDataURL(blob); if (type === 'dataUrl') {
reader.readAsDataURL(blob);
}
else {
reader.readAsText(blob);
}
}); });
}; };
const fetchDataURL = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () { const fetchBlob = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () {
const r = yield fetch(imgUrl); const r = yield fetch(imgUrl, {
const blob = yield r.blob(); cache: 'no-cache',
return getDataURL(blob); });
return r.blob();
}); });
const fetchText = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () { const generatePDF = (imgBlobs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () {
const r = yield fetch(imgUrl);
return r.text();
});
const generatePDF = (imgURLs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () {
// @ts-ignore // @ts-ignore
const pdf = new PDFDocument({ const pdf = new PDFDocument({
// compress: true, // compress: true,
@ -26469,7 +26471,7 @@ Please pipe the document into a Node stream.\
layout: 'portrait', layout: 'portrait',
}); });
if (imgType === 'png') { if (imgType === 'png') {
const imgDataUrlList = yield Promise.all(imgURLs.map(fetchDataURL)); const imgDataUrlList = yield Promise.all(imgBlobs.map(b => readData(b, 'dataUrl')));
imgDataUrlList.forEach((data) => { imgDataUrlList.forEach((data) => {
pdf.addPage(); pdf.addPage();
pdf.image(data, { pdf.image(data, {
@ -26479,7 +26481,7 @@ Please pipe the document into a Node stream.\
}); });
} }
else { // imgType == "svg" else { // imgType == "svg"
const svgList = yield Promise.all(imgURLs.map(fetchText)); const svgList = yield Promise.all(imgBlobs.map(b => readData(b, 'text')));
svgList.forEach((svg) => { svgList.forEach((svg) => {
pdf.addPage(); pdf.addPage();
source(pdf, svg, 0, 0, { source(pdf, svg, 0, 0, {
@ -26492,8 +26494,9 @@ Please pipe the document into a Node stream.\
return buf.buffer; return buf.buffer;
}); });
onmessage = (e) => __awaiter(void 0, void 0, void 0, function* () { onmessage = (e) => __awaiter(void 0, void 0, void 0, function* () {
const [imgURLs, imgType, width, height,] = e.data; const [imgUrls, imgType, width, height,] = e.data;
const pdfBuf = yield generatePDF(imgURLs, imgType, width, height); const imgBlobs = yield Promise.all(imgUrls.map(url => fetchBlob(url)));
const pdfBuf = yield generatePDF(imgBlobs, imgType, width, height);
postMessage(pdfBuf, [pdfBuf]); postMessage(pdfBuf, [pdfBuf]);
}); });

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "name": "musescore-downloader",
"version": "0.23.7", "version": "0.23.8",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "name": "musescore-downloader",
"version": "0.23.7", "version": "0.23.8",
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱", "description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱",
"main": "dist/main.js", "main": "dist/main.js",
"bin": "dist/cli.js", "bin": "dist/cli.js",