plugins/webamp: self-host the Webamp bundle (#23)

This commit was merged in pull request #23.
This commit is contained in:
teahubxyz committed 2026-10-22 18:34:38 +00:00
1 parent 6baa7127f9
commit 917f69fbce
3 files changed
+19 -5

No files matched your search

+4 -1
View File
@@ -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"
}
@@ -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(() => {
+1 -1
View File
@@ -1,2 +1,2 @@
{{/* teahub plugin: webamp */}}
<script type="module" nonce="{{ctx.CspScriptNonce}}" src="{{AssetUrlPrefix}}/plugins/webamp/webamp-mod.js?v=010" data-playlist="https://gandora.yolopreneur.lol/playlist.json"></script>
<script type="module" nonce="{{ctx.CspScriptNonce}}" src="{{AssetUrlPrefix}}/plugins/webamp/webamp-mod.js?v=011" data-playlist="https://gandora.yolopreneur.lol/playlist.json"></script>