Remove suffix, don't alert on download cancel

This commit is contained in:
2026-08-06 16:30:01 -05:00
parent fecc87cd66
commit f07e9f9c3a
7 changed files with 39 additions and 11 deletions

View File

@@ -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(() => {