This commit is contained in:
Xmader 2020-09-27 12:21:27 -04:00
parent 9a0f51fa15
commit a11e92a1de
2 changed files with 93 additions and 74 deletions

161
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.7.3 // @version 0.8.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/*/*
@ -26311,6 +26311,7 @@ Please pipe the document into a Node stream.\
const scoreinfo = { const scoreinfo = {
get playerdata() { get playerdata() {
// @ts-ignore // @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return window.UGAPP.store.jmuse_settings.score_player; return window.UGAPP.store.jmuse_settings.score_player;
}, },
get id() { get id() {
@ -26349,7 +26350,7 @@ Please pipe the document into a Node stream.\
}, },
get msczUrl() { get msczUrl() {
// https://github.com/Xmader/cloudflare-worker-musescore-mscz // https://github.com/Xmader/cloudflare-worker-musescore-mscz
return `https://mscz.librescore.org/?id=${this.id}&name=${this.fileName}&token=`; return `https://musescore.now.sh/api/mscz?id=${this.id}&token=`;
}, },
get sheetImgType() { get sheetImgType() {
try { try {
@ -26367,7 +26368,7 @@ Please pipe the document into a Node stream.\
}; };
let pdfBlob; let pdfBlob;
const _downloadPDF = (imgURLs, imgType, name) => __awaiter(void 0, void 0, void 0, function* () { const _downloadPDF = (imgURLs, imgType, name = '') => __awaiter(void 0, void 0, void 0, function* () {
if (pdfBlob) { if (pdfBlob) {
return saveAs(pdfBlob, `${name}.pdf`); return saveAs(pdfBlob, `${name}.pdf`);
} }
@ -26443,6 +26444,26 @@ Please pipe the document into a Node stream.\
saveAs(data, `${filename}.mscz`); saveAs(data, `${filename}.mscz`);
}); });
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.10/webmscore.js';
const initMscore = (w) => __awaiter(void 0, void 0, void 0, function* () {
if (!w['WebMscore']) {
// init webmscore (https://github.com/LibreScore/webmscore)
const script = w.document.createElement('script');
script.src = WEBMSCORE_URL;
w.document.body.append(script);
yield new Promise(resolve => { script.onload = resolve; });
}
});
const loadMscore = (w) => __awaiter(void 0, void 0, void 0, function* () {
yield initMscore(w);
const WebMscore = w['WebMscore'];
// parse mscz data
const data = new Uint8Array(new Uint8Array(yield fetchMscz()));
const score = yield WebMscore.load('mscz', data);
yield score.generateExcerpts();
return score;
});
/** /**
* Select the original Download Button * Select the original Download Button
*/ */
@ -26500,58 +26521,8 @@ Please pipe the document into a Node stream.\
BtnAction.openUrl = (url) => { BtnAction.openUrl = (url) => {
return () => window.open(url); return () => window.open(url);
}; };
BtnAction.process = (fn) => { BtnAction.mscoreWindow = (fn) => {
return (name, btn, setText) => __awaiter(this, void 0, void 0, function* () { return (btnName, btn, setText) => __awaiter(this, void 0, void 0, function* () {
const _onclick = btn.onclick;
btn.onclick = null;
setText(BtnAction.PROCESSING_TEXT);
try {
yield fn();
setText(name);
}
catch (err) {
setText(BtnAction.ERROR_TEXT);
console.error(err);
}
btn.onclick = _onclick;
});
};
})(BtnAction || (BtnAction = {}));
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.5/webmscore.js';
const main = () => {
// @ts-ignore
if (!window.UGAPP || !window.UGAPP.store || !window.UGAPP.store.jmuse_settings) {
return;
}
// init recaptcha
// eslint-disable-next-line @typescript-eslint/no-floating-promises
init();
const btnList = new BtnList(getDownloadBtn());
btnList.add({
name: 'Download MSCZ',
action: BtnAction.process(downloadMscz),
});
btnList.add({
name: 'Download PDF',
action: BtnAction.process(downloadPDF),
});
btnList.add({
name: 'Download MusicXML',
action: BtnAction.openUrl(scoreinfo.mxlUrl),
});
btnList.add({
name: 'Download MIDI',
action: BtnAction.openUrl(scoreinfo.midiUrl),
});
btnList.add({
name: 'Download MP3',
action: BtnAction.openUrl(scoreinfo.mp3Url),
});
btnList.add({
name: 'Individual Parts',
action(btnName, btn, setText) {
return __awaiter(this, void 0, void 0, function* () {
const _onclick = btn.onclick; const _onclick = btn.onclick;
btn.onclick = null; btn.onclick = null;
setText(BtnAction.PROCESSING_TEXT); setText(BtnAction.PROCESSING_TEXT);
@ -26572,22 +26543,71 @@ Please pipe the document into a Node stream.\
setText(btnName); setText(btnName);
btn.onclick = _onclick; btn.onclick = _onclick;
}); });
// load webmscore (https://github.com/LibreScore/webmscore) score = yield loadMscore(w);
const script = w.document.createElement('script'); fn(w, score, txt);
script.src = WEBMSCORE_URL; });
w.document.body.append(script); };
yield new Promise(resolve => { script.onload = resolve; }); BtnAction.process = (fn) => {
// parse mscz data return (name, btn, setText) => __awaiter(this, void 0, void 0, function* () {
const data = new Uint8Array(new Uint8Array(yield fetchMscz()) // copy its ArrayBuffer const _onclick = btn.onclick;
); btn.onclick = null;
score = yield w['WebMscore'].load('mscz', data); setText(BtnAction.PROCESSING_TEXT);
yield score.generateExcerpts(); try {
yield fn();
setText(name);
}
catch (err) {
setText(BtnAction.ERROR_TEXT);
console.error(err);
}
btn.onclick = _onclick;
});
};
})(BtnAction || (BtnAction = {}));
const main = () => {
// @ts-ignore
if (!window.UGAPP || !window.UGAPP.store || !window.UGAPP.store.jmuse_settings) {
return;
}
// init recaptcha
// eslint-disable-next-line @typescript-eslint/no-floating-promises
init();
const btnList = new BtnList(getDownloadBtn());
btnList.add({
name: 'Download MSCZ',
action: BtnAction.process(downloadMscz),
});
btnList.add({
name: 'Download PDF',
action: BtnAction.process(downloadPDF),
});
btnList.add({
name: 'Download MusicXML',
action: BtnAction.mscoreWindow((w, score) => __awaiter(void 0, void 0, void 0, function* () {
const mxl = yield score.saveMxl();
const data = new Blob([mxl]);
saveAs(data, `${scoreinfo.fileName}.mxl`);
w.close();
})),
});
btnList.add({
name: 'Download MIDI',
action: BtnAction.openUrl(scoreinfo.midiUrl),
});
btnList.add({
name: 'Download MP3',
action: BtnAction.openUrl(scoreinfo.mp3Url),
});
btnList.add({
name: 'Individual Parts',
action: BtnAction.mscoreWindow((w, score, txt) => __awaiter(void 0, void 0, void 0, function* () {
const metadata = yield score.metadata(); const metadata = yield score.metadata();
console.log('score metadata loaded by webmscore', metadata); console.log('score metadata loaded by webmscore', metadata);
// render the part selection page // render the part selection page
txt.remove(); txt.remove();
const fieldset = w.document.createElement('fieldset'); const fieldset = w.document.createElement('fieldset');
metadata.excerpts.unshift({ id: -1, title: 'Full score' }); metadata.excerpts.unshift({ id: -1, title: 'Full score', parts: [] });
for (const excerpt of metadata.excerpts) { for (const excerpt of metadata.excerpts) {
const id = excerpt.id; const id = excerpt.id;
const partName = excerpt.title; const partName = excerpt.title;
@ -26595,7 +26615,7 @@ Please pipe the document into a Node stream.\
e.name = 'score-part'; e.name = 'score-part';
e.type = 'radio'; e.type = 'radio';
e.alt = partName; e.alt = partName;
e.value = id; e.value = id.toString();
e.checked = id === 0; // initially select the first part e.checked = id === 0; // initially select the first part
const label = w.document.createElement('label'); const label = w.document.createElement('label');
label.innerText = partName; label.innerText = partName;
@ -26607,17 +26627,16 @@ Please pipe the document into a Node stream.\
submitBtn.value = 'Download PDF'; submitBtn.value = 'Download PDF';
fieldset.append(submitBtn); fieldset.append(submitBtn);
w.document.body.append(fieldset); w.document.body.append(fieldset);
submitBtn.onclick = () => __awaiter(this, void 0, void 0, function* () { submitBtn.onclick = () => __awaiter(void 0, void 0, void 0, function* () {
const checked = fieldset.querySelector('input:checked'); const checked = fieldset.querySelector('input:checked');
const id = checked.value; const id = checked.value;
const partName = checked.alt; const partName = checked.alt;
yield score.setExcerptId(id); yield score.setExcerptId(+id);
const filename = scoreinfo.fileName; const filename = scoreinfo.fileName;
const data = new Blob([yield score.savePdf()]); const data = new Blob([yield score.savePdf()]);
saveAs(data, `${filename} - ${partName}.pdf`); saveAs(data, `${filename} - ${partName}.pdf`);
}); });
}); })),
},
}).title = 'Download individual parts (BETA)'; }).title = 'Download individual parts (BETA)';
btnList.commit(); btnList.commit();
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "name": "musescore-downloader",
"version": "0.7.3", "version": "0.8.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": {
@ -16,7 +16,7 @@
"dependencies": { "dependencies": {
"pdfkit": "git+https://github.com/Xmader/pdfkit.git", "pdfkit": "git+https://github.com/Xmader/pdfkit.git",
"svg-to-pdfkit": "^0.1.8", "svg-to-pdfkit": "^0.1.8",
"webmscore": "^0.5.0" "webmscore": "^0.10.4"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-json": "^4.0.0", "@rollup/plugin-json": "^4.0.0",