This commit is contained in:
2026-08-05 22:46:02 -05:00
parent 47871d4bc5
commit 4f10991abc
5 changed files with 357 additions and 134 deletions

123
popup.js
View File

@@ -16,41 +16,101 @@ function formatMeta(entry) {
const packName = entry && entry.packName ? entry.packName : "n/a";
const key = entry && entry.key ? entry.key : "n/a";
const bpm = entry && entry.bpm ? entry.bpm : "n/a";
const tags = entry && Array.isArray(entry.tags) && entry.tags.length ? entry.tags.join(", ") : "n/a";
return `Pack: ${packName} | Key: ${key} | BPM: ${bpm} | Tags: ${tags}`;
return { packName, key, bpm };
}
function formatTags(entry) {
if (!entry || !Array.isArray(entry.tags) || !entry.tags.length) {
return "No tags";
}
const maxTags = 5;
const tags = entry.tags.slice(0, maxTags);
const suffix = entry.tags.length > maxTags ? ` +${entry.tags.length - maxTags}` : "";
return tags.join(" • ") + suffix;
}
function createDownloadIcon() {
const ns = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(ns, "svg");
svg.setAttribute("viewBox", "0 0 24 24");
svg.setAttribute("width", "22");
svg.setAttribute("height", "22");
svg.setAttribute("aria-hidden", "true");
const arrow = document.createElementNS(ns, "path");
arrow.setAttribute("d", "M12 4v10m0 0l4-4m-4 4l-4-4");
arrow.setAttribute("fill", "none");
arrow.setAttribute("stroke", "currentColor");
arrow.setAttribute("stroke-width", "2");
arrow.setAttribute("stroke-linecap", "round");
arrow.setAttribute("stroke-linejoin", "round");
const tray = document.createElementNS(ns, "path");
tray.setAttribute("d", "M4 18v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1");
tray.setAttribute("fill", "none");
tray.setAttribute("stroke", "currentColor");
tray.setAttribute("stroke-width", "2");
tray.setAttribute("stroke-linecap", "round");
tray.setAttribute("stroke-linejoin", "round");
svg.appendChild(arrow);
svg.appendChild(tray);
return svg;
}
function buildRow(entry) {
const li = document.createElement("li");
li.className = "url-item";
const meta = formatMeta(entry);
if (entry.coverImageUrl) {
const cover = document.createElement("img");
cover.className = "cover-image";
cover.src = entry.coverImageUrl;
cover.alt = "Cover art";
cover.loading = "lazy";
li.appendChild(cover);
}
const head = document.createElement("div");
head.className = "item-head";
const p = document.createElement("p");
p.className = "url-text";
p.textContent = entry.fileName || entry.sampleId || "(unknown filename)";
const cover = document.createElement("img");
cover.className = "cover-image";
cover.src = entry.coverImageUrl || "icons/icon-48.png";
cover.alt = "Cover art";
cover.loading = "lazy";
const status = document.createElement("p");
status.className = "status";
status.textContent = `Source: ${entry.source || "unknown"} | Mode: ${entryLabel(entry)} | ID: ${entry.sampleId || "n/a"}`;
const info = document.createElement("div");
info.className = "item-info";
const meta = document.createElement("p");
meta.className = "status";
meta.textContent = formatMeta(entry);
const title = document.createElement("p");
title.className = "item-title";
title.textContent = entry.fileName || entry.sampleId || "(unknown filename)";
const actions = document.createElement("div");
actions.className = "actions";
const sub = document.createElement("p");
sub.className = "item-sub";
sub.textContent = `${meta.packName}${entryLabel(entry)}`;
const tags = document.createElement("p");
tags.className = "item-tags";
tags.textContent = formatTags(entry);
const badges = document.createElement("div");
badges.className = "item-badges";
const keyBadge = document.createElement("span");
keyBadge.className = "badge";
keyBadge.textContent = `Key ${meta.key}`;
const bpmBadge = document.createElement("span");
bpmBadge.className = "badge";
bpmBadge.textContent = `BPM ${meta.bpm}`;
badges.appendChild(keyBadge);
badges.appendChild(bpmBadge);
info.appendChild(title);
info.appendChild(sub);
info.appendChild(tags);
info.appendChild(badges);
const download = document.createElement("button");
download.type = "button";
download.textContent = "Download";
download.className = "download-icon-btn";
download.setAttribute("aria-label", "Download sample");
download.setAttribute("title", "Download sample");
download.appendChild(createDownloadIcon());
download.addEventListener("click", async () => {
const result = await browser.runtime.sendMessage({ type: "DOWNLOAD_ENTRY", entry });
if (!result || !result.ok) {
@@ -60,21 +120,10 @@ function buildRow(entry) {
setStatus(result.mode === "full" ? "Downloaded full file URL." : "Downloaded decoded preview fallback.");
});
const copy = document.createElement("button");
copy.type = "button";
copy.className = "secondary";
copy.textContent = "Copy URL";
copy.addEventListener("click", async () => {
const url = entry.fullUrl || entry.previewUrl || "";
await navigator.clipboard.writeText(url);
});
actions.appendChild(download);
actions.appendChild(copy);
li.appendChild(p);
li.appendChild(status);
li.appendChild(meta);
li.appendChild(actions);
head.appendChild(cover);
head.appendChild(info);
head.appendChild(download);
li.appendChild(head);
return li;
}