修复无法使用的问题
This commit is contained in:
parent
1491cac295
commit
8f14934144
|
@ -1,7 +1,9 @@
|
|||
import "./meta"
|
||||
|
||||
import { ScorePlayerData } from "./types"
|
||||
import { getIndexPath } from "./utils"
|
||||
import { getIndexPath, waitForDocumentLoaded } from "./utils"
|
||||
|
||||
const main = () => {
|
||||
|
||||
// @ts-ignore
|
||||
const scorePlayer: ScorePlayerData = window.UGAPP.store.jmuse_settings.score_player
|
||||
|
@ -50,3 +52,7 @@ const newDownloadBtns = Object.keys(downloadURLs).map((name) => {
|
|||
})
|
||||
|
||||
downloadBtn.replaceWith(...newDownloadBtns)
|
||||
|
||||
}
|
||||
|
||||
waitForDocumentLoaded().then(main)
|
||||
|
|
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)
|
||||
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