var qualitychanger={mplayer:undefined,count:0,levels:Array,waitForYT:function(){qualitychanger.count++;if(!(qualitychanger.count>10))if(document.getElementById("movie_player"))if(typeof document.getElementById("movie_player").getPlaybackQuality=="function"){qualitychanger.mplayer=document.getElementById("movie_player");qualitychanger.changeQuality()}else window.setTimeout("qualitychanger.waitForYT()",100);else{qualitychanger.count++;window.setTimeout("qualitychanger.waitForYT()",100)}},changeQuality:function(){chrome.extension.sendRequest(-1,
function(a){if(a=="wide"){console.log("Widening the video.");document.getElementById("watch-video").className="wide";document.getElementById("content").className="watch-wide"}else if(a=="shrink"){console.log("Shrinking the video.");document.getElementById("watch-video").className="small";document.getElementById("content").className="watch-small"}});qualitychanger.levels=qualitychanger.mplayer.getAvailableQualityLevels();qualitychanger.mplayer.setPlaybackQuality("default");for(i=0;i<4;i++){var b=false;
chrome.extension.sendRequest(i,function(a){if(!b)for(u=0;u<qualitychanger.levels.length;u++)if(a==qualitychanger.levels[u]||a=="default"){b=true;console.log("Playing "+a+" quality video.");qualitychanger.mplayer.setPlaybackQuality(a);return}});if(b==true)return}}};window.addEventListener("load",qualitychanger.waitForYT,false);