musescore-downloader/src/utils.ts

25 lines
810 B
TypeScript
Raw Normal View History

2019-11-03 19:13:06 +00:00
export const getIndexPath = (id: number) => {
const idStr = String(id)
// 获取最后三位,倒序排列
2019-11-12 02:44:47 +00:00
// 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
2019-11-03 19:13:06 +00:00
// "5449062" -> ["2", "6", "0"]
const indexN = idStr.split("").reverse().slice(0, 3)
return indexN.join("/")
}
2019-11-29 23:07:43 +00:00
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()
}
}