Youtube Auto Quality

Adjusts YouTube quality when not focused

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Youtube Auto Quality
// @version     1.0
// @grant       none
// @match       https://www.youtube.com/*
// @run-at      document-start
// @author      RexOmni
// @description Adjusts YouTube quality when not focused
// @no-frames
// @namespace https://greasyfork.org/users/48806
// ==/UserScript==

/* Acceptable qulaities
'auto'
'highres'  // 8k or 'original'
'hd2880'
'hd2160'
'hd1440'
'hd1080'
'hd720'
'large'
'medium'
'small'
'tiny'

if the one you chose is not available it will choose the better one
*/

const FOCUSEDQUALITY = 'hd720';
const HIDDENQUALITY = 'tiny';

(function(){
    'use strict';

    document.addEventListener('DOMContentLoaded', function(){
        // Handle page visibility change
        document.addEventListener("visibilitychange", function(){
            if (document.visibilityState == 'hidden') {
                document.getElementById("movie_player").setPlaybackQualityRange(HIDDENQUALITY);
            } else if (document.visibilityState == 'visible') {
                document.getElementById("movie_player").setPlaybackQualityRange(FOCUSEDQUALITY);
            }
        }, false);
    })

})();

console.log('YAQ: LOADED');