v0.6.4 - show "Download Failed" instead of always "Processing"

This commit is contained in:
Xmader 2020-04-18 15:48:37 -04:00
parent 4b3dedb3e5
commit 4a54512ab2
3 changed files with 44 additions and 28 deletions

37
dist/main.js vendored
View File

@ -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.6.3
// @version 0.6.4
// @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱
// @author Xmader
// @match https://musescore.com/*/*
@ -28960,25 +28960,34 @@ Please pipe the document into a Node stream.\
const url = downloadURLs[name];
const { btn, textNode } = createBtn(name);
if (name == "PDF") {
btn.onclick = () => {
const text = textNode.textContent;
btn.onclick = () => __awaiter(void 0, void 0, void 0, function* () {
const filename = getScoreFileName(scorePlayer);
textNode.textContent = "Processing…";
generatePDF(sheetImgURLs, imgType, filename).then(() => {
textNode.textContent = text;
});
};
try {
yield generatePDF(sheetImgURLs, imgType, filename);
textNode.textContent = "Download PDF";
}
catch (err) {
textNode.textContent = "❌Download Failed!";
console.error(err);
}
});
}
else if (name == "MSCZ") {
btn.onclick = () => __awaiter(void 0, void 0, void 0, function* () {
const text = textNode.textContent;
textNode.textContent = "Processing…";
const token = yield execute();
const filename = getScoreFileName(scorePlayer);
const r = yield fetch(url + token);
const data = yield r.blob();
textNode.textContent = text;
saveAs(data, `${filename}.mscz`);
try {
const token = yield execute();
const filename = getScoreFileName(scorePlayer);
const r = yield fetch(url + token);
const data = yield r.blob();
textNode.textContent = "Download MSCZ";
saveAs(data, `${filename}.mscz`);
}
catch (err) {
textNode.textContent = "❌Download Failed!";
console.error(err);
}
});
}
else {

View File

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

View File

@ -88,7 +88,7 @@ const main = () => {
// fix the icon of the download btn
// if the `downloadBtn` seleted was a `Print` btn, replace the `print` icon with the `download` icon
const svgPath: SVGPathElement = downloadBtn.querySelector("svg > path")
if(svgPath) {
if (svgPath) {
svgPath.setAttribute("d", "M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z")
}
@ -131,30 +131,37 @@ const main = () => {
const { btn, textNode } = createBtn(name)
if (name == "PDF") {
btn.onclick = () => {
const text = textNode.textContent
btn.onclick = async () => {
const filename = getScoreFileName(scorePlayer)
textNode.textContent = "Processing…"
generatePDF(sheetImgURLs, imgType, filename).then(() => {
textNode.textContent = text
})
try {
await generatePDF(sheetImgURLs, imgType, filename)
textNode.textContent = "Download PDF"
} catch (err) {
textNode.textContent = "❌Download Failed!"
console.error(err)
}
}
} else if (name == "MSCZ") {
btn.onclick = async () => {
const text = textNode.textContent
textNode.textContent = "Processing…"
const token = await recaptcha.execute()
const filename = getScoreFileName(scorePlayer)
try {
const token = await recaptcha.execute()
const filename = getScoreFileName(scorePlayer)
const r = await fetch(url + token)
const data = await r.blob()
const r = await fetch(url + token)
const data = await r.blob()
textNode.textContent = text
textNode.textContent = "Download MSCZ"
saveAs(data, `${filename}.mscz`)
saveAs(data, `${filename}.mscz`)
} catch (err) {
textNode.textContent = "❌Download Failed!"
console.error(err)
}
}
} else {
btn.onclick = () => {