Spotify Miniplayer Unlocker

Removes the Premium resize popup in Spotify's miniplayers.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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

})();