YouTube Auto HD

Tự động đặt chất lượng video YouTube lên 1080p hoặc 720p

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         YouTube Auto HD
// @namespace    https://tampermonkey.net/
// @version      1.1
// @description  Tự động đặt chất lượng video YouTube lên 1080p hoặc 720p
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    function setQuality() {
        const player = document.querySelector('video');
        const ytPlayer = document.getElementById('movie_player');

        if (!ytPlayer || !ytPlayer.getAvailableQualityLevels) return;

        const levels = ytPlayer.getAvailableQualityLevels();

        if (levels.includes('hd1080')) {
            ytPlayer.setPlaybackQualityRange('hd1080');
        } else if (levels.includes('hd720')) {
            ytPlayer.setPlaybackQualityRange('hd720');
        } else if (levels.length > 0) {
            ytPlayer.setPlaybackQualityRange(levels[0]);
        }
    }

    // Đợi video load
    setInterval(setQuality, 2000);
})();