Youtube Auto Quality

Adjusts YouTube quality when not focused

  1. // ==UserScript==
  2. // @name Youtube Auto Quality
  3. // @version 1.0
  4. // @grant none
  5. // @match https://www.youtube.com/*
  6. // @run-at document-start
  7. // @author RexOmni
  8. // @description Adjusts YouTube quality when not focused
  9. // @no-frames
  10. // @namespace https://greasyfork.org/users/48806
  11. // ==/UserScript==
  12.  
  13. /* Acceptable qulaities
  14. 'auto'
  15. 'highres' // 8k or 'original'
  16. 'hd2880'
  17. 'hd2160'
  18. 'hd1440'
  19. 'hd1080'
  20. 'hd720'
  21. 'large'
  22. 'medium'
  23. 'small'
  24. 'tiny'
  25.  
  26. if the one you chose is not available it will choose the better one
  27. */
  28.  
  29. const FOCUSEDQUALITY = 'hd720';
  30. const HIDDENQUALITY = 'tiny';
  31.  
  32. (function(){
  33. 'use strict';
  34.  
  35. document.addEventListener('DOMContentLoaded', function(){
  36. // Handle page visibility change
  37. document.addEventListener("visibilitychange", function(){
  38. if (document.visibilityState == 'hidden') {
  39. document.getElementById("movie_player").setPlaybackQualityRange(HIDDENQUALITY);
  40. } else if (document.visibilityState == 'visible') {
  41. document.getElementById("movie_player").setPlaybackQualityRange(FOCUSEDQUALITY);
  42. }
  43. }, false);
  44. })
  45.  
  46. })();
  47.  
  48. console.log('YAQ: LOADED');