musescore-downloader

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7e4b5e2c15b4c12793d0e2173c06d78eaaa2e8b9
parent 8f149341445afe2a7b42a163466ed109c9b164c9
Author: Xmader <xmader@outlook.com>
Date:   Fri, 29 Nov 2019 18:09:03 -0500

v0.1.7 - fix - #1

Diffstat:
Mdist/main.js | 91++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mpackage.json | 2+-
2 files changed, 56 insertions(+), 37 deletions(-)

diff --git a/dist/main.js b/dist/main.js @@ -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.1.6 +// @version 0.1.7 // @description 免登录、免 Musescore Pro,下载 musescore.com 上的曲谱 // @author Xmader // @match https://musescore.com/*/* @@ -20,48 +20,67 @@ const getIndexPath = (id) => { const idStr = String(id); // 获取最后三位,倒序排列 + // x, y, z are the reversed last digits of the score id. Example: id 123456789, x = 9, y = 8, z = 7 + // https://developers.musescore.com/#/file-urls // "5449062" -> ["2", "6", "0"] const indexN = idStr.split("").reverse().slice(0, 3); return indexN.join("/"); }; - - // @ts-ignore - const scorePlayer = window.UGAPP.store.jmuse_settings.score_player; - const { id, vid } = scorePlayer.json; - const baseURL = scorePlayer.urls.image_path; - const scoreHexId = baseURL.split("/").filter(Boolean).reverse()[0]; - const msczURL = `https://musescore.com/static/musescore/scoredata/score/${getIndexPath(id)}/${id}/score_${vid}_${scoreHexId}.mscz`; - const pdfURL = baseURL + "score_full.pdf"; - const mxlURL = baseURL + "score.mxl"; - const { midi: midiURL, mp3: mp3URL } = scorePlayer.urls; - const btnsDiv = document.querySelector(".score-right .buttons-wrapper") || document.querySelectorAll("aside section > div")[3]; - const downloadBtn = btnsDiv.querySelector("button, .button"); - downloadBtn.onclick = null; - const downloadURLs = { - "Musescore": msczURL, - "PDF": pdfURL, - "MusicXML": mxlURL, - "MIDI": midiURL, - "MP3": mp3URL, - }; - const newDownloadBtns = Object.keys(downloadURLs).map((name) => { - const url = downloadURLs[name]; - const btn = downloadBtn.cloneNode(true); - btn.onclick = () => { - window.open(url); - }; - if (btn.nodeName.toLowerCase() == "button") { - btn.setAttribute("style", "width: 205px !important"); + const waitForDocumentLoaded = () => { + if (document.readyState !== "complete") { + return new Promise(resolve => { + document.addEventListener("readystatechange", () => { + if (document.readyState == "complete") { + resolve(); + } + }, { once: true }); + }); } else { - btn.dataset.target = ""; + return Promise.resolve(); } - const span = [...btn.childNodes].find((x) => { - return x.textContent.includes("Download"); + }; + + const main = () => { + // @ts-ignore + const scorePlayer = window.UGAPP.store.jmuse_settings.score_player; + const { id, vid } = scorePlayer.json; + const baseURL = scorePlayer.urls.image_path; + const scoreHexId = baseURL.split("/").filter(Boolean).reverse()[0]; + const msczURL = `https://musescore.com/static/musescore/scoredata/score/${getIndexPath(id)}/${id}/score_${vid}_${scoreHexId}.mscz`; + const pdfURL = baseURL + "score_full.pdf"; + const mxlURL = baseURL + "score.mxl"; + const { midi: midiURL, mp3: mp3URL } = scorePlayer.urls; + const btnsDiv = document.querySelector(".score-right .buttons-wrapper") || document.querySelectorAll("aside section > div")[3]; + const downloadBtn = btnsDiv.querySelector("button, .button"); + downloadBtn.onclick = null; + const downloadURLs = { + "Musescore": msczURL, + "PDF": pdfURL, + "MusicXML": mxlURL, + "MIDI": midiURL, + "MP3": mp3URL, + }; + const newDownloadBtns = Object.keys(downloadURLs).map((name) => { + const url = downloadURLs[name]; + const btn = downloadBtn.cloneNode(true); + btn.onclick = () => { + window.open(url); + }; + if (btn.nodeName.toLowerCase() == "button") { + btn.setAttribute("style", "width: 205px !important"); + } + else { + btn.dataset.target = ""; + } + const span = [...btn.childNodes].find((x) => { + return x.textContent.includes("Download"); + }); + span.textContent = `Download ${name}`; + return btn; }); - span.textContent = `Download ${name}`; - return btn; - }); - downloadBtn.replaceWith(...newDownloadBtns); + downloadBtn.replaceWith(...newDownloadBtns); + }; + waitForDocumentLoaded().then(main); }()); diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "musescore-downloader", - "version": "0.1.6", + "version": "0.1.7", "description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱", "main": "dist/main.js", "repository": {