Skip to content

Instantly share code, notes, and snippets.

@BitesizedLion
Created May 1, 2023 12:24
Show Gist options
  • Select an option

  • Save BitesizedLion/a45d776b50222bb8aec6a567301b9a2c to your computer and use it in GitHub Desktop.

Select an option

Save BitesizedLion/a45d776b50222bb8aec6a567301b9a2c to your computer and use it in GitHub Desktop.
//@ts-check
// NAME: Anonymized Radios
/// <reference path="../../spicetify-cli/globals.d.ts" />
(function anonymizedradios() {
const { Platform, URI } = Spicetify;
if (!(Platform && URI)) {
// is this even needed?
setTimeout(anonymizedradios, 300);
return;
}
const buttontxt = "Create anonymized playlist";
async function makePlaylist(uris) {
const radioID = uris[0].split(":")[2];
const sse = new EventSource(
`https://open.spoqify.com/anonymize?url=${radioID}`
);
sse.addEventListener("done", function (e) {
sse.close();
let anonymizedURL = e.data.replace("https://open.spotify.com", "");
Spicetify.Platform.History.replace(anonymizedURL);
});
sse.addEventListener("error", function (e) {
sse.close();
// toast or something?
});
}
function shouldDisplayContextMenu(uris) {
if (uris.length > 1) return false;
const uri = uris[0];
const uriObj = Spicetify.URI.fromString(uri);
if (uriObj.type === Spicetify.URI.Type.PLAYLIST_V2) {
return true;
}
return false;
}
const cntxMenu = new Spicetify.ContextMenu.Item(
buttontxt,
makePlaylist,
shouldDisplayContextMenu
);
cntxMenu.register();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment