修复无法使用的问题
This commit is contained in:
parent
1491cac295
commit
8f14934144
90
src/main.ts
90
src/main.ts
|
@ -1,52 +1,58 @@
|
||||||
import "./meta"
|
import "./meta"
|
||||||
|
|
||||||
import { ScorePlayerData } from "./types"
|
import { ScorePlayerData } from "./types"
|
||||||
import { getIndexPath } from "./utils"
|
import { getIndexPath, waitForDocumentLoaded } from "./utils"
|
||||||
|
|
||||||
// @ts-ignore
|
const main = () => {
|
||||||
const scorePlayer: ScorePlayerData = window.UGAPP.store.jmuse_settings.score_player
|
|
||||||
|
|
||||||
const { id, vid } = scorePlayer.json
|
// @ts-ignore
|
||||||
const baseURL = scorePlayer.urls.image_path
|
const scorePlayer: ScorePlayerData = window.UGAPP.store.jmuse_settings.score_player
|
||||||
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 { id, vid } = scorePlayer.json
|
||||||
const pdfURL = baseURL + "score_full.pdf"
|
const baseURL = scorePlayer.urls.image_path
|
||||||
const mxlURL = baseURL + "score.mxl"
|
const scoreHexId = baseURL.split("/").filter(Boolean).reverse()[0]
|
||||||
const { midi: midiURL, mp3: mp3URL } = scorePlayer.urls
|
|
||||||
|
|
||||||
const btnsDiv = document.querySelector(".score-right .buttons-wrapper") || document.querySelectorAll("aside section > div")[3]
|
const msczURL = `https://musescore.com/static/musescore/scoredata/score/${getIndexPath(id)}/${id}/score_${vid}_${scoreHexId}.mscz`
|
||||||
const downloadBtn = btnsDiv.querySelector("button, .button") as HTMLElement
|
const pdfURL = baseURL + "score_full.pdf"
|
||||||
downloadBtn.onclick = null
|
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") as HTMLElement
|
||||||
|
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) as HTMLElement
|
||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
|
downloadBtn.replaceWith(...newDownloadBtns)
|
||||||
|
|
||||||
const downloadURLs = {
|
|
||||||
"Musescore": msczURL,
|
|
||||||
"PDF": pdfURL,
|
|
||||||
"MusicXML": mxlURL,
|
|
||||||
"MIDI": midiURL,
|
|
||||||
"MP3": mp3URL,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newDownloadBtns = Object.keys(downloadURLs).map((name) => {
|
waitForDocumentLoaded().then(main)
|
||||||
const url = downloadURLs[name]
|
|
||||||
|
|
||||||
const btn = downloadBtn.cloneNode(true) as HTMLElement
|
|
||||||
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
|
|
||||||
})
|
|
||||||
|
|
||||||
downloadBtn.replaceWith(...newDownloadBtns)
|
|
||||||
|
|
14
src/utils.ts
14
src/utils.ts
|
@ -8,3 +8,17 @@ export const getIndexPath = (id: number) => {
|
||||||
const indexN = idStr.split("").reverse().slice(0, 3)
|
const indexN = idStr.split("").reverse().slice(0, 3)
|
||||||
return indexN.join("/")
|
return indexN.join("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const waitForDocumentLoaded = (): Promise<void> => {
|
||||||
|
if (document.readyState !== "complete") {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
document.addEventListener("readystatechange", () => {
|
||||||
|
if (document.readyState == "complete") {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}, { once: true })
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue