Spotify - Random Buttons

Add missing randomize features to Spotify (only random artist for now, more to come later).

Stan na 03-12-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Spotify - Random Buttons
// @namespace    spotify-random-buttons
// @version      0.2
// @description  Add missing randomize features to Spotify (only random artist for now, more to come later).
// @author       Mark McEver
// @match        https://open.spotify.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=spotify.com
// @grant        GM_registerMenuCommand
// ==/UserScript==

GM_registerMenuCommand('Random Followed Artist', () => {
    new class{
        constructor(){
            const variables = encodeURIComponent(JSON.stringify({"filters":["Artists"],"order":null,"textFilter":"","features":["LIKED_SONGS","YOUR_EPISODES"],"limit":50,"offset":0,"flatten":false,"expandedFolders":[],"folderUri":null,"includeFoldersWhenFlattening":true,"withCuration":false}))
            const extensions = encodeURIComponent(JSON.stringify({"persistedQuery":{"version":1,"sha256Hash":"0cc9ca58bd1dad0ce11712768bf4357ca8a9c6dab1dc0b43331fe526c47ff885"}}))

            fetch('https://api-partner.spotify.com/pathfinder/v1/query?operationName=libraryV3&variables=' + variables + '&extensions=' + extensions, {
                headers: {
                    'Authorization': 'Bearer ' + JSON.parse(document.querySelector('#session').textContent).accessToken
                }
            })
                .then(response => response.json())
                .then(data => {
                const artists = data.data.me.libraryV3.items
                const artist = artists[this.rand(0, artists.length-1)]
                const id = artist.item.data.uri.split(':')[2]
                location.href = '/artist/' + id
            })
        }

        rand(min, max){
            return Math.floor(Math.random() * (max - min + 1) + min)
        }
    }
})