Spotify Miniplayer Unlocker

Removes the Premium resize popup in Spotify's miniplayers.

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

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

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 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);

})();