Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2012
2,880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Youtube Aspect Remake
  3. // @description    Adds buttons to toggle 4:3 and 16:9 aspect ratios on youtube, probs to the great work of scupizzaboy who mades this script. I've just changed the buttons to make them more adapt at the new youtube design. Original Script: http://userscripts.org/scripts/show/101165
  4. // @namespace      NoXPhasma
  5. // @include        http://youtube.*/*
  6. // @include        http://*.youtube.*/*
  7. // @include        https://youtube.*/*
  8. // @include        https://*.youtube.*/*
  9. // @version        9
  10. // @date           2012-15-03
  11. // ==/UserScript==
  12.  
  13. function setAspectWide()
  14. {
  15.     document = unsafeWindow.document;
  16.     var player = document.getElementById('movie_player');
  17.     var flashvars = player.getAttribute('flashvars').split('&');
  18.     for (var i = 0; i < flashvars.length; i++)
  19.     {
  20.         if (flashvars[i].indexOf('keywords') == 0)
  21.         {
  22.             var keywords = flashvars[i].split('=')[1].split(',');
  23.             var found = false;
  24.             for (var j = 0; j < keywords.length; j++)
  25.             {
  26.                 if (decodeURIComponent(keywords[j]) == 'yt:stretch=4:3')
  27.                 {
  28.                     keywords[j] = encodeURIComponent('yt:stretch=16:9');
  29.                     found = true;
  30.                 }
  31.             }
  32.             if (found == false)
  33.             {
  34.                 keywords.push(encodeURIComponent('yt:stretch=16:9'));
  35.             }
  36.             flashvars[i] = 'keywords=' + keywords.join(',');
  37.         }
  38.     }
  39.     player.setAttribute('flashvars', flashvars.join('&'));
  40.     player.src += "";
  41. }
  42.  
  43. function setAspectNarrow()
  44. {
  45.     document = unsafeWindow.document;
  46.     var player = document.getElementById('movie_player');
  47.     var flashvars = player.getAttribute('flashvars').split('&');
  48.     for (var i = 0; i < flashvars.length; i++)
  49.     {
  50.         if (flashvars[i].indexOf('keywords') == 0)
  51.         {
  52.             var keywords = flashvars[i].split('=')[1].split(',');
  53.             var found = false;
  54.             for (var j = 0; j < keywords.length; j++)
  55.             {
  56.                 if (decodeURIComponent(keywords[j]) == 'yt:stretch=16:9')
  57.                 {
  58.                     keywords[j] = encodeURIComponent('yt:stretch=4:3');
  59.                     found = true;
  60.                 }
  61.             }
  62.             if (found == false)
  63.             {
  64.                 keywords.push(encodeURIComponent('yt:stretch=4:3'));
  65.             }
  66.             flashvars[i] = 'keywords=' + keywords.join(',');
  67.         }
  68.     }
  69.     player.setAttribute('flashvars', flashvars.join('&'));
  70.     player.src += "";
  71. }
  72.  
  73. function fixWindowBox()
  74. {
  75.     document = unsafeWindow.document;
  76.     var player = document.getElementById('movie_player');
  77.     var flashvars = player.getAttribute('flashvars').split('&');
  78.     for (var i = 0; i < flashvars.length; i++)
  79.     {
  80.         if (flashvars[i].indexOf('keywords') == 0)
  81.         {
  82.             var keywords = flashvars[i].split('=')[1].split(',');
  83.             var found = false;
  84.             for (var j = 0; j < keywords.length; j++)
  85.             {
  86.                 if (decodeURIComponent(keywords[j]) == 'yt:crop=16:9')
  87.                 {
  88.                     found = true;
  89.                 }
  90.             }
  91.             if (found == false)
  92.             {
  93.                 keywords.push(encodeURIComponent('yt:crop=16:9'));
  94.             }
  95.             flashvars[i] = 'keywords=' + keywords.join(',');
  96.         }
  97.     }
  98.     player.setAttribute('flashvars', flashvars.join('&'));
  99.     player.src += "";
  100. }
  101.  
  102. var target = document.getElementById('watch-actions');  
  103.  
  104. var group = document.createElement('span');
  105. group.setAttribute("class", "yt-uix-button-group");
  106. target.appendChild(group);
  107.  
  108. var button = document.createElement('input');
  109. button.setAttribute("class", "start yt-uix-tooltip-reverse  yt-uix-button yt-uix-button-default yt-uix-tooltip");
  110. button.setAttribute("style", 'width:17px;height:2.77em;padding:0px 6px');
  111. button.setAttribute("value", '4:3');
  112. button.setAttribute("title", "Stretch to 4:3");
  113. button.addEventListener('click', setAspectNarrow, false);
  114. group.appendChild(button);
  115.  
  116. var button = document.createElement('input');
  117. button.setAttribute("class", "middle yt-uix-tooltip-reverse  yt-uix-button yt-uix-button-default yt-uix-tooltip");
  118. button.setAttribute("style", 'width:24px;height:2.77em;padding:0px 6px');
  119. button.setAttribute("value", '16:9');
  120. button.setAttribute("title", "Stretch to 16:9");
  121. button.addEventListener('click', setAspectWide, false);
  122. group.appendChild(button);
  123.  
  124. var button = document.createElement('input');
  125. button.setAttribute("class", "end yt-uix-tooltip-reverse  yt-uix-button yt-uix-button-default yt-uix-tooltip");
  126. button.setAttribute("style", 'width:24px;height:2.77em;padding:0px 6px');
  127. button.setAttribute("value", 'Zoom');
  128. button.setAttribute("title", "Fix Windowboxing");
  129. button.addEventListener('click', fixWindowBox, false);
  130. group.appendChild(button);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement