29 June, 2014

UserJS: Force video playback quality and disable autoplay on YouTube


This script forces the chosen quality and disables the autoplay feature for videos on YouTube.com


Download

Qualities:
"hd720"="720p"
"large"="480p"
"medium"="360p"
"small"="240p"
"tiny"="144p"

It also hides the video annotations and disables keyboard shortcuts (it may also force buffering).

▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌

// ==UserScript==
// @name YouTube - force player quality; disables autoplay;
// @include *youtube.com/watch*
// @author Drozdman
// ==/UserScript==

(function (window, document) {


if(window.location.href.match('watch') && !window.location.href.match('nohtml5=1')){
 var vid_id = window.location.href.match(/v=([^&]+)/)[1];

 window.location="https://www.youtube.com/watch?v="+vid_id+"&nohtml5=1"
} // added Nov30 2016


var quality="medium";
//qualities: "hd720"="720p"; "large"="480p"; "medium"="360p"; "small"="240p"; "tiny"="144p"



YT_player=function(){

var player=document.getElementById('movie_player') || document.getElementById('movie_player-flash') || document.getElementById('movie_player-html5') || document.getElementById('movie_player-html5-flash') || document.embeds[0];

var player_new=player.cloneNode(true);
var flashvars=player.getAttribute("flashvars");
var flashvars_new=flashvars.replace('vq=auto','vq='+quality).replace(/watermark=[^&]*/,'') +
"&autoplay=0&autohide=0" + "&vq=" + quality +
"&theme=dark&color=red&iv_load_policy=3&enablejsapi=1"+
"&disablekb=1" //disable shortcut keys
//+flashvars_new+="&dash=0"; // force buffering; not working for 144p, 1080p ;





player_new.setAttribute("flashvars",flashvars_new);

player.parentNode.replaceChild(player_new,player)

}

window.addEventListener('DOMContentLoaded',YT_player)


})(window, window.document)


//=========================================================================
/*

qualities: "hd720"="720p"; "large"="480p"; "medium"="360p"; "small"="240p"; "tiny"="144p"

&autoplay=0
&autohide=0 ; video controls hide
&theme=dark&color=red
&iv_load_policy=3 ;video annotations not shown by default
&enablejsapi=1
&disablekb=1 - disable shortcut keys

*/

▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌


1 comment: