Last active
May 3, 2023 21:28
-
-
Save BitesizedLion/3693e3aebf8caf2dd427e6b8c7ddec74 to your computer and use it in GitHub Desktop.
Anonymized Radios w/ track context menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NAME: Anonymized Radios | |
(function anonymizedradios() { | |
const { Platform, URI } = Spicetify; | |
async function makePlaylist(uris) { | |
const trackID = uris[0].substr(8); | |
const sse = new EventSource( | |
`https://open.spoqify.com/anonymize?url=${trackID}` | |
); | |
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.TRACK) { | |
return true; | |
} | |
return false; | |
} | |
const cntxMenu = new Spicetify.ContextMenu.Item( | |
"Create anonymized playlist", | |
makePlaylist, | |
shouldDisplayContextMenu | |
); | |
cntxMenu.register(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment