Spotify Miniplayer Unlocker

Removes the Premium resize popup in Spotify's miniplayers.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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

})();