YouTube Auto HD

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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