m.YouTube.com quality change buttons

Adds quality change buttons below the video (144p, 240p, 360p, 480p, 720p, 1080p)

2023-10-12 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         m.YouTube.com quality change buttons
// @namespace    m-youtube-com-quality-change-buttons
// @version      1.2
// @description  Adds quality change buttons below the video (144p, 240p, 360p, 480p, 720p, 1080p)
// @author       hlorand.hu
// @match        https://m.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @license      https://creativecommons.org/licenses/by-nc-sa/4.0/
// ==/UserScript==

(function() {
    //'use strict';

    function addbuttons(){
        document.getElementById("qualitybuttons").innerHTML = "";

        var player = document.getElementById('movie_player');

        const qualities = ["tiny","small","medium","large","hd720","hd1080"];

        qualities.forEach((quality)=>{

            let button = document.createElement('button');
            button.setAttribute("quality", quality);
            let text = "";
            switch( quality ){
                case 'tiny': text = '144p'; break;
                case 'small': text = '240p'; break;
                case 'medium': text = '360p'; break;
                case 'large': text = '480p'; break;
                case 'hd720': text = '720p'; break;
                case 'hd1080': text = '1080p'; break;
            }
            button.textContent = text;
            button.className = "qualitybutton";

            button.style.margin = "5px";
            button.style.padding = "5px";
            button.style.backgroundColor = "green";
            button.style.position = "relative";

            button.onclick = function() {
                player.setPlaybackQualityRange( this.getAttribute("quality") );

                document.querySelectorAll(".qualitybutton").forEach((btn)=>{
                    btn.style.backgroundColor = "green";
                });
                this.style.backgroundColor = "darkorange";
            };

            let div = document.querySelector('.related-chips-slot-wrapper');
            div.insertBefore(button, div.firstChild);

        }); // end qualities foreach

    } // end addbuttons

    window.addEventListener('load', function () {
        setInterval(()=>{
            if( document.getElementById("qualitybuttons") == undefined ){
                let parent = document.querySelector('.related-chips-slot-wrapper');
                let wrapper = document.createElement('div');
                wrapper.setAttribute("id","qualitybuttons");
                parent.insertBefore(wrapper, parent.firstChild);
                addbuttons();
            }
        }, 1000);
    }); // end addEventListener

})();