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 03 February 2013 (1.25)
  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.  
  32.  
  33. ////////////////////////////////////////////////
  34. // No need to modify anything past this point //
  35. ////////////////////////////////////////////////
  36.  
  37. console.log('Embed Tweak - This script grants no special privileges, so it runs without security limitations.');
  38.  
  39. // Modify existing iframes size and href
  40. var iFrames = document.getElementsByTagName('IFRAME');
  41. var iFramesLen = iFrames.length;
  42. for (var i = 0; i < iFramesLen; i++)
  43. {
  44. var ifr = iFrames[i];
  45. if (ifr.src.indexOf('youtube.com/embed/') > -1 || ifr.src.indexOf('youtube-nocookie.com/embed/') > -1) {
  46. if (videosize == 'large') {
  47. ifr.width = '1024';
  48. ifr.height = '576';
  49. }
  50. if (videosize == 'medium') {
  51. ifr.width = '640';
  52. ifr.height = '385';
  53. }
  54. //alert('0.1 ' + ifr.src);
  55. if (defaulturl == 1) {
  56. }
  57. else {
  58. if (https == 1) {
  59. ifr.src = ifr.src.replace(/http\:/, 'https:'); }
  60. if (privacy == 1) {
  61. ifr.src = ifr.src.replace(/youtube\.com/, 'youtube-nocookie.com'); }
  62. ifr.src += '?';
  63. if (autohide == 1) {
  64. ifr.src += '&autohide=1'; }
  65. if (ytheme == "light") {
  66. ifr.src += '&theme=light'; }
  67. if (ytheme == "dark") {
  68. ifr.src += '&theme=dark'; }
  69. if (ycolor == "red") {2
  70. ifr.src += '&color=red'; }
  71. if (ycolor == "white") {
  72. ifr.src += '&color=white'; }
  73. if (annotation == 0) {
  74. ifr.src += '&iv_load_policy=3'; }
  75. if (related == 0) {
  76. ifr.src += '&rel=0'; }
  77. }
  78. //alert('1 ' + ifr.src);
  79. }
  80. }
  81.  
  82.  
  83. // change other types of object embed tags
  84. var iObjects = document.getElementsByTagName('object');
  85. var iObjectsLen = iObjects.length;
  86. for (var i = 0; i < iObjectsLen; i++)
  87. {
  88. var iOr = iObjects[i];
  89. if (iOr.data.indexOf('youtube.com/v/') > -1 || iOr.data.indexOf('youtube-nocookie.com/v/') > -1) {
  90. if (videosize == 'large') {
  91. iOr.style.width = '1024px';
  92. iOr.style.height = '576px';
  93. }
  94. if (videosize == 'medium') {
  95. iOr.style.width = '640px';
  96. iOr.style.height = '385px';
  97. }
  98. //alert('0.2 ' + iOr.data);
  99. if (defaulturl == 1) {
  100. }
  101. else {
  102. if (https == 1) {
  103. iOr.data = iOr.data.replace(/http\:/, 'https:'); }
  104. if (privacy == 1) {
  105. iOr.data = iOr.data.replace(/youtube\.com/, 'youtube-nocookie.com'); }
  106. iOr.data = iOr.data.split('&')[0];
  107. iOr.data = iOr.data.split('?')[0];
  108. iOr.data += '?version=3';
  109. if (autohide == 1) {
  110. iOr.data += '&autohide=1'; }
  111. if (ytheme == "light") {
  112. iOr.data += '&theme=light'; }
  113. if (ytheme == "dark") {
  114. iOr.data += '&theme=dark'; }
  115. if (ycolor == "red") {
  116. iOr.data += '&color=red'; }
  117. if (ycolor == "white") {
  118. iOr.data += '&color=white'; }
  119. if (annotation == 0) {
  120. iOr.data += '&iv_load_policy=3'; }
  121. if (related == 0) {
  122. iOr.data += '&rel=0'; }
  123. //alert('2 ' + iOr.data);
  124. }
  125. }
  126. }
  127.  
  128. var iEmbeds = document.getElementsByTagName('embed');
  129. var iEmbedsLen = iEmbeds.length;
  130. for (var i = 0; i < iEmbedsLen; i++)
  131. {
  132. var iEr = iEmbeds[i];
  133. if (iEr.src.indexOf('youtube.com/v/') > -1 || iEr.src.indexOf('youtube-nocookie.com/v/') > -1) {
  134. if (videosize == 'large') {
  135. iEr.width = 1024;
  136. iEr.height = 576;
  137. }
  138. if (videosize == 'medium') {
  139. iEr.width = 640;
  140. iEr.height = 385;
  141. }
  142. //alert('0.3 ' + iEr.src);
  143. if (defaulturl == 1) {
  144. }
  145. else {
  146. if (https == 1) {
  147. iEr.src = iEr.src.replace(/http\:/, 'https:'); }
  148. if (privacy == 1) {
  149. iEr.src = iEr.src.replace(/youtube\.com/, 'youtube-nocookie.com'); }
  150. iEr.src = iEr.src.split('&')[0];
  151. iEr.src = iEr.src.split('?')[0];
  152. iEr.src += '?version=3';
  153. if (autohide == 1) {
  154. iEr.src += '&autohide=1'; }
  155. if (ytheme == "light") {
  156. iEr.src += '&theme=light'; }
  157. if (ytheme == "dark") {
  158. iEr.src += '&theme=dark'; }
  159. if (ycolor == "red") {
  160. iEr.src += '&color=red'; }
  161. if (ycolor == "white") {
  162. iEr.src += '&color=white'; }
  163. if (annotation == 0) {
  164. iEr.src += '&iv_load_policy=3'; }
  165. if (related == 0) {
  166. iEr.src += '&rel=0'; }
  167. }
  168. //alert('3 ' + iEr.src);
  169. /*
  170. //Testing adding a download link
  171. var vid = iEr.src.split("v/")[1].substring(0, 11)
  172. var a = document.createElement('a');
  173. a.textContent = 'Youtube Link';
  174. a.setAttribute('style', 'font-size: 12px; font-family: arial, verdana, sans-serif;');
  175. a.target = '_blank';
  176. a.href = 'https://www.youtube.com/watch?v='+vid;
  177. a.id = 'a_v_'+vid;
  178. iEr.parentNode.insertBefore(document.createElement('br'), iEr.nextSibling);
  179. iEr.parentNode.insertBefore(a, iEr.nextSibling.nextSibling);
  180. */
  181. }
  182. }