This commit is contained in:
Xmader 2020-11-13 01:27:15 -05:00
parent e98d639000
commit 94305ff964
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
3 changed files with 35 additions and 12 deletions

43
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.14.6 // @version 0.15.0
// @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/*/*
@ -220,6 +220,17 @@
const data = yield r.arrayBuffer(); const data = yield r.arrayBuffer();
return new Uint8Array(data); return new Uint8Array(data);
}); });
const useTimeout = (promise, ms) => __awaiter(void 0, void 0, void 0, function* () {
if (!(promise instanceof Promise)) {
return promise;
}
return new Promise((resolve, reject) => {
const i = setTimeout(() => {
reject(new Error('timeout'));
}, ms);
promise.then(resolve, reject).finally(() => clearTimeout(i));
});
});
const waitForDocumentLoaded = () => { const waitForDocumentLoaded = () => {
if (document.readyState !== 'complete') { if (document.readyState !== 'complete') {
return new Promise(resolve => { return new Promise(resolve => {
@ -26876,13 +26887,13 @@ Please pipe the document into a Node stream.\
window.open(yield normalizeUrlInput(url)); window.open(yield normalizeUrlInput(url));
})); }));
}; };
BtnAction.download = (url) => { BtnAction.download = (url, fallback, timeout) => {
return BtnAction.process(() => __awaiter(this, void 0, void 0, function* () { return BtnAction.process(() => __awaiter(this, void 0, void 0, function* () {
const _url = yield normalizeUrlInput(url); const _url = yield normalizeUrlInput(url);
const a = document.createElement('a'); const a = document.createElement('a');
a.href = _url; a.href = _url;
a.dispatchEvent(new MouseEvent('click')); a.dispatchEvent(new MouseEvent('click'));
})); }), fallback, timeout);
}; };
BtnAction.mscoreWindow = (fn) => { BtnAction.mscoreWindow = (fn) => {
return (btnName, btn, setText) => __awaiter(this, void 0, void 0, function* () { return (btnName, btn, setText) => __awaiter(this, void 0, void 0, function* () {
@ -26910,18 +26921,25 @@ Please pipe the document into a Node stream.\
fn(w, score, txt); fn(w, score, txt);
}); });
}; };
BtnAction.process = (fn) => { BtnAction.process = (fn, fallback, timeout = Infinity) => {
return (name, btn, setText) => __awaiter(this, void 0, void 0, function* () { return (name, btn, setText) => __awaiter(this, void 0, void 0, function* () {
const _onclick = btn.onclick; const _onclick = btn.onclick;
btn.onclick = null; btn.onclick = null;
setText(i18n('PROCESSING')()); setText(i18n('PROCESSING')());
try { try {
yield fn(); yield useTimeout(fn(), timeout);
setText(name); setText(name);
} }
catch (err) { catch (err) {
setText(i18n('BTN_ERROR')());
console.error(err); console.error(err);
if (fallback) {
// use fallback
yield fallback();
setText(name);
}
else {
setText(i18n('BTN_ERROR')());
}
} }
btn.onclick = _onclick; btn.onclick = _onclick;
}); });
@ -26938,13 +26956,18 @@ Please pipe the document into a Node stream.\
const main = () => { const main = () => {
const btnList = new BtnList(); const btnList = new BtnList();
const filename = scoreinfo.fileName; const filename = scoreinfo.fileName;
let indvPartBtn = null;
const fallback = () => {
// btns fallback to load from MSCZ file (`Individual Parts`)
return indvPartBtn === null || indvPartBtn === void 0 ? void 0 : indvPartBtn.click();
};
btnList.add({ btnList.add({
name: i18n('DOWNLOAD')('MSCZ'), name: i18n('DOWNLOAD')('MSCZ'),
action: BtnAction.process(downloadMscz), action: BtnAction.process(downloadMscz),
}); });
btnList.add({ btnList.add({
name: i18n('DOWNLOAD')('PDF'), name: i18n('DOWNLOAD')('PDF'),
action: BtnAction.process(downloadPDF), action: BtnAction.process(downloadPDF, fallback, 3 * 60 * 1000 /* 3min */),
}); });
btnList.add({ btnList.add({
name: i18n('DOWNLOAD')('MusicXML'), name: i18n('DOWNLOAD')('MusicXML'),
@ -26957,13 +26980,13 @@ Please pipe the document into a Node stream.\
}); });
btnList.add({ btnList.add({
name: i18n('DOWNLOAD')('MIDI'), name: i18n('DOWNLOAD')('MIDI'),
action: BtnAction.download(() => getFileUrl('midi')), action: BtnAction.download(() => getFileUrl('midi'), fallback, 30 * 1000 /* 30s */),
}); });
btnList.add({ btnList.add({
name: i18n('DOWNLOAD')('MP3'), name: i18n('DOWNLOAD')('MP3'),
action: BtnAction.download(() => getFileUrl('mp3')), action: BtnAction.download(() => getFileUrl('mp3'), fallback, 30 * 1000 /* 30s */),
}); });
btnList.add({ indvPartBtn = btnList.add({
name: i18n('IND_PARTS')(), name: i18n('IND_PARTS')(),
tooltip: i18n('IND_PARTS_TOOLTIP')(), tooltip: i18n('IND_PARTS_TOOLTIP')(),
action: BtnAction.mscoreWindow((w, score, txt) => __awaiter(void 0, void 0, void 0, function* () { action: BtnAction.mscoreWindow((w, score, txt) => __awaiter(void 0, void 0, void 0, function* () {

2
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "name": "musescore-downloader",
"version": "0.14.6", "version": "0.15.0",
"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": {