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/ // @namespace https://www.xmader.com/
// @homepageURL https://github.com/Xmader/musescore-downloader/ // @homepageURL https://github.com/Xmader/musescore-downloader/
// @supportURL https://github.com/Xmader/musescore-downloader/issues // @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 上的曲谱 // @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/*/*
@ -28960,25 +28960,34 @@ Please pipe the document into a Node stream.\
const url = downloadURLs[name]; const url = downloadURLs[name];
const { btn, textNode } = createBtn(name); const { btn, textNode } = createBtn(name);
if (name == "PDF") { if (name == "PDF") {
btn.onclick = () => { btn.onclick = () => __awaiter(void 0, void 0, void 0, function* () {
const text = textNode.textContent;
const filename = getScoreFileName(scorePlayer); const filename = getScoreFileName(scorePlayer);
textNode.textContent = "Processing…"; textNode.textContent = "Processing…";
generatePDF(sheetImgURLs, imgType, filename).then(() => { try {
textNode.textContent = text; yield generatePDF(sheetImgURLs, imgType, filename);
}); textNode.textContent = "Download PDF";
}; }
catch (err) {
textNode.textContent = "❌Download Failed!";
console.error(err);
}
});
} }
else if (name == "MSCZ") { else if (name == "MSCZ") {
btn.onclick = () => __awaiter(void 0, void 0, void 0, function* () { btn.onclick = () => __awaiter(void 0, void 0, void 0, function* () {
const text = textNode.textContent;
textNode.textContent = "Processing…"; textNode.textContent = "Processing…";
const token = yield execute(); try {
const filename = getScoreFileName(scorePlayer); const token = yield execute();
const r = yield fetch(url + token); const filename = getScoreFileName(scorePlayer);
const data = yield r.blob(); const r = yield fetch(url + token);
textNode.textContent = text; const data = yield r.blob();
saveAs(data, `${filename}.mscz`); textNode.textContent = "Download MSCZ";
saveAs(data, `${filename}.mscz`);
}
catch (err) {
textNode.textContent = "❌Download Failed!";
console.error(err);
}
}); });
} }
else { else {

View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "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 上的曲谱", "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",
"repository": { "repository": {

View File

@ -88,7 +88,7 @@ const main = () => {
// fix the icon of the download btn // fix the icon of the download btn
// if the `downloadBtn` seleted was a `Print` btn, replace the `print` icon with the `download` icon // if the `downloadBtn` seleted was a `Print` btn, replace the `print` icon with the `download` icon
const svgPath: SVGPathElement = downloadBtn.querySelector("svg > path") 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") 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) const { btn, textNode } = createBtn(name)
if (name == "PDF") { if (name == "PDF") {
btn.onclick = () => { btn.onclick = async () => {
const text = textNode.textContent
const filename = getScoreFileName(scorePlayer) const filename = getScoreFileName(scorePlayer)
textNode.textContent = "Processing…" textNode.textContent = "Processing…"
generatePDF(sheetImgURLs, imgType, filename).then(() => { try {
textNode.textContent = text await generatePDF(sheetImgURLs, imgType, filename)
}) textNode.textContent = "Download PDF"
} catch (err) {
textNode.textContent = "❌Download Failed!"
console.error(err)
}
} }
} else if (name == "MSCZ") { } else if (name == "MSCZ") {
btn.onclick = async () => { btn.onclick = async () => {
const text = textNode.textContent
textNode.textContent = "Processing…" textNode.textContent = "Processing…"
const token = await recaptcha.execute() try {
const filename = getScoreFileName(scorePlayer) const token = await recaptcha.execute()
const filename = getScoreFileName(scorePlayer)
const r = await fetch(url + token) const r = await fetch(url + token)
const data = await r.blob() 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 { } else {
btn.onclick = () => { btn.onclick = () => {