Advertisement
Kocayine

Untitled

Jul 11th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Youtube Aspect
  3. // @description Adds buttons to toggle 4:3 and 16:9 aspect ratios on youtube
  4. // @namespace scupizzaboy - "fixed" by Kocayine
  5. // @include http://youtube.*/*
  6. // @include http://*.youtube.*/*
  7. // @include https://youtube.*/*
  8. // @include https://*.youtube.*/*
  9. // ==/UserScript==
  10.  
  11. function setAspectWide()
  12. {
  13. document = unsafeWindow.document;
  14. var player = document.getElementById('movie_player');
  15. var flashvars = player.getAttribute('flashvars').split('&');
  16. for (var i = 0; i < flashvars.length; i++)
  17. {
  18. if (flashvars[i].indexOf('keywords') == 0)
  19. {
  20. var keywords = flashvars[i].split('=')[1].split(',');
  21. var found = false;
  22. for (var j = 0; j < keywords.length; j++)
  23. {
  24. if (decodeURIComponent(keywords[j]) == 'yt:stretch=4:3')
  25. {
  26. keywords[j] = encodeURIComponent('yt:stretch=16:9');
  27. found = true;
  28. }
  29. }
  30. if (found == false)
  31. {
  32. keywords.push(encodeURIComponent('yt:stretch=16:9'));
  33. }
  34. flashvars[i] = 'keywords=' + keywords.join(',');
  35. }
  36. }
  37. player.setAttribute('flashvars', flashvars.join('&'));
  38. player.src += "";
  39. }
  40.  
  41. function setAspectNarrow()
  42. {
  43. document = unsafeWindow.document;
  44. var player = document.getElementById('movie_player');
  45. var flashvars = player.getAttribute('flashvars').split('&');
  46. for (var i = 0; i < flashvars.length; i++)
  47. {
  48. if (flashvars[i].indexOf('keywords') == 0)
  49. {
  50. var keywords = flashvars[i].split('=')[1].split(',');
  51. var found = false;
  52. for (var j = 0; j < keywords.length; j++)
  53. {
  54. if (decodeURIComponent(keywords[j]) == 'yt:stretch=16:9')
  55. {
  56. keywords[j] = encodeURIComponent('yt:stretch=4:3');
  57. found = true;
  58. }
  59. }
  60. if (found == false)
  61. {
  62. keywords.push(encodeURIComponent('yt:stretch=4:3'));
  63. }
  64. flashvars[i] = 'keywords=' + keywords.join(',');
  65. }
  66. }
  67. player.setAttribute('flashvars', flashvars.join('&'));
  68. player.src += "";
  69. }
  70.  
  71. var target = document.getElementById('watch-actions');
  72. var target2 = document.getElementById('watch7-secondary-actions');
  73.  
  74. var button = document.createElement('input');
  75. button.name = 'setAspectNarrow';
  76. button.setAttribute("class", "start yt-uix-tooltip-reverse yt-uix-button yt-uix-button-default yt-uix-tooltip");
  77. button.setAttribute("style", 'width:25px');
  78. button.type = 'button';
  79. button.value = '4:3';
  80. button.addEventListener('click', setAspectNarrow, false);
  81. if (target != null) target.appendChild(button);
  82. if (target2 != null) target2.appendChild(button);
  83.  
  84. var button = document.createElement('input');
  85. button.name = 'setAspectWide';
  86. button.setAttribute("class", "start yt-uix-tooltip-reverse yt-uix-button yt-uix-button-default yt-uix-tooltip");
  87. button.setAttribute("style", 'width:25px');
  88. button.type = 'button';
  89. button.value = '16:9';
  90. button.addEventListener('click', setAspectWide, false);
  91. if (target != null) target.appendChild(button);
  92. if (target2 != null) target2.appendChild(button);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement