diff --git a/plugins/webamp/plugin.json b/plugins/webamp/plugin.json index d644739..6d8cf1b 100644 --- a/plugins/webamp/plugin.json +++ b/plugins/webamp/plugin.json @@ -1,12 +1,15 @@ { "name": "webamp", "title": "Webamp", - "version": "0.1.0", + "version": "0.1.1", "description": "A Winamp-style player on every Teahub page, fed by gandora.", "slots": { "footer": "templates/custom/footer.tmpl" }, "assets": ["public/assets/plugins/webamp/webamp-mod.js"], + "vendor": { + "public/assets/plugins/webamp/webamp.bundle.min.js": "https://registry.npmjs.org/webamp/-/webamp-1.5.0.tgz#package/built/webamp.bundle.min.js" + }, "config": { "playlist_url": "https://gandora.yolopreneur.lol/playlist.json" } diff --git a/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js b/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js index 931b9c8..71b0860 100644 --- a/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js +++ b/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js @@ -1,7 +1,7 @@ // teahub plugin: webamp — a Winamp-style player docked on every Teahub page. -// Loads Webamp from the CDN on first click, so pages stay fast for everyone else. +// Loads the self-hosted Webamp bundle on first click, so pages stay fast for everyone else. -// Module scripts have no document.currentScript, so find our tag by its data attribute. +// Module scripts have no document.currentScript, so find our tag by its src. const script = document.querySelector('script[src*="plugins/webamp/webamp-mod.js"]'); const PLAYLIST_URL = script?.dataset.playlist; const KEY = 'teahub-webamp-open'; @@ -36,9 +36,20 @@ async function loadTracks() { let webamp = null; +function loadWebamp() { + if (window.Webamp) return Promise.resolve(window.Webamp); + return new Promise((ok, fail) => { + const s = document.createElement('script'); + s.src = new URL('webamp.bundle.min.js', import.meta.url).href; + s.onload = () => ok(window.Webamp); + s.onerror = fail; + document.head.appendChild(s); + }); +} + async function open() { if (webamp) return; - const { default: Webamp } = await import('https://unpkg.com/webamp@1.5.0/built/webamp.bundle.min.mjs'); + const Webamp = await loadWebamp(); if (!Webamp.browserIsSupported()) return; webamp = new Webamp({ initialTracks: await loadTracks() }); webamp.onClose(() => { diff --git a/plugins/webamp/templates/custom/footer.tmpl b/plugins/webamp/templates/custom/footer.tmpl index 770cec0..4a97501 100644 --- a/plugins/webamp/templates/custom/footer.tmpl +++ b/plugins/webamp/templates/custom/footer.tmpl @@ -1,2 +1,2 @@ {{/* teahub plugin: webamp */}} - +