mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-17 18:11:20 -08:00
24 lines
879 B
TypeScript
24 lines
879 B
TypeScript
import type Artplayer from '../../artplayer/public/artplayer.ts'
|
|
import { createLibraryLoader, exampleSource, parameters } from './loader.ts'
|
|
|
|
declare global {
|
|
interface Window { Artplayer: typeof Artplayer }
|
|
}
|
|
|
|
window.Artplayer.DEBUG = true
|
|
const loader = createLibraryLoader()
|
|
window.addEventListener('pagehide', (event) => {
|
|
if (!event.persisted)
|
|
loader.dispose()
|
|
})
|
|
|
|
async function start(): Promise<void> {
|
|
const { code, libs, example } = parameters(location.href)
|
|
await loader.loadLibraries(libs)
|
|
const source = example ? await exampleSource(example) : code ? decodeURIComponent(code).trim() : await exampleSource('mobile')
|
|
// eslint-disable-next-line no-new-func -- Run user-selected example code in the existing classic-script function scope.
|
|
new Function(source)()
|
|
}
|
|
|
|
start().catch(error => console.error('Failed to initialize mobile example:', error))
|