Spotify Miniplayer Unlocker

Removes the Premium resize popup in Spotify's miniplayers.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Spotify Miniplayer Unlocker
// @namespace    https://open.spotify.com/
// @version      1.0.1
// @description  Removes the Premium resize popup in Spotify's miniplayers.
// @author       shmo
// @license      MIT
// @match        https://open.spotify.com/*
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    function killPopup(doc) {
        var popup = doc.querySelector('.gDrPbJQiN4Ij2XGL');
        if (!popup) return;
        popup.style.setProperty('display', 'none', 'important');
        var notNow = popup.querySelector('.kaOb9iL_4FaiiHH9');
        if (!notNow) {
            var all = popup.querySelectorAll('[data-encore-id="buttonTertiary"]');
            notNow = all[all.length - 1] || null;
        }
        if (notNow) notNow.click();
    }

    function setupInPiP(doc, pipWin) {

        if (!doc.getElementById('smu-suppress')) {
            try {
                var s = doc.createElement('style');
                s.id = 'smu-suppress';
                s.textContent = '.gDrPbJQiN4Ij2XGL { display: none !important; }';
                (doc.head || doc.documentElement).appendChild(s);
            } catch (e) { /* mario kart */ }
        }

        if (!doc._smuObserver) {
            var root = doc.querySelector('.encore-dark-theme') || doc.documentElement;
            doc._smuObserver = new MutationObserver(function () {
                killPopup(doc);
            });
            doc._smuObserver.observe(root, {
                attributes:      true,
                attributeFilter: ['style'],
                childList:       true,
                subtree:         true,
            });
            killPopup(doc);
        }
    }

    function injectIntoPiP(pipWin) {
        if (pipWin._smuInjected) return;
        pipWin._smuInjected = true;
        var doc = pipWin.document;
        setupInPiP(doc, pipWin);
        pipWin.addEventListener('load', function () {
            setupInPiP(pipWin.document, pipWin);
        });
        setTimeout(function () { setupInPiP(pipWin.document, pipWin); }, 500);
        setTimeout(function () { setupInPiP(pipWin.document, pipWin); }, 1500);
    }

    function hookPiP() {
        var pip;
        try { pip = unsafeWindow.documentPictureInPicture; } catch (e) {}

        if (!pip) {
            setTimeout(hookPiP, 400);
            return;
        }
        if (pip.__smu__) return;
        pip.__smu__ = true;

        var orig = pip.requestWindow.bind(pip);
        pip.requestWindow = function (opts) {
            return orig(opts).then(function (pipWin) {
                injectIntoPiP(pipWin);
                return pipWin;
            });
        };
        if (pip.window) injectIntoPiP(pip.window);
    }
    function pollForPiP() {
        try {
            var pip = unsafeWindow.documentPictureInPicture;
            if (pip && pip.window && !pip.window._smuInjected) {
                injectIntoPiP(pip.window);
            }
        } catch (e) {}
    }

    hookPiP();
    setInterval(pollForPiP, 1000);

})();