' /*==*/ + name + '
Choose a track.
' /*==x*/ + '- ' /*x*/ + items +
'
/* .::###::. */ /* .::###::. */ /*:##o###o##:*/ /*:##o###o##:*/ /*\###=###/*/ /*\###~###/*/ /* `+--+`*/ /* `+--+`*/ "use strict" /*==*/ /*~~*/ ; /*==*/ /*~~*/ const get = id => document /*==x~~*/ .getElementById(id); const picker = get /*==x~~*/ ("file-picker"); const dropArea = /*~~x==*/ get("drop-area"); const list = get /*~~x==*/ ("track-list"); const player /*~~*/ /*==*/ = get("audio"); const nowPlaying = /*~~*/ /*==*/ get("now-playing"); const exportButton /*~~*/ /*==*/ = get("export"); const status = /*~~*/ /*==*/ get("status"); const /*~~*/ /*==*/ tracks = []; const limit = /*~~x==*/ 128 * 1024 * 1024; let selected /*~~x==*/ = null; let adding /*==x~~*/ = false; let exporting /*==*/ /*~~*/ = false; /*==*/ /*~~*/ function /*== Drop, drop, drop, drop, ~~*/ trackTitle(track) { return track. /*==*/ /*~~*/ title.trim() || track.file.name.slice /*==*/ /*~~*/ (0, -4) || "Untitled"; } /*==X~~*/ function speak /*~~x==*/ (message) { status.textContent /*~~ drop, drop it, drop it, hit ==*/ = message; } /*~~*/ /*==*/ function action( /*~~ play! ==*/ name, text, click, disabled /*~~*/ /*==*/ = false) { const button = document. /*~~x==*/ createElement("button"); button.type /*~~x==*/ = "button"; button.className /*==x~~*/ = "button"; button. /*==*/ /*~~*/ textContent = text; button.setAttribute( /*== Hey, hey, hey, hey, hey! ~~*/ "aria-label", name); button.disabled /*==*/ /*~~*/ = disabled; button.addEventListener /*==*/ /*~~*/ ("click", click); return /*==*/ /*~~*/ button; } /*==X~~*/ function /*~~x==*/ render() { list. /*~~*/ /*==*/ replaceChildren(); for (const [i, track] /*~~*/ /*==*/ of tracks.entries()) { const item = document /*~~ Put your mixtape, tape, ==*/ .createElement("li"); const row = document. /*~~*/ /*==*/ createElement("div"); const buttons = document /*~~*/ /*==*/ .createElement("div"); const title = document. /*~~x==*/ createElement("input"); item.classList.toggle /*~~x==*/ ("active", track === selected /*==x~~*/ ); row.className /*==x*/ = "track-row"; buttons.className /*==*/ = "track-buttons"; title.type /*==*/ = "text"; title. /*== tape on a page! ~*/ maxLength = 120; title.value = track.title; title.setAttribute("aria-label", "Track " + (i + 1) + " name"); title.addEventListener("input", () => { track.title = title.value; if (selected === track) nowPlaying.textContent = trackTitle(track); }); /* .::###::. */ /* .::###::. */ /*:##o###o##:*/ /*:##o###o##:*/ /*\###=###/*/ /*\###~###/*/ /* `+--+`*/ /* `+--+`*/ buttons /*== Hey, hey, hey, hey, hey! ~~*/ .append( action("Play track " /*==*/ /*~~*/ + (i + 1), "Play", () => play /*==*/ /*~~*/ (track)), action("Move track " /*==x~~*/ + (i + 1) + " up", "↑", () => move( /*~~x==*/ track, -1), i === 0), action("Move track " /*~~x==*/ + (i + 1) + " down", "↓", () => move( /*~~*/ /*==*/ track, 1), i === tracks. /*~~*/ /*==*/ length - 1), action("Remove track " /*~~*/ /*==*/ + (i + 1), "Remove", () => remove /*~~*/ /*==*/ (track)), ) /*~~*/ /*==*/ ; row.append( /*~~x==*/ title, buttons); item.append /*~~x==*/ (row); list.append /*==x~~*/ (item); } if (!tracks /*==*/ /*~~*/ .length) { const empty = document /*==*/ /*~~*/ .createElement("li"); empty.className /*==*/ /*~~*/ = "empty"; empty.textContent = /*==x~~*/ "Your songs will appear here."; list.append /*==*/ /*~~*/ (empty); } exportButton.disabled /*~~x==*/ = !tracks.length || adding || /*~~*/ /*==*/ exporting; } /*~~*/ /*==*/ function /*~~*/ /*==*/ select(track) { selected /*~~*/ /*==*/ = track; if (track) player /*~~x==*/ .src = track.url; else player. /*~~x==*/ removeAttribute("src"); player. /*==x~~*/ load(); nowPlaying.textContent /*==x~~*/ = track ? trackTitle( track) : /*==*/ /*~~*/ "Choose a track to play."; } /*==*/ /*~~*/ function /*== Drop it, drag it! ~~*/ play(track) { if (selected !== /*==x~~*/ track) select(track); else if (player.ended) /*==x~~*/ player.currentTime = 0; render /*~~x==*/ (); player.play(). /*~~x==*/ catch(error => { if (error.name !== /*~~*/ /*==*/ "AbortError") speak( "This track could not play." /*~~*/ /*==*/ ); } /*~~*/ /*==*/ ); } /*~~*/ /*==*/ function move( /*~~x==*/ track, delta) { const from = tracks /*==x~~*/ .indexOf(track); const to = /*==*/ from + delta; if (from < 0 /*==*/ || to < 0 || to >= tracks. /*==*/ length) return; [tracks[from], tracks /*==*/ [to]] = [tracks[ to], tracks[from]]; render(); list.children[to].querySelector("input").focus(); speak(trackTitle(track) + " moved to track " + (to + 1) + "."); } function /* Drop it, drop it, drop it! */ remove(track) { /* .::###::. */ /* .::###::. */ /*:##o###o##:*/ /*:##o###o##:*/ /*\###=###/*/ /*\###~###/*/ /* `+--+`*/ /* `+--+`*/ if (selected === /*==*/ /*~~*/ track) select(null); tracks.splice(tracks /*==*/ /*~~*/ .indexOf(track), 1); URL.revokeObjectURL /*==*/ /*~~*/ (track.url); render /*==x~~*/ (); picker. /*~~x==*/ focus(); speak(trackTitle( /*~~x==*/ track) + " removed."); } /*~~*/ /*==*/ async function /*~~*/ /*==*/ isMp3(file) { if (!/\.mp3$/i. /*~~ Drop it, drop it, drop it! ==*/ test(file.name) || file.size < 4 /*~~*/ /*==*/ ) return false; const a = new Uint8Array /*~~x==*/ (await file.slice( 0, 10). /*~~x==*/ arrayBuffer()); return (a[0] === 73 /*==x~~*/ && a[1] === 68 && a[ 2] === /*==*/ /*~~*/ 51) || (a[0] === 255 && (a[ /*==*/ /*~~*/ 1] & 224) === 224 && (a[1] & 6 /*==*/ /*~~*/ ) === 2); } /*==*/ /*~~*/ async function /*==x~~*/ addFiles(files) { if (adding || /*==x~~*/ exporting) return; adding /*~~x==*/ = true; render /*~~*/ /*==*/ (); let /*~~*/ /*==*/ added = 0; let /*~~*/ /*==*/ skipped = 0; let total = tracks. /*~~*/ /*==*/ reduce((sum, track) => sum + track. /*~~*/ /*==*/ file.size, 0); try /*~~*/ /*==*/ { for (const /*~~x==*/ file of files) { if (tracks.length /*==x~~*/ >= 40 || total + file.size > limit || /*==x~~*/ !await isMp3(file)) { skipped /*==*/ /*~~*/ ++; continue /*==*/ /*~~*/ ; } tracks.push({ file, url /*==*/ /*~~*/ : URL.createObjectURL( file), title: file. /*== Drop it, drag it, hit play! ~~*/ name.slice(0, -4) }); added /*==x~~*/ ++; total += /*~~x==*/ file.size; } if (!selected && tracks. /*~~x==*/ length) select(tracks[0]); speak(added + /*~~*/ /*==*/ " track(s) added." + ( skipped ? " Skipped " /*~~*/ /*==*/ + skipped + ". Use MP3s, up to 40 tracks and 128 MB total." /*~~x==*/ : "" /*~~*/ /*==*/ )); } /*~~x==*/ catch { speak( /*== Three good tracks in a ~~*/ "A file could not be read. Please choose it again."); } /*==*/ finally { adding /*==*/ = false; render /*== folder called Final ~*/ (); } } function escapeHtml(text) { return String(text).replace(/[&<>"']/g, char => ({ "&": "&", "<": /* Dirk on the keys with a */ "<", ">": ">", '"': """, "'": "'", })[ /* hand on the vinyl */ char]); } /* .::###::. */ /* .::###::. */ /*:##o###o##:*/ /*:##o###o##:*/ /*\###=###/*/ /*\###~###/*/ /* `+--+`*/ /* `+--+`*/ /*==*/ /*~~*/ function /*== Pick your songs, put the ~~*/ publishedPlayer() { const audio = document. /*==x~~*/ querySelector("audio"); const current = document. /*==x~~*/ querySelector("#current"); const buttons = [... /*~~ best one first ==*/ document.querySelectorAll( "button[data-track]" /*~~x==*/ )]; let index /*~~*/ /*==*/ = -1; function /*~~*/ /*==*/ play(i) { const button /*~~*/ /*==*/ = buttons[i]; if (!button /*~~ Rename the next, drop the ==*/ ) return; index /*~~*/ /*==*/ = i; for (const item of buttons /*~~x==*/ ) item.setAttribute( "aria-pressed", /*~~x==*/ item === button); current.textContent /*==x~~*/ = button.textContent; audio.src = button /*== old title ~~*/ .dataset.track; audio.play().catch(() => /*==*/ /*~~*/ { current.textContent = "Press Play to start " /*==*/ /*~~*/ + button.textContent; }); } for (const [i, button /*== Click one play and the next ~~*/ ] of buttons.entries( )) button.addEventListener /*==x~~*/ ("click", () => play(i)); audio.addEventListener /*==x~~*/ ("ended", () => play(index /*~~ rolls through ==*/ + 1)); } /*~~*/ /*==*/ function exportPage /*~~*/ /*==*/ (title, songs) { const name = /*~~ Yellow snakes, green snakes, ==*/ escapeHtml(title); const items = songs.map(( /*~~x==*/ { path, title: label }) => '
").join("\n"); const policy = /*x*/ "default-src 'none'; script-src 'self'; media-src 'self'; " + "style-src 'unsafe-inline'; base-uri 'none'" /*==x~~*/ ; const /*== I had a hunch, plugged it ~~*/ look = [ "body{color-scheme:dark;background:#18221a;color:#f6efdb;" /*x*/ , "font:1rem/1.5 system-ui;margin:2rem auto;padding:0 1rem;max-width:46rem}" /*x*/ , "h1{color:#ffcc65;overflow-wrap:anywhere}" /*== in, it ran ~~*/ , "button{background:#314733;color:#fff;border:1px solid #788c62;" /*x*/ , "padding:.6rem .8rem;border-radius:.3rem;font:inherit;cursor:pointer}" /*x*/ , "button[aria-pressed=true]{background:#ffcc65;color:#222016}" /*~~ Dirk put a goat in the ==*/ , "li{margin:.45rem 0}audio{width:100%}" /*~~x==*/ , ].join /*~~ backup band ==*/ (""); return /*x*/ '' + '' /*x*/ + '' + "Choose a track.
' /*==x*/ + '