musescore-downloader/src/main.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-11-03 19:13:06 +00:00
import "./meta"
import { ScorePlayerData } from "./types"
import { getIndexPath } from "./utils"
// @ts-ignore
const scorePlayer: ScorePlayerData = 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]
2019-11-03 19:13:06 +00:00
2019-11-03 20:01:29 +00:00
const msczURL = `https://musescore.com/static/musescore/scoredata/score/${getIndexPath(id)}/${id}/score_${vid}_${scoreHexId}.mscz`
2019-11-03 19:13:06 +00:00
const pdfURL = baseURL + "score_full.pdf"
const mxlURL = baseURL + "score.mxl"
const { midi: midiURL, mp3: mp3URL } = scorePlayer.urls
2019-11-03 20:21:59 +00:00
const btnsDiv = document.querySelector(".score-right .buttons-wrapper") || document.querySelectorAll("aside section > div")[3]
const downloadBtn = btnsDiv.querySelector("button, .button") as HTMLElement
2019-11-03 19:13:06 +00:00
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]
2019-11-03 20:21:59 +00:00
const btn = downloadBtn.cloneNode(true) as HTMLElement
2019-11-03 19:13:06 +00:00
btn.onclick = () => {
window.open(url)
}
2019-11-03 20:21:59 +00:00
if (btn.nodeName.toLowerCase() == "button") {
btn.setAttribute("style", "width: 205px !important")
2019-11-03 20:24:58 +00:00
} else {
btn.dataset.target = ""
2019-11-03 20:21:59 +00:00
}
2019-11-03 20:21:59 +00:00
const span = [...btn.childNodes].find((x) => {
return x.textContent.includes("Download")
})
2019-11-03 20:01:29 +00:00
span.textContent = `Download ${name}`
2019-11-03 19:13:06 +00:00
return btn
})
downloadBtn.replaceWith(...newDownloadBtns)