Embed Tweak

Modifies Youtube embed videos, Forces all videos to a larger size (640x385) or (1024x576), With options for: Video Size, Privacy, Https, Autohide, Theme and Colour Setting, Hide Annotations and Hide Related.

2014-07-19 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Embed Tweak
  3. // @namespace embedtweak
  4. // @grant none
  5. // @description Modifies Youtube embed videos, Forces all videos to a larger size (640x385) or (1024x576), With options for: Video Size, Privacy, Https, Autohide, Theme and Colour Setting, Hide Annotations and Hide Related.
  6. // @version 19 July 2014 (1.26)
  7. // @include http*
  8. // @exclude *liveleak.com*
  9. // ==/UserScript==
  10. //
  11. // Set variables below
  12. //
  13. // Set Video Size, large or medium. Large (1024x576) medium (640x385)
  14. var videosize = "medium";
  15. // Force the url to not be modified, Improves Performance! NOTE: This must be set to 0 in order for the features below this to work. (video size is always modified)
  16. var defaulturl = 0;
  17. // theme, options: light or dark
  18. var ytheme = "dark";
  19. // color, options: red or white
  20. var ycolor = "white";
  21. // Set annotation = 0 or 1, 0 disables annotations
  22. var annotation = 0;
  23. // Show Related videos at end of playback, option: 1 or 0,
  24. var related = 0;
  25. // Force https option, 1 enables https,
  26. var https = 1;
  27. // Force Privacy domain youtube-nocookie.com. 1 forces,
  28. var privacy = 0;
  29. // Set autohide = 0 or 1, 1 enables auto hide of player controls. (0 is default behaviour)
  30. var autohide = 1;
  31. // enable fullscreen, v3 player does always enable fullscreen.
  32. var fullscreen = 1;
  33.  
  34.  
  35.  
  36. ////////////////////////////////////////////////
  37. // No need to modify anything past this point //
  38. ////////////////////////////////////////////////
  39.  
  40. console.log('Embed Tweak - This script grants no special privileges, so it runs without security limitations.');
  41.  
  42. // Modify existing iframes size and href
  43. var iFrames = document.getElementsByTagName('IFRAME');
  44. var iFramesLen = iFrames.length;
  45. for (var i = 0; i < iFramesLen; i++)
  46. {
  47. var ifr = iFrames[i];
  48. if (ifr.src.indexOf('youtube.com/embed/') > -1 || ifr.src.indexOf('youtube-nocookie.com/embed/') > -1) {
  49. if (videosize == 'large') {
  50. ifr.width = '1024';
  51. ifr.height = '576';
  52. }
  53. if (videosize == 'medium') {
  54. ifr.width = '640';
  55. ifr.height = '385';
  56. }
  57. if (fullscreen == 1) {
  58. ifr.allowfullscreen = '1';
  59. }
  60. //alert('0.1 ' + ifr.src);
  61. if (defaulturl == 1) {
  62. }
  63. else {
  64. if (https == 1) {
  65. ifr.src = ifr.src.replace(/http\:/, 'https:'); }
  66. if (privacy == 1) {
  67. ifr.src = ifr.src.replace(/youtube\.com/, 'youtube-nocookie.com'); }
  68. ifr.src += '?';
  69. if (autohide == 1) {
  70. ifr.src += '&autohide=1'; }
  71. if (ytheme == "light") {
  72. ifr.src += '&theme=light'; }
  73. if (ytheme == "dark") {
  74. ifr.src += '&theme=dark'; }
  75. if (ycolor == "red") {
  76. ifr.src += '&color=red'; }
  77. if (ycolor == "white") {
  78. ifr.src += '&color=white'; }
  79. if (annotation == 0) {
  80. ifr.src += '&iv_load_policy=3'; }
  81. if (related == 0) {
  82. ifr.src += '&rel=0'; }
  83. }
  84. //alert('1 ' + ifr.src);
  85. }
  86. }
  87.  
  88.  
  89. // change other types of object embed tags
  90. var iEmbeds = document.getElementsByTagName('embed');
  91. var iEmbedsLen = iEmbeds.length;
  92. for (var i = 0; i < iEmbedsLen; i++)
  93. {
  94. var iEr = iEmbeds[i];
  95. if (iEr.src.indexOf('youtube.com/v/') > -1 || iEr.src.indexOf('youtube-nocookie.com/v/') > -1) {
  96. if (videosize == 'large') {
  97. iEr.width = 1024;
  98. iEr.height = 576;
  99. }
  100. if (videosize == 'medium') {
  101. iEr.width = 640;
  102. iEr.height = 385;
  103. }
  104. //alert('0.3 ' + iEr.src);
  105. if (defaulturl == 1) {
  106. }
  107. else {
  108. if (https == 1) {
  109. iEr.src = iEr.src.replace(/http\:/, 'https:'); }
  110. if (privacy == 1) {
  111. iEr.src = iEr.src.replace(/youtube\.com/, 'youtube-nocookie.com'); }
  112. iEr.src = iEr.src.split('&')[0];
  113. iEr.src = iEr.src.split('?')[0];
  114. iEr.src += '?version=3';
  115. if (autohide == 1) {
  116. iEr.src += '&autohide=1'; }
  117. if (ytheme == "light") {
  118. iEr.src += '&theme=light'; }
  119. if (ytheme == "dark") {
  120. iEr.src += '&theme=dark'; }
  121. if (ycolor == "red") {
  122. iEr.src += '&color=red'; }
  123. if (ycolor == "white") {
  124. iEr.src += '&color=white'; }
  125. if (annotation == 0) {
  126. iEr.src += '&iv_load_policy=3'; }
  127. if (related == 0) {
  128. iEr.src += '&rel=0'; }
  129. if (fullscreen == 1) {
  130. iEr.src += '&fs=1'; }
  131. }
  132. //alert('3 ' + iEr.src);
  133. /*
  134. //Testing adding a download link
  135. var vid = iEr.src.split("v/")[1].substring(0, 11)
  136. var a = document.createElement('a');
  137. a.textContent = 'Youtube Link';
  138. a.setAttribute('style', 'font-size: 12px; font-family: arial, verdana, sans-serif;');
  139. a.target = '_blank';
  140. a.href = 'https://www.youtube.com/watch?v='+vid;
  141. a.id = 'a_v_'+vid;
  142. iEr.parentNode.insertBefore(document.createElement('br'), iEr.nextSibling);
  143. iEr.parentNode.insertBefore(a, iEr.nextSibling.nextSibling);
  144. */
  145. }
  146. }