Youtube Music fix performance

Try to fix the performance issues that youtube music has

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Youtube Music fix performance
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Try to fix the performance issues that youtube music has
// @author       Marco Pfeiffer <[email protected]>
// @match        https://music.youtube.com/*
// @icon         https://music.youtube.com/favicon.ico
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const global = window.unsafeWindow ?? window;
    const setInterval = global.setInterval;
    const clearInterval = global.clearInterval;
    const intervals = new Set();

    global.setInterval = function(fn, ms) {
        const n = setInterval.call(this, fn, ms);
        console.log("setup interval", n, fn, ms, "still pending timers", Array.from(intervals));
        intervals.add(n);
        return n;
    };
    global.clearInterval = function (n) {
        if (!intervals.delete(n)) {
            console.log("failed cleanup of", n, "still pending timers", Array.from(intervals));
            if (intervals.size > 5) {
                const timersToCleanUp = Array.from(intervals).slice(0, -5);
                console.log("cleanup timers", timersToCleanUp);
                timersToCleanUp.forEach(clearInterval);
            }
        } else {
            console.log("cleanup interval", n, "still pending timers", Array.from(intervals));
        }
        return clearInterval.call(this, n);
    };
})();