Auto Change Youtube Video Resolution to Max

auto change the video resolution to Max

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

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 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               Auto Change Youtube Video Resolution to Max
// @name:zh-TW         Auto Change Youtube Video Resolution to Max
// @namespace          https://greatest.deepsurf.us/scripts/453854
// @version            1.1.1
// @description        auto change the video resolution to Max
// @description:zh-TW  自動將影片畫質切換至最高畫質
// @author             Derek
// @match              *://www.youtube.com/*
// @grant              none
// @noframes
// ==/UserScript==

const $ = (element) => document.querySelector(element)

const main = () => {
  if (window.location.href.includes('/watch?v=')) {
    const observer = new MutationObserver(() => {
      const moviePlayer = $('#movie_player')
      if (moviePlayer) {
        const maxRes = moviePlayer.getAvailableQualityLevels()[0]
        moviePlayer.setPlaybackQualityRange(maxRes)
        observer.disconnect()
      }
    })
    observer.observe(document.body, { attributes: false, childList: true, subtree: true })
  }
}

document.addEventListener('yt-navigate-finish', main)