Created
May 1, 2023 12:24
-
-
Save BitesizedLion/a45d776b50222bb8aec6a567301b9a2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //@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