Embed Tweak

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

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

  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, Https, Autohide, Theme, Hide Annotations and Hide Related. Latest version based on https://greasyfork.org/scripts/829-restore-youtube-embed-defaults
  6. // @version 13 August 2014 (1.3)
  7. // @include http*
  8. // @exclude *liveleak.com*
  9. // @exclude *.youtube.com/*
  10. // ==/UserScript==
  11. //
  12. // Set variables below
  13. //
  14. // Set Video Size, large or medium. Large (1024x576) medium (640x385)
  15. var videosize = 'medium';
  16. // nochangeurl must be set to no for player settings to work. yes = default url and no = modified url, size is always modified.
  17. var nochangeurl = 'no'
  18. // theme, options: light or dark
  19. var ytheme = 'light';
  20. // color, options: red or white
  21. var ycolor = 'white';
  22. // Set annotation = 0 or 1, 0 disables annotations
  23. var annotation = 0;
  24. // Show Related videos at end of playback, option: 1 or 0,
  25. var related = 0;
  26. // Force https option, 1 or 0, 1 enables https
  27. var ssl = 1;
  28. // Set autohide = 0 or 1, 1 enables auto hide of player controls. (0 is default behaviour)
  29. var autohide = 1;
  30. //
  31. //
  32. //
  33. //
  34. ////////////////////////////////////////////////
  35. // No need to modify anything past this point //
  36. ////////////////////////////////////////////////
  37. console.log('Embed Tweak - This script grants no special privileges, so it runs without security limitations.');
  38. var i,
  39. j,
  40. k,
  41. index;
  42. var video_id,
  43. video_url,
  44. video_link;
  45. var risky_elements,
  46. risky_attributes,
  47. risky_node;
  48. var risky_tags = [
  49. 'object',
  50. 'embed',
  51. 'iframe'
  52. ];
  53. var bad_elements = [
  54. ];
  55. var bad_ids = [
  56. ];
  57. for (i = 0; i < risky_tags.length; i++) {
  58. risky_elements = document.getElementsByTagName(risky_tags[i]);
  59. for (j = 0; j < risky_elements.length; j++) {
  60. index = 0;
  61. risky_attributes = risky_elements[j].attributes;
  62. for (k = 0; k < risky_attributes.length; k++) {
  63. risky_node = risky_attributes[k].nodeValue;
  64. if ((risky_node.indexOf('youtube.com') >= 0) || (risky_node.indexOf('youtube-nocookie.com') >= 0)) {
  65. risky_elements[j].style.display = 'none';
  66. if (risky_node.indexOf('/v/') >= 0) {
  67. index = risky_node.indexOf('/v/') + 3;
  68. } else if (risky_node.indexOf('?v=') >= 0) {
  69. index = risky_node.indexOf('?v=') + 3;
  70. } else if (risky_node.indexOf('/embed/') >= 0) {
  71. index = risky_node.indexOf('/embed/') + 7;
  72. }
  73. if (index > 0) {
  74. video_id = risky_node.substring(index, index + 11);
  75. bad_elements.push(risky_elements[j]);
  76. bad_ids.push(video_id);
  77. }
  78. break;
  79. }
  80. }
  81. }
  82. }
  83. for (i = 0; i < bad_ids.length; i++) {
  84. video_id = bad_ids[i];
  85. if (nochangeurl == 'yes') {
  86. video_url = 'http://www.youtube.com/embed/' + video_id;
  87. }
  88. else {
  89. if (ssl == 1) {
  90. protid = 'https://'
  91. }
  92. if (ssl == 0) {
  93. protid = 'http://'
  94. }
  95. if (ytheme == 'light') {
  96. ythemeid = 'theme=light&';
  97. }
  98. if (ytheme == 'dark') {
  99. ythemeid = 'theme=dark&';
  100. }
  101. if (annotation == 0) {
  102. ivid = 'iv_load_policy=3&';
  103. }
  104. if (annotation == 1) {
  105. ivid = 'iv_load_policy=1&';
  106. }
  107. if (related == 0) {
  108. relatedid = 'rel=0&';
  109. }
  110. if (related == 1) {
  111. relatedid = 'rel=1&';
  112. }
  113. if (autohide == 1) {
  114. ahid = 'autohide=1&';
  115. }
  116. if (autohide == 0) {
  117. ahid = 'autohide=0&';
  118. }
  119. if (ycolor == 'red') {
  120. ycolorid = 'color=red&';
  121. }
  122. if (ycolor == 'white') {
  123. ycolorid = 'color=white&';
  124. }
  125. video_url = protid + 'www.youtube.com/embed/' + video_id + '?' + ythemeid + ycolorid + ivid + relatedid + ahid;
  126. }
  127. video_link = document.createElement('iframe');
  128. video_link.setAttribute('src', video_url);
  129. // Set the width, if present
  130. if (videosize == 'large') {
  131. video_link.width = '1024';
  132. video_link.height = '576';
  133. }
  134. if (videosize == 'medium') {
  135. video_link.width = '640';
  136. video_link.height = '385';
  137. }
  138. video_link.setAttribute('frameborder', '0');
  139. video_link.setAttribute('allowfullscreen', '1');
  140. bad_elements[i].parentNode.replaceChild(video_link, bad_elements[i]);
  141. }