YouTube Auto HD

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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