Embed Tweak

Modifies Youtube embed videos, Forces all videos to a larger size (640x385) or (1024x576), With options for: Video Size, HD Playback, Https, Autohide, Theme, Hide Annotations and Hide Related. Latest version based on https://greasyfork.org/scripts/829-restore-youtube-embed-defaults

当前为 2014-08-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Embed Tweak
  3. // @namespace embedtweak
  4. // @grant none
  5. // @icon http://i.imgur.com/JyEgdDl.png
  6. // @description Modifies Youtube embed videos, Forces all videos to a larger size (640x385) or (1024x576), With options for: Video Size, HD Playback, Https, Autohide, Theme, Hide Annotations and Hide Related. Latest version based on https://greasyfork.org/scripts/829-restore-youtube-embed-defaults
  7. // @version 30 August 2014 (1.42)
  8. // @include http*
  9. // @exclude *liveleak.com*
  10. // @exclude *.youtube.com/*
  11. // ==/UserScript==
  12. //
  13. // Set variables below
  14. //
  15. // Set Video Size, large or medium. Large (1024x576) medium (640x385) or Set size in percentage, for a video size based off the container size.
  16. var videosize = 'medium';
  17. // or
  18. //var videosize = '50%';
  19. // nochangeurl must be set to no for player settings to work. yes = default url and no = modified url, size is always modified.
  20. var nochangeurl = 'no';
  21. // hd = 0 or 1 or 2. 0 = default, 1 = 720p , 2 = 1080p. if available.
  22. var hd = 1;
  23. // theme, options: light or dark
  24. var ytheme = 'dark';
  25. // color, options: red or white
  26. var ycolor = 'white';
  27. // Set annotation = 0 or 1, 0 disables annotations
  28. var annotation = 0;
  29. // Show Related videos at end of playback, option: 1 or 0,
  30. var related = 0;
  31. // Force https option, 1 or 0, 1 enables https
  32. var ssl = 1;
  33. // Set autohide = 0 or 1, 1 enables auto hide of player controls. (0 is default behaviour)
  34. var autohide = 1;
  35. //
  36. //
  37. //
  38. //
  39. ////////////////////////////////////////////////
  40. // No need to modify anything past this point //
  41. ////////////////////////////////////////////////
  42. console.log('Embed Tweak - This script grants no special privileges, so it runs without security limitations.');
  43. var i,
  44. j,
  45. k,
  46. index;
  47. var video_id,
  48. video_url,
  49. video_link;
  50. var risky_elements,
  51. risky_attributes,
  52. risky_node;
  53. var risky_tags = [
  54. 'object',
  55. 'embed',
  56. 'iframe'
  57. ];
  58. var bad_elements = [
  59. ];
  60. var bad_ids = [
  61. ];
  62. for (i = 0; i < risky_tags.length; i++) {
  63. risky_elements = document.getElementsByTagName(risky_tags[i]);
  64. for (j = 0; j < risky_elements.length; j++) {
  65. index = 0;
  66. risky_attributes = risky_elements[j].attributes;
  67. for (k = 0; k < risky_attributes.length; k++) {
  68. risky_node = risky_attributes[k].nodeValue;
  69. if ((risky_node.indexOf('youtube.com') >= 0) || (risky_node.indexOf('youtube-nocookie.com') >= 0)) {
  70. risky_elements[j].style.display = 'none';
  71. if (risky_node.indexOf('/v/') >= 0) {
  72. index = risky_node.indexOf('/v/') + 3;
  73. } else if (risky_node.indexOf('?v=') >= 0) {
  74. index = risky_node.indexOf('?v=') + 3;
  75. } else if (risky_node.indexOf('/embed/') >= 0) {
  76. index = risky_node.indexOf('/embed/') + 7;
  77. }
  78. if (index > 0) {
  79. video_id = risky_node.substring(index, index + 11);
  80. bad_elements.push(risky_elements[j]);
  81. bad_ids.push(video_id);
  82. }
  83. break;
  84. }
  85. }
  86. }
  87. }
  88. for (i = 0; i < bad_ids.length; i++) {
  89. video_id = bad_ids[i];
  90. if (nochangeurl == 'yes') {
  91. video_url = 'http://www.youtube.com/embed/' + video_id;
  92. }
  93. else {
  94. if (ssl == 1) {
  95. protid = 'https://'
  96. }
  97. if (ssl == 0) {
  98. protid = 'http://'
  99. }
  100. if (ytheme == 'light') {
  101. ythemeid = 'theme=light&';
  102. }
  103. if (ytheme == 'dark') {
  104. ythemeid = 'theme=dark&';
  105. }
  106. if (annotation == 0) {
  107. ivid = 'iv_load_policy=3&';
  108. }
  109. if (annotation == 1) {
  110. ivid = 'iv_load_policy=1&';
  111. }
  112. if (related == 0) {
  113. relatedid = 'rel=0&';
  114. }
  115. if (related == 1) {
  116. relatedid = 'rel=1&';
  117. }
  118. if (autohide == 1) {
  119. ahid = 'autohide=1&';
  120. }
  121. if (autohide == 0) {
  122. ahid = 'autohide=0&';
  123. }
  124. if (ycolor == 'red') {
  125. ycolorid = 'color=red&';
  126. }
  127. if (ycolor == 'white') {
  128. ycolorid = 'color=white&';
  129. }
  130. if (hd == 0) {
  131. hdid = 'vq=default&';
  132. }
  133. if (hd == 1) {
  134. hdid = 'vq=hd720&';
  135. }
  136. if (hd == 2) {
  137. hdid = 'vq=hd1080&';
  138. }
  139. video_url = protid + 'www.youtube.com/embed/' + video_id + '?' + ythemeid + ycolorid + ivid + relatedid + ahid + hdid;
  140. }
  141. video_link = document.createElement('iframe');
  142. video_link.setAttribute('src', video_url);
  143. if (vsm = videosize.match(/^\s*(\d+)%\s*$/)) { // percentage size code thanks to wOxxOm
  144. var parent = bad_elements[i].parentNode;
  145. while (parent) {
  146. available_width = parent.offsetWidth || parent.clientWidth;
  147. if (available_width > 0) {
  148. video_link.width = available_width * vsm[1] / 100;
  149. video_link.height = Math.floor(video_link.width / 16 * 9);
  150. break;
  151. }
  152. parent = parent.parentNode;
  153. }
  154. }
  155. if (videosize == 'large') {
  156. video_link.width = '1024';
  157. video_link.height = '576';
  158. }
  159. if (videosize == 'medium') {
  160. video_link.width = '640';
  161. video_link.height = '385';
  162. }
  163. video_link.setAttribute('frameborder', '0');
  164. video_link.setAttribute('allowfullscreen', '1');
  165. bad_elements[i].parentNode.replaceChild(video_link, bad_elements[i]);
  166. }