Youtube Video Quality

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

目前为 2023-11-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Video Quality
  3. // @version 2.0
  4. // @icon https://www.gstatic.com/youtube/img/branding/favicon/favicon_144x144.png
  5. // @grant GM_addStyle
  6. // @match *://*.youtube.com/*
  7. // @exclude *://music.youtube.com/*
  8. // @exclude *://*.music.youtube.com/*
  9. // @run-at document-end
  10. // @author Yamako - Tanuki
  11. // @description Disabling auto video quality with toast notification, original script -> https://greasyfork.org/en/users/226529
  12. // @no-frames
  13. // @namespace https://greasyfork.org/en/scripts/379822-youtube-video-quality
  14. // @homepage https://greasyfork.org/en/scripts/379822-youtube-video-quality
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. var entut = 0;
  19. var kntd = 0;
  20.  
  21. const QUALITIES = ['auto', 'highres', 'hd2880', 'hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small', 'tiny'];
  22. const QUALITY_HIGHRES = QUALITIES[1]; //Highest resolution available
  23. const QUALITY_1080 = QUALITIES[5]; //HD 1080p
  24. const QUALITY_LARGE = QUALITIES[7]; //480p
  25. const QUALITY_MEDIUM = QUALITIES[8]; //360p
  26. const QUALITY_SMALL = QUALITIES[9]; //240p
  27.  
  28. // Edit This Variable to Change Video Quality
  29. const KUALITAS = QUALITY_MEDIUM;
  30.  
  31. // Main Function for changing quality
  32. function SetQuality() {
  33. var mp = document.getElementById("movie_player");
  34. if (window.location.href.indexOf('watch?v=')>1){
  35. if (mp.getPlaybackQuality() != KUALITAS &&
  36. mp.getAvailableQualityLevels().indexOf(KUALITAS) > -1)
  37. {
  38. Toast("Change "+mp.getPlaybackQuality()+" to "+ KUALITAS);
  39. mp.setPlaybackQualityRange(KUALITAS);
  40. }
  41. else
  42. {
  43. if (entut == 0 && mp.getPlaybackQuality() != "unknown"){
  44. Toast("Already "+ mp.getPlaybackQuality());
  45. entut = 1;
  46. }
  47. }
  48. }
  49. }
  50.  
  51. function Toast(text) {
  52. var x = document.getElementById("qualitytoast");
  53. x.className = "show";
  54. x.innerHTML = text;
  55. setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
  56. }
  57.  
  58. window.addEventListener("load", () => {
  59. var toastdiv = document.createElement('div');
  60. toastdiv.id = "qualitytoast";
  61. document.body.appendChild(toastdiv);
  62.  
  63. setTimeout(SetQuality, 1000);
  64. setInterval(SetQuality, 500);
  65.  
  66. GM_addStyle(`
  67. #qualitytoast {
  68. visibility: hidden;
  69. min-width: 250px;
  70. margin-left: -125px;
  71. background-color: #303030;
  72. color: #f9f9f9;
  73. text-align: center;
  74. border-radius: 10px;
  75. padding: 16px;
  76. position: fixed;
  77. z-index: 1;
  78. left: 50%;
  79. bottom: 30px;
  80. font-size: 21px;
  81. }
  82.  
  83. #qualitytoast.show {
  84. visibility: visible;
  85. -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  86. animation: fadein 0.5s, fadeout 0.5s 2.5s;
  87. }
  88.  
  89. @-webkit-keyframes fadein {
  90. from {bottom: 0; opacity: 0;}
  91. to {bottom: 30px; opacity: 1;}
  92. }
  93.  
  94. @keyframes fadein {
  95. from {bottom: 0; opacity: 0;}
  96. to {bottom: 30px; opacity: 1;}
  97. }
  98.  
  99. @-webkit-keyframes fadeout {
  100. from {bottom: 30px; opacity: 1;}
  101. to {bottom: 0; opacity: 0;}
  102. }
  103.  
  104. @keyframes fadeout {
  105. from {bottom: 30px; opacity: 1;}
  106. to {bottom: 0; opacity: 0;}
  107. }
  108. `);
  109.  
  110. });
  111.