Reddit - Auto Best Video Quality

Reddit - Auto Best Video Quality. Reddit - 视频自动最佳画质

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Reddit - Auto Best Video Quality
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Reddit - Auto Best Video Quality. Reddit - 视频自动最佳画质
// @author       Martin______X
// @match        https://www.reddit.com/*
// @match        https://www.redgifs.com/ifr/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// @license      MIT
// ==/UserScript==

const simpleClick = (async (button) => {
    button.click();
    button.setAttribute("tred","");
});
const autoQualityInterval = setInterval(() => {
    try {
        let hlsjss = document.querySelectorAll('shreddit-player-static-hlsjs');
        for(let i=0; i<hlsjss.length;i++){
            //
            let hlsjs = hlsjss[i];
            if(hlsjs.shadowRoot){
                //
                let video = hlsjs.shadowRoot.querySelector('video');
                video.setAttribute("loop","");
                //
                let media_ui = hlsjs.shadowRoot.querySelector('shreddit-media-ui');
                //
                if(media_ui.shadowRoot){
                    let video_settings = media_ui.shadowRoot.querySelector('shreddit-video-settings');
                    //
                    if(video_settings.shadowRoot){
                        let autoplay_toggle = video_settings.shadowRoot.querySelector('button[data-testid="autoplay-toggle"]');
                        //
                        if(autoplay_toggle){
                            let best_quality = autoplay_toggle.parentElement.querySelector('button[data-testid="quality-option"]');
                            //
                            if(best_quality && !best_quality.hasAttribute("tred")){
                                simpleClick(best_quality);
                            }
                        }
                    }
                }
            }
        }
        //
        let qualityButton = document.querySelector('button.gifQualityButton');
        if(qualityButton && !qualityButton.hasAttribute("tred")){
            simpleClick(qualityButton);
        }
    } catch (error) {
        console.error(error)
    }
}, 1);