Remove suffix, don't alert on download cancel
This commit is contained in:
@@ -33,7 +33,7 @@ WTFPL licensed.
|
|||||||
1. Open `about:debugging#/runtime/this-firefox`
|
1. Open `about:debugging#/runtime/this-firefox`
|
||||||
2. Click **Load Temporary Add-on...**
|
2. Click **Load Temporary Add-on...**
|
||||||
3. Select this extension's `manifest.json`
|
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
|
## Build Firefox Package
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const FULL_URL_BY_SAMPLE = new Map();
|
|||||||
const HISTORY_KEY = "capturedS3History";
|
const HISTORY_KEY = "capturedS3History";
|
||||||
const MAX_HISTORY_ITEMS = 500;
|
const MAX_HISTORY_ITEMS = 500;
|
||||||
const TARGET_HOST = "splice.com";
|
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 AUDIO_SAMPLE_PATH_RE = /\/audio_samples\//i;
|
||||||
const WAVEFORM_PATH_RE = /\.wv\.json$/i;
|
const WAVEFORM_PATH_RE = /\.wv\.json$/i;
|
||||||
const SCRAMBLED_PATH_RE = /-scrambled\//i;
|
const SCRAMBLED_PATH_RE = /-scrambled\//i;
|
||||||
@@ -18,7 +18,9 @@ function isDomainAllowed(pageUrl) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(pageUrl);
|
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) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -409,7 +411,7 @@ function deriveFilename(entry, mode) {
|
|||||||
}
|
}
|
||||||
return `${safeStem}.wav`;
|
return `${safeStem}.wav`;
|
||||||
}
|
}
|
||||||
return `${safeStem}_decoded.mp3`;
|
return `${safeStem}.mp3`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadDirectUrl(url, entry) {
|
async function downloadDirectUrl(url, entry) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const TARGET_SELECTOR = ".playbar-playback-info-bar.playback-row-section.svelte-11gjrk3";
|
const TARGET_SELECTOR = ".playbar-playback-info-bar.playback-row-section.svelte-11gjrk3";
|
||||||
const INJECTED_CONTAINER_ID = "s3-audio-capture-controls";
|
const INJECTED_CONTAINER_ID = "s3-audio-capture-controls";
|
||||||
const TARGET_HOST = "splice.com";
|
const TARGET_HOST = "splice.com";
|
||||||
const TARGET_PATH = "/sounds/search/samples";
|
const TARGET_PATH_PREFIX = "/sounds";
|
||||||
const PROBE_EVENT_SOURCE = "S3_CAPTURE_PROBE";
|
const PROBE_EVENT_SOURCE = "S3_CAPTURE_PROBE";
|
||||||
let knownUrls = new Set();
|
let knownUrls = new Set();
|
||||||
let knownPerformanceUrls = new Set();
|
let knownPerformanceUrls = new Set();
|
||||||
@@ -21,13 +21,20 @@ let currentPlaybackCoverImageUrl = "";
|
|||||||
let lastPlaybackMetaSignature = "";
|
let lastPlaybackMetaSignature = "";
|
||||||
let lastPlaybackMetaApplied = false;
|
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) {
|
function isDomainAllowed(url) {
|
||||||
if (typeof url !== "string") {
|
if (typeof url !== "string") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(url);
|
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) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -595,6 +602,9 @@ function injectControls() {
|
|||||||
const currentButton = createButtonMetaItem("download", "Download current audio", () => {
|
const currentButton = createButtonMetaItem("download", "Download current audio", () => {
|
||||||
browser.runtime.sendMessage({ type: "DOWNLOAD_LATEST" }).then((result) => {
|
browser.runtime.sendMessage({ type: "DOWNLOAD_LATEST" }).then((result) => {
|
||||||
if (!result || !result.ok) {
|
if (!result || !result.ok) {
|
||||||
|
if (isUserCancelledError(result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.alert((result && result.error) || "No URL available for download.");
|
window.alert((result && result.error) || "No URL available for download.");
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ const statusEl = document.getElementById("status");
|
|||||||
const listEl = document.getElementById("historyList");
|
const listEl = document.getElementById("historyList");
|
||||||
const clearHistoryBtn = document.getElementById("clearHistoryBtn");
|
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) {
|
function formatMeta(entry) {
|
||||||
const packName = entry && entry.packName ? entry.packName : "n/a";
|
const packName = entry && entry.packName ? entry.packName : "n/a";
|
||||||
const key = entry && entry.key ? entry.key : "n/a";
|
const key = entry && entry.key ? entry.key : "n/a";
|
||||||
@@ -105,6 +110,9 @@ function buildItem(entry) {
|
|||||||
entry
|
entry
|
||||||
});
|
});
|
||||||
if (!result || !result.ok) {
|
if (!result || !result.ok) {
|
||||||
|
if (isUserCancelledError(result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.alert((result && result.error) || "Download failed.");
|
window.alert((result && result.error) || "Download failed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Splirate",
|
"name": "Splirate",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "Splirate captures Splice sample links and downloads playable audio.",
|
"description": "Splirate captures Splice sample links and downloads playable audio.",
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "icons/icon-48.png",
|
"48": "icons/icon-48.png",
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"storage",
|
"storage",
|
||||||
"downloads",
|
"downloads",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"https://splice.com/sounds/search/samples*",
|
"https://splice.com/sounds*",
|
||||||
"*://*.amazonaws.com/*",
|
"*://*.amazonaws.com/*",
|
||||||
"*://*.amazonaws.com.cn/*",
|
"*://*.amazonaws.com.cn/*",
|
||||||
"webNavigation"
|
"webNavigation"
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
"https://splice.com/sounds/search/samples*"
|
"https://splice.com/sounds*"
|
||||||
],
|
],
|
||||||
"js": [
|
"js": [
|
||||||
"content-script.js"
|
"content-script.js"
|
||||||
@@ -59,4 +59,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "splirate",
|
"name": "splirate",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Splirate Firefox extension",
|
"description": "Splirate Firefox extension",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
8
popup.js
8
popup.js
@@ -9,6 +9,11 @@ function setStatus(message) {
|
|||||||
statusEl.textContent = 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) {
|
function entryLabel(entry) {
|
||||||
return entry && entry.fullUrl ? "full candidate" : "preview fallback";
|
return entry && entry.fullUrl ? "full candidate" : "preview fallback";
|
||||||
}
|
}
|
||||||
@@ -115,6 +120,9 @@ function buildRow(entry) {
|
|||||||
download.addEventListener("click", async () => {
|
download.addEventListener("click", async () => {
|
||||||
const result = await browser.runtime.sendMessage({ type: "DOWNLOAD_ENTRY", entry });
|
const result = await browser.runtime.sendMessage({ type: "DOWNLOAD_ENTRY", entry });
|
||||||
if (!result || !result.ok) {
|
if (!result || !result.ok) {
|
||||||
|
if (isUserCancelledError(result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.alert((result && result.error) || "Download failed.");
|
window.alert((result && result.error) || "Download failed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user