From f07e9f9c3a05fd4b20da1a3aaa81ab6df4222584 Mon Sep 17 00:00:00 2001 From: Zetaphor Date: Thu, 6 Aug 2026 16:30:01 -0500 Subject: [PATCH] Remove suffix, don't alert on download cancel --- README.md | 2 +- background.js | 8 +++++--- content-script.js | 14 ++++++++++++-- history.js | 8 ++++++++ manifest.json | 8 ++++---- package.json | 2 +- popup.js | 8 ++++++++ 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 256871b..9e6d90c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ WTFPL licensed. 1. Open `about:debugging#/runtime/this-firefox` 2. Click **Load Temporary Add-on...** 3. Select this extension's `manifest.json` -4. Visit `https://splice.com/sounds/search/samples` +4. Visit any URL under `https://splice.com/sounds` (for example `https://splice.com/sounds/packs/`) ## Build Firefox Package diff --git a/background.js b/background.js index 2c1f6d0..d78fef5 100644 --- a/background.js +++ b/background.js @@ -5,7 +5,7 @@ const FULL_URL_BY_SAMPLE = new Map(); const HISTORY_KEY = "capturedS3History"; const MAX_HISTORY_ITEMS = 500; const TARGET_HOST = "splice.com"; -const TARGET_PATH = "/sounds/search/samples"; +const TARGET_PATH_PREFIX = "/sounds"; const AUDIO_SAMPLE_PATH_RE = /\/audio_samples\//i; const WAVEFORM_PATH_RE = /\.wv\.json$/i; const SCRAMBLED_PATH_RE = /-scrambled\//i; @@ -18,7 +18,9 @@ function isDomainAllowed(pageUrl) { } try { const parsed = new URL(pageUrl); - return parsed.protocol === "https:" && parsed.hostname === TARGET_HOST && parsed.pathname === TARGET_PATH; + const path = parsed.pathname || ""; + const inSoundsPath = path === TARGET_PATH_PREFIX || path.startsWith(TARGET_PATH_PREFIX + "/"); + return parsed.protocol === "https:" && parsed.hostname === TARGET_HOST && inSoundsPath; } catch (error) { return false; } @@ -409,7 +411,7 @@ function deriveFilename(entry, mode) { } return `${safeStem}.wav`; } - return `${safeStem}_decoded.mp3`; + return `${safeStem}.mp3`; } async function downloadDirectUrl(url, entry) { diff --git a/content-script.js b/content-script.js index b7fadb2..d229926 100644 --- a/content-script.js +++ b/content-script.js @@ -3,7 +3,7 @@ const TARGET_SELECTOR = ".playbar-playback-info-bar.playback-row-section.svelte-11gjrk3"; const INJECTED_CONTAINER_ID = "s3-audio-capture-controls"; const TARGET_HOST = "splice.com"; -const TARGET_PATH = "/sounds/search/samples"; +const TARGET_PATH_PREFIX = "/sounds"; const PROBE_EVENT_SOURCE = "S3_CAPTURE_PROBE"; let knownUrls = new Set(); let knownPerformanceUrls = new Set(); @@ -21,13 +21,20 @@ let currentPlaybackCoverImageUrl = ""; let lastPlaybackMetaSignature = ""; let lastPlaybackMetaApplied = false; +function isUserCancelledError(result) { + const error = result && typeof result.error === "string" ? result.error.toLowerCase() : ""; + return error.includes("canceled by the user") || error.includes("cancelled by the user"); +} + function isDomainAllowed(url) { if (typeof url !== "string") { return false; } try { const parsed = new URL(url); - return parsed.protocol === "https:" && parsed.hostname === TARGET_HOST && parsed.pathname === TARGET_PATH; + const path = parsed.pathname || ""; + const inSoundsPath = path === TARGET_PATH_PREFIX || path.startsWith(TARGET_PATH_PREFIX + "/"); + return parsed.protocol === "https:" && parsed.hostname === TARGET_HOST && inSoundsPath; } catch (error) { return false; } @@ -595,6 +602,9 @@ function injectControls() { const currentButton = createButtonMetaItem("download", "Download current audio", () => { browser.runtime.sendMessage({ type: "DOWNLOAD_LATEST" }).then((result) => { if (!result || !result.ok) { + if (isUserCancelledError(result)) { + return; + } window.alert((result && result.error) || "No URL available for download."); } }).catch(() => { diff --git a/history.js b/history.js index 55a8ef1..9832646 100644 --- a/history.js +++ b/history.js @@ -4,6 +4,11 @@ const statusEl = document.getElementById("status"); const listEl = document.getElementById("historyList"); const clearHistoryBtn = document.getElementById("clearHistoryBtn"); +function isUserCancelledError(result) { + const error = result && typeof result.error === "string" ? result.error.toLowerCase() : ""; + return error.includes("canceled by the user") || error.includes("cancelled by the user"); +} + function formatMeta(entry) { const packName = entry && entry.packName ? entry.packName : "n/a"; const key = entry && entry.key ? entry.key : "n/a"; @@ -105,6 +110,9 @@ function buildItem(entry) { entry }); if (!result || !result.ok) { + if (isUserCancelledError(result)) { + return; + } window.alert((result && result.error) || "Download failed."); return; } diff --git a/manifest.json b/manifest.json index 1270241..204a6fa 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Splirate", - "version": "1.0.1", + "version": "1.0.2", "description": "Splirate captures Splice sample links and downloads playable audio.", "icons": { "48": "icons/icon-48.png", @@ -13,7 +13,7 @@ "storage", "downloads", "webRequest", - "https://splice.com/sounds/search/samples*", + "https://splice.com/sounds*", "*://*.amazonaws.com/*", "*://*.amazonaws.com.cn/*", "webNavigation" @@ -26,7 +26,7 @@ "content_scripts": [ { "matches": [ - "https://splice.com/sounds/search/samples*" + "https://splice.com/sounds*" ], "js": [ "content-script.js" @@ -59,4 +59,4 @@ } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 3cc7075..a4af730 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "splirate", - "version": "1.0.1", + "version": "1.0.2", "private": true, "description": "Splirate Firefox extension", "scripts": { diff --git a/popup.js b/popup.js index 5b66ebc..5a87e11 100644 --- a/popup.js +++ b/popup.js @@ -9,6 +9,11 @@ function setStatus(message) { statusEl.textContent = message; } +function isUserCancelledError(result) { + const error = result && typeof result.error === "string" ? result.error.toLowerCase() : ""; + return error.includes("canceled by the user") || error.includes("cancelled by the user"); +} + function entryLabel(entry) { return entry && entry.fullUrl ? "full candidate" : "preview fallback"; } @@ -115,6 +120,9 @@ function buildRow(entry) { download.addEventListener("click", async () => { const result = await browser.runtime.sendMessage({ type: "DOWNLOAD_ENTRY", entry }); if (!result || !result.ok) { + if (isUserCancelledError(result)) { + return; + } window.alert((result && result.error) || "Download failed."); return; }