Skip to content

Commit 3f6c823

Browse files
committed
feat: add ability to change cors proxy server
1 parent 693686d commit 3f6c823

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

CustomApps/lyrics-plus/Settings.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,22 @@ const ServiceList = ({ itemsList, onListChange = () => {}, onToggle = () => {},
452452
});
453453
};
454454

455+
const corsProxyTemplate = () => {
456+
const [proxyValue, setProxyValue] = react.useState(localStorage.getItem("spicetify:corsProxyTemplate") || "https://cors-proxy.spicetify.app/{url}");
457+
458+
return react.createElement("input", {
459+
placeholder: "CORS Proxy Template",
460+
value: proxyValue,
461+
onChange: (event) => {
462+
const value = event.target.value;
463+
setProxyValue(value);
464+
465+
if (value === "" || !value) return localStorage.removeItem("spicetify:corsProxyTemplate");
466+
localStorage.setItem("spicetify:corsProxyTemplate", value);
467+
},
468+
});
469+
};
470+
455471
const OptionList = ({ type, items, onChange }) => {
456472
const [itemList, setItemList] = useState(items);
457473
const [, forceUpdate] = useState();
@@ -646,6 +662,19 @@ function openConfig() {
646662
CONFIG.providers[name].token = value;
647663
localStorage.setItem(`${APP_NAME}:provider:${name}:token`, value);
648664
},
665+
}),
666+
react.createElement("h2", null, "CORS Proxy Template"),
667+
react.createElement("span", {
668+
dangerouslySetInnerHTML: {
669+
__html:
670+
"Use this to bypass CORS restrictions. Replace the URL with your cors proxy server of your choice. <code>{url}</code> will be replaced with the request URL.",
671+
},
672+
}),
673+
react.createElement(corsProxyTemplate),
674+
react.createElement("span", {
675+
dangerouslySetInnerHTML: {
676+
__html: "Spotify will reload its webview after applying. Leave empty to restore default: <code>https://cors-proxy.spicetify.app/{url}</code>",
677+
},
649678
})
650679
);
651680

jsHelper/spicetifyWrapper.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ window.Spicetify = {
352352

353353
const _cosmos = Spicetify.Player.origin?._cosmos ?? Spicetify.Platform?.Registry.resolve(Symbol.for("Cosmos"));
354354

355-
const corsProxyURL = "https://cors-proxy.spicetify.app";
356355
const allowedMethodsMap = {
357356
get: "get",
358357
post: "post",
@@ -374,6 +373,7 @@ window.Spicetify = {
374373
return async function (url, body) {
375374
const urlObj = new URL(url);
376375

376+
const corsProxyURLTemplate = window.localStorage.getItem("spicetify:corsProxyTemplate") ?? "https://cors-proxy.spicetify.app/{url}";
377377
const isWebAPI = urlObj.hostname === "api.spotify.com";
378378
const isSpClientAPI = urlObj.hostname.includes("spotify.com") && urlObj.hostname.includes("spclient");
379379
const isInternalURL = internalEndpoints.has(urlObj.protocol);
@@ -396,10 +396,18 @@ window.Spicetify = {
396396
if (body) {
397397
if (method === "get") {
398398
const params = new URLSearchParams(body);
399-
finalURL += `?${params.toString()}`;
399+
const useSeparator = shouldUseCORSProxy && new URL(finalURL).search.startsWith("?");
400+
finalURL += `${useSeparator ? "&" : "?"}${params.toString()}`;
400401
} else options.body = !Array.isArray(body) && typeof body === "object" ? JSON.stringify(body) : body;
401402
}
402-
if (shouldUseCORSProxy) finalURL = `${corsProxyURL}/${finalURL}`;
403+
if (shouldUseCORSProxy) {
404+
finalURL = corsProxyURLTemplate.replace(/{url}/, finalURL);
405+
try {
406+
new URL(finalURL);
407+
} catch {
408+
console.error("[spicetifyWrapper] Invalid CORS Proxy URL template");
409+
}
410+
}
403411

404412
const Authorization = `Bearer ${Spicetify.Platform.AuthorizationAPI.getState().token.accessToken}`;
405413
let injectedHeaders = {};
@@ -459,7 +467,7 @@ window.Spicetify = {
459467
() => {
460468
webpackDidCallback = true;
461469
},
462-
6
470+
12
463471
);
464472

465473
let chunks = Object.entries(require.m);

0 commit comments

Comments
 (0)