Youtube Video Quality

Disabling auto video quality with toast notification, original script -> https://greasyfork.org/en/users/226529

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Youtube Video Quality
// @version     2.0
// @icon        https://www.gstatic.com/youtube/img/branding/favicon/favicon_144x144.png
// @grant       GM_addStyle
// @match       *://*.youtube.com/*
// @exclude     *://music.youtube.com/*
// @exclude     *://*.music.youtube.com/*
// @run-at      document-end
// @author      Yamako - Tanuki
// @description Disabling auto video quality with toast notification, original script -> https://greasyfork.org/en/users/226529
// @no-frames
// @namespace   https://greasyfork.org/en/scripts/379822-youtube-video-quality
// @homepage    https://greasyfork.org/en/scripts/379822-youtube-video-quality
// @license     MIT
// ==/UserScript==

var entut = 0;
var kntd = 0;

const QUALITIES =  ['auto', 'highres', 'hd2880', 'hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small', 'tiny'];
const QUALITY_HIGHRES = QUALITIES[1]; //Highest resolution available
const QUALITY_1080 = QUALITIES[5]; //HD 1080p
const QUALITY_LARGE = QUALITIES[7]; //480p
const QUALITY_MEDIUM = QUALITIES[8]; //360p
const QUALITY_SMALL = QUALITIES[9]; //240p

// Edit This Variable to Change Video Quality
const KUALITAS = QUALITY_MEDIUM;

// Main Function for changing quality
function SetQuality() {
  var mp = document.getElementById("movie_player");
  if (window.location.href.indexOf('watch?v=')>1){
    if (mp.getPlaybackQuality() != KUALITAS &&
        mp.getAvailableQualityLevels().indexOf(KUALITAS) > -1)
    {
      Toast("Change "+mp.getPlaybackQuality()+" to "+ KUALITAS);
      mp.setPlaybackQualityRange(KUALITAS);
    }
      else
    {
      if (entut == 0 && mp.getPlaybackQuality() != "unknown"){
        Toast("Already "+ mp.getPlaybackQuality());
        entut = 1;
      }
    }
  }
}

function Toast(text) {
  var x = document.getElementById("qualitytoast");
  x.className = "show";
  x.innerHTML = text;
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}

window.addEventListener("load", () => {
    var toastdiv = document.createElement('div');
    toastdiv.id = "qualitytoast";
    document.body.appendChild(toastdiv);

    setTimeout(SetQuality, 1000);
    setInterval(SetQuality, 500);

    GM_addStyle(`
        #qualitytoast {
            visibility: hidden;
            min-width: 250px;
            margin-left: -125px;
            background-color: #303030;
            color: #f9f9f9;
            text-align: center;
            border-radius: 10px;
            padding: 16px;
            position: fixed;
            z-index: 1;
            left: 50%;
            bottom: 30px;
            font-size: 21px;
        }

        #qualitytoast.show {
            visibility: visible;
            -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
            animation: fadein 0.5s, fadeout 0.5s 2.5s;
        }

        @-webkit-keyframes fadein {
            from {bottom: 0; opacity: 0;}
            to {bottom: 30px; opacity: 1;}
        }

        @keyframes fadein {
            from {bottom: 0; opacity: 0;}
            to {bottom: 30px; opacity: 1;}
        }

        @-webkit-keyframes fadeout {
            from {bottom: 30px; opacity: 1;}
            to {bottom: 0; opacity: 0;}
        }

        @keyframes fadeout {
            from {bottom: 30px; opacity: 1;}
            to {bottom: 0; opacity: 0;}
        }
    `);

});