FYTE /Fast YouTube Embedded/ Player

Hugely improves load speed of pages with lots of embedded Youtube videos by instantly showing clickable and immediately accessible placeholders, then the thumbnails are loaded in background. Optionally a fast simple HTML5 direct playback (720p max) can be selected if available for the video.

当前为 2016-10-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FYTE /Fast YouTube Embedded/ Player
  3. // @description Hugely improves load speed of pages with lots of embedded Youtube videos by instantly showing clickable and immediately accessible placeholders, then the thumbnails are loaded in background. Optionally a fast simple HTML5 direct playback (720p max) can be selected if available for the video.
  4. // @description:ru На порядок ускоряет время загрузки страниц с большим количеством вставленных Youtube-видео. С первого момента загрузки страницы появляются заглушки для видео, которые можно щелкнуть для загрузки плеера, и почти сразу же появляются кавер-картинки с названием видео. В опциях можно включить режим использования упрощенного браузерного плеера (макс. 720p).
  5. // @version 2.7.4
  6. // @include *
  7. // @exclude /^https:\/\/www\.youtube\.com\/(?!embed)/
  8. // @exclude https://plus.google.*/_/notifications/frame*
  9. // @exclude https://accounts.google.*/o/oauth2/postmessageRelay*
  10. // @exclude https://clients*.google.*/youtubei/*
  11. // @exclude https://clients*.google.*/static/proxy*
  12. // @author wOxxOm
  13. // @namespace wOxxOm.scripts
  14. // @license MIT License
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @grant GM_addStyle
  18. // @grant GM_xmlhttpRequest
  19. // @connect www.youtube.com
  20. // @connect youtube.com
  21. // @run-at document-start
  22. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACABAMAAAAxEHz4AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAwUExURUxpcQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJuxkb8AAAAPdFJOUwDvH0biMvjOZFW6pxJ6kh7r3iMAAAPDSURBVGje7ZlNaBNBFMeXhNDWpkKgFg9iYlBB6SGwiPQkftaCYATjTaRKiwi1xVaKXpqTpHhosR66p4pQhb209CQGbSweK/TiRYwfFy+NkWBM2pR2nHm73abJzuceRMj/kEzSvl92Z9689+atpjXUUEMN1WgpoRupbH41nTbNUaxzlkIhe0C+M810Ov8zmzL0RGeNeeDThUEkof72N/Fqe/8LJK07sR173yJS0EbEATxFSurZtm9DilqxAV9VAZuWfbPbLBOFqtSBP9f/WxIAV2Bc6H5owiKPG7p+IpFIRG11LsPbEfyVrhvTqeyX1dfmaBiM9gFgjgwrTzJSfncMFq7s3EExJuu5/rHte3hPBvfkff84sbuEBxPkUiLygCC5hDV7CvpUtt81axICZBN9UwHsxYalOMxhIaIC8IVhFlvJtlALIWQl57Um/LquBpjBpkOwin1qADKLB7RD9moqiPz2TcAMqQGa4OI9Av5op/DrMzXAHmz6mw4IxEQA67AW825/bhngAVoBMEHzZD+aFQCsQUCkAAor/M2wCYAVdwCqxJmANgD8cmJjPQDt5wK22AD0nAVoBsAiE1BMcgAbAJikAqoTYP1CA4BEtBgdgC6yARUuAC3QI7sDiLMAxUk2YAwiIwNAn4YAhGU+YKcOqAUMCgJQziugHGMALmNAhANAWxkaoEgABS4ADdMyiyiglPMIcJ0GKQAayDAAGQEAuu8VUB/gJAH1AS4IgLAwAA24AAoygAeuAPFbqHPHoNwc1HuCJCDncRl7NG8At7Ak48qugVEGsOBxO7snB58T0ngASlwWjomFpMegOusxrFOLBCexsFMbvUzxCyVXRqEkBpjlpXdOgcEqFlsEKpRynFviMIus0md+kcUEDAuUeaxCcysjUGgySt1yTKTUZRTbOaFim17unxUr92doBw4f9zTKObGInZl+//NTW592VP3g+Q4Onh6Ovjfgt5vsPoSCJuDuPRz/58CFmhEtKPIEvY8kZAd3VxRxRJJSyIXcUu0/VOz3okITJRC2ex9kGdB5ecBVZLtgCyt70fUB2nGTTjOu/HFZohsXXLoOrbQKfDps1ePtTj9wSter2oGWoBnYRZqB+bQ5OnLaShpnrNAz6N6R7OW1I1HJjnmPVFuit7eDV1jNvuAkpJNqgJ0DQPCHiv3dqmULfJe3P7hrB/oej3T0S/Tme7tf1Xp/MArPB/Ayp82X5OlAaJfI8wHsJ2/zWXg6EGV4XXB5CbuN3mUYxnQKNI6HU9i3op0y3tpQQw39b/oLfDt0HcsiqWsAAAAASUVORK5CYII=
  23. // @compatible chrome
  24. // @compatible firefox
  25. // @compatible opera
  26. // ==/UserScript==
  27.  
  28. /* jshint lastsemic:true, multistr:true, laxbreak:true, -W030, -W041, -W084 */
  29.  
  30. if (location.href.indexOf('https://www.youtube.com/') == 0) {
  31. if (!window.chrome || window == window.parent
  32. || !location.href.match(/^https:\/\/www\.youtube\.com\/embed.*?FYTEfullscreen=1/))
  33. return;
  34. var fsbtn = document.getElementsByClassName('ytp-fullscreen-button');
  35. new MutationObserver(function() {
  36. if (fsbtn[0]) {
  37. this.disconnect();
  38. fsbtn[0].outerHTML = fsbtn[0].outerHTML;
  39. fsbtn[0].addEventListener('click', function(e) {
  40. window.parent.postMessage('FYTE-toggle-fullscreen', '*');
  41. });
  42. }
  43. }).observe(document, {subtree:true, childList:true});
  44. return;
  45. }
  46.  
  47. var resizeMode = GM_getValue('resize', 'Fit to width');
  48. if (typeof resizeMode != 'string')
  49. resizeMode = resizeMode ? 'Fit to width' : 'Original';
  50.  
  51. var resizeWidth = GM_getValue('width', 1280) |0;
  52. var resizeHeight = GM_getValue('height', 720) |0;
  53. updateCustomSize();
  54.  
  55. var playDirectly = !!GM_getValue('playHTML5', false);
  56. var skipCustom = !!GM_getValue('skipCustom', true);
  57. var showStoryboard = !!GM_getValue('showStoryboard', true);
  58. var pinnable = GM_getValue('pinnable', 'on');
  59. if (!/^(on|hide|off)$/.test(pinnable))
  60. pinnable = !!pinnable ? 'on' : 'hide';
  61.  
  62. var _ = initTL();
  63.  
  64. var imageLoader = document.createElement('img');
  65. var imageLoader2 = document.createElement('img');
  66.  
  67. var fytedom = document.getElementsByClassName('instant-youtube-container');
  68. var iframes = document.getElementsByTagName('iframe');
  69. var objects = document.getElementsByTagName('object');
  70. var persite = (function() {
  71. var rules = [
  72. {host: /(^|\.)google\.\w{2,3}(\.\w{2,3})?$/, class:'g-blk', query: 'a[href*="youtube.com/watch"][data-ved]', eatparent: 1},
  73. {host: 'pikabu.ru', class:'b-video', match: '[data-url*="youtube.com/embed"]', attr: 'data-url'},
  74. {host: 'androidauthority.com', eatparent: '.video-container'},
  75. {host: 'reddit.com',
  76. match: '[data-url*="youtube.com/"] [src*="/mediaembed"], [data-url*="youtu.be/"] [src*="/mediaembed"]',
  77. src: function(e) { return e.closest('[data-url*="youtube.com/"], [data-url*="youtu.be/"]').dataset.url }},
  78. {host: '9gag.com', eatparent: 0},
  79. ];
  80. for (var i=0, rule; (i<rules.length) && (rule=rules[i]); i++) {
  81. var rx = rule.host instanceof RegExp ? rule.host : new RegExp('(^|\\.)' + rule.host.replace(/\./g, '\\.') + '$', 'i');
  82. if (rx.test(location.hostname)) {
  83. if (!rule.tag && !rule.class)
  84. rule.tag = 'iframe';
  85. if (!rule.match && !rule.query)
  86. rule.match = '[src*="youtube.com/embed"]';
  87. return {
  88. nodes: rule.class ? document.getElementsByClassName(rule.class) : document.getElementsByTagName(rule.tag),
  89. match: rule.match ? function(e) { return e.matches(rule.match) ? e : null }
  90. : function(e) { return e.querySelector(rule.query) },
  91. attr: rule.attr,
  92. src: rule.src,
  93. eatparent: rule.eatparent,
  94. };
  95. }
  96. }
  97. })();
  98.  
  99. findEmbeds();
  100. injectStylesIfNeeded();
  101. new MutationObserver(findEmbeds).observe(document, {subtree:true, childList:true});
  102.  
  103. document.addEventListener('DOMContentLoaded', function(e) {
  104. injectStylesIfNeeded();
  105. adjustNodesIfNeeded(e);
  106. });
  107. window.addEventListener('resize', adjustNodesIfNeeded, true);
  108. window.addEventListener('message', function(e) {
  109. if (e.data == 'FYTE-toggle-fullscreen') {
  110. $$('iframe[allowfullscreen]').some(function(iframe) {
  111. if (iframe.contentWindow == e.source) {
  112. goFullscreen(iframe, !(document.webkitIsFullScreen || document.mozIsFullScreen || document.isFullScreen));
  113. return true;
  114. }
  115. });
  116. }
  117. else if (e.data == 'iframe-allowfs') {
  118. $$('iframe:not([allowfullscreen])').some(function(iframe) {
  119. if (iframe.contentWindow == e.source) {
  120. iframe.allowFullscreen = true;
  121. return true;
  122. }
  123. });
  124. if (window != window.top)
  125. window.parent.postMessage('iframe-allowfs', '*');
  126. }
  127. });
  128.  
  129. function findEmbeds(mutations) {
  130. var i, len, e, m;
  131. if (mutations && mutations.length == 1 && !mutations[0].addedNodes.length)
  132. return;
  133. if (persite)
  134. for (i=0, len=persite.nodes.length; (i<len) && (e=persite.nodes[i]); i++)
  135. if (e = persite.match(e))
  136. processEmbed(e, persite.src && persite.src(e) || e.getAttribute(persite.attr));
  137. for (i=0, len=iframes.length; (i<len) && (e=iframes[i]); i++)
  138. if (/youtube\.com|youtu\.be/i.test(e.src))
  139. processEmbed(e);
  140. for (i=0, len=objects.length; (i<len) && (e=objects[i]); i++)
  141. if (m = e.querySelector('embed, [value*="youtu.be"], [value*="youtube.com"]'))
  142. processEmbed(e, m.src || 'https://' + m.value.match(/youtu\.be.*|youtube\.com.*/)[0]);
  143. }
  144.  
  145. function processEmbed(node, src) {
  146. function decodeEmbedUrl(url) {
  147. return url.indexOf('youtube.com%2Fembed') > 0
  148. ? decodeURIComponent(url.replace(/^.*?(http[^&?=]+?youtube.com%2Fembed[^&]+).*$/i, '$1'))
  149. : url;
  150. }
  151. src = src || node.src || node.href || '';
  152. var n = node;
  153. var np = n.parentNode, npw;
  154. var srcFixed = decodeEmbedUrl(src).replace(/\/(watch\?v=|v\/)/, '/embed/');
  155. if (src.indexOf('cdn.embedly.com/') > 0 ||
  156. resizeMode != 'Original' && np && np.children.length == 1 && !np.className && !np.id)
  157. {
  158. n = location.hostname == 'disqus.com' ? np.parentNode : np;
  159. np = n.parentElement;
  160. }
  161. if (!np ||
  162. !np.parentNode ||
  163. skipCustom && srcFixed.indexOf('enablejsapi=1') > 0 ||
  164. node.matches('.instant-youtube-embed, .YTLT-embed') ||
  165. node.onload // skip some retarded loaders
  166. )
  167. return;
  168.  
  169. var id = srcFixed.match(/(?:^https?:\/\/)(?:www\.)?(?:youtube\.com\/(?:embed\/|\/.*?[&?\/]v[=\/])|youtu\.be\/)([^\s,.()\[\]?]+?)(?:[&?\/].*|$)/);
  170. if (!id)
  171. return;
  172. id = id[1];
  173.  
  174. var autoplay = srcFixed.indexOf('autoplay=1') > 0;
  175.  
  176. if (np.localName == 'object')
  177. n = np, np = n.parentElement;
  178.  
  179. var eatparent = persite && persite.eatparent || 0;
  180. if (typeof eatparent == 'string')
  181. n = np.closest(eatparent) || n, np = n.parentElement;
  182. else
  183. while (eatparent--)
  184. n = np, np = n.parentElement;
  185.  
  186. injectStylesIfNeeded('force');
  187.  
  188. var div = document.createElement('div');
  189. div.className = 'instant-youtube-container';
  190. div.FYTE = {
  191. state: 'querying',
  192. srcEmbed: srcFixed.replace(/&$/, ''),
  193. originalWidth: /%/.test(node.width) ? 320 : node.width|0 || n.clientWidth|0,
  194. originalHeight: /%/.test(node.height) ? 200 : node.height|0 || n.clientHeight|0,
  195. cache: JSON.parse(GM_getValue('cache-' + id, '0')) || {
  196. id: id,
  197. }
  198. };
  199. div.FYTE.srcEmbedFixed = div.FYTE.srcEmbed.replace(/^http:/, 'https:').replace(/&?wmode=\w+/, '').replace(/[?&]feature=oembed/, '');
  200. div.FYTE.srcWatchFixed = div.FYTE.srcEmbedFixed.replace(/\/embed\//, '/watch?v=');
  201.  
  202. var cache = div.FYTE.cache;
  203.  
  204. if (cache.reason)
  205. div.setAttribute('disabled', '');
  206.  
  207. var divSize = calcContainerSize(div, n);
  208. var origStyle = getComputedStyle(n);
  209. div.style.cssText = important(
  210. (autoplay ? '' : 'background-color:transparent; transition:background-color 2s;') +
  211. (origStyle.hasOwnProperty('position') ? Object.keys(origStyle) : Object.keys(origStyle.__proto__) /*FF*/)
  212. .filter(function(k) { return !!k.match(/^(position|left|right|top|bottom)$/) })
  213. .map(function(k) { return k + ':' + origStyle[k] })
  214. .join(';')
  215. .replace(/\b[^;:]+:\s*(auto|static|block)\s*(!\s*important)?;/g, '') +
  216. (origStyle.display == 'inline' ? ';display:inline-block;width:100%' : '') +
  217. ';min-width:' + Math.min(divSize.w, div.FYTE.originalWidth) + 'px' +
  218. ';min-height:' + Math.min(divSize.h, div.FYTE.originalHeight) + 'px' +
  219. (resizeMode == 'Fit to width' ? ';width:100%' : '') +
  220. ';max-width:' + divSize.w + 'px; height:' + (persite && persite.eatparent === 0 ? '100%' : divSize.h + 'px;'));
  221. if (!autoplay) {
  222. setTimeout(function() { div.style.backgroundColor = '' }, 0);
  223. setTimeout(function() { div.style.transition = '' }, 2000);
  224. }
  225.  
  226. // consume parents of retardedly positioned videos
  227. if (div.style.position.match('absolute|relative')) {
  228. if (np.children.length == 1 && floatPadding(np, getComputedStyle(np, ':after'), 'Top') >= div.FYTE.originalHeight)
  229. n = np, np = n.parentElement;
  230. div.style.cssText = div.style.cssText.replace(/\b(position|left|top|right|bottom):[^;]+/g, '');
  231. }
  232.  
  233. var wrapper = div.appendChild(document.createElement('div'));
  234. wrapper.className = 'instant-youtube-wrapper';
  235.  
  236. var img = wrapper.appendChild(document.createElement('img'));
  237. if (!autoplay)
  238. img.src = 'https://i.ytimg.com/vi/' + id + '/' + (cache.cover || 'maxresdefault.jpg');
  239. img.className = 'instant-youtube-thumbnail';
  240. img.style.cssText = important((cache.cover ? '' : 'transition:opacity 0.1s ease-out; opacity:0; ') +
  241. 'padding:0; margin:auto; position:absolute; left:0; right:0; top:0; bottom:0; max-width:none; max-height:none;');
  242.  
  243. img.title = _('Shift-click to use alternative player');
  244. img.onload = function(e) {
  245. if (img.naturalWidth <= 120 && !cache.coverHeight)
  246. return img.onerror(e);
  247. var fitToWidth = true;
  248. if (img.naturalHeight || cache.coverHeight) {
  249. if (!cache.coverHeight) {
  250. cache.coverWidth = img.naturalWidth;
  251. cache.coverHeight = img.naturalHeight;
  252. GM_setValue('cache-' + id, JSON.stringify(cache));
  253. }
  254. var ratio = cache.coverWidth / cache.coverHeight;
  255. if (ratio > 4.1/3 && ratio < divSize.w/divSize.h) {
  256. img.style.cssText += important('width:auto; height:100%;');
  257. fitToWidth = false;
  258. }
  259. }
  260. if (fitToWidth) {
  261. img.style.cssText += important('width:100%; height:auto;');
  262. }
  263. if (cache.videoWidth)
  264. fixThumbnailAR(div);
  265. if (!autoplay)
  266. img.style.opacity = 1;
  267. };
  268. img.onerror = function(e) {
  269. if (img.src.indexOf('maxresdefault') > 0)
  270. img.src = img.src.replace('maxresdefault','hqdefault');
  271. };
  272. if (cache.coverWidth)
  273. img.onload();
  274.  
  275. translateHTML(wrapper, 'beforeend', '\
  276. <a class="instant-youtube-title" target="_blank" href="' + div.FYTE.srcWatchFixed + '">' +
  277. (cache.title || cache.reason ? '<strong>' + (cache.title || cache.reason || '') + '</strong>' +
  278. '<span>' + (cache.duration || '') + '</span>'
  279. : '&nbsp;') + '</a>\
  280. <svg class="instant-youtube-play-button"><path fill-rule="evenodd" clip-rule="evenodd" fill="#1F1F1F" class="ytp-large-play-button-svg" d="M84.15,26.4v6.35c0,2.833-0.15,5.967-0.45,9.4c-0.133,1.7-0.267,3.117-0.4,4.25l-0.15,0.95c-0.167,0.767-0.367,1.517-0.6,2.25c-0.667,2.367-1.533,4.083-2.6,5.15c-1.367,1.4-2.967,2.383-4.8,2.95c-0.633,0.2-1.316,0.333-2.05,0.4c-0.767,0.1-1.3,0.167-1.6,0.2c-4.9,0.367-11.283,0.617-19.15,0.75c-2.434,0.034-4.883,0.067-7.35,0.1h-2.95C38.417,59.117,34.5,59.067,30.3,59c-8.433-0.167-14.05-0.383-16.85-0.65c-0.067-0.033-0.667-0.117-1.8-0.25c-0.9-0.133-1.683-0.283-2.35-0.45c-2.066-0.533-3.783-1.5-5.15-2.9c-1.033-1.067-1.9-2.783-2.6-5.15C1.317,48.867,1.133,48.117,1,47.35L0.8,46.4c-0.133-1.133-0.267-2.55-0.4-4.25C0.133,38.717,0,35.583,0,32.75V26.4c0-2.833,0.133-5.95,0.4-9.35l0.4-4.25c0.167-0.966,0.417-2.05,0.75-3.25c0.7-2.333,1.567-4.033,2.6-5.1c1.367-1.434,2.967-2.434,4.8-3c0.633-0.167,1.333-0.3,2.1-0.4c0.4-0.066,0.917-0.133,1.55-0.2c4.9-0.333,11.283-0.567,19.15-0.7C35.65,0.05,39.083,0,42.05,0L45,0.05c2.467,0,4.933,0.034,7.4,0.1c7.833,0.133,14.2,0.367,19.1,0.7c0.3,0.033,0.833,0.1,1.6,0.2c0.733,0.1,1.417,0.233,2.05,0.4c1.833,0.566,3.434,1.566,4.8,3c1.066,1.066,1.933,2.767,2.6,5.1c0.367,1.2,0.617,2.284,0.75,3.25l0.4,4.25C84,20.45,84.15,23.567,84.15,26.4z M33.3,41.4L56,29.6L33.3,17.75V41.4z"></path><polygon fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" points="33.3,41.4 33.3,17.75 56,29.6"></polygon></svg>\
  281. <span tl class="instant-youtube-alternative">' + (playDirectly ? 'Play with Youtube player' : 'Play directly (up to 720p)') + '</span>\
  282. <div tl class="instant-youtube-options-button">Options</div>\
  283. ');
  284.  
  285. np.insertBefore(div, n);
  286. n.remove();
  287.  
  288. if (!cache.title && !cache.reason || autoplay && playDirectly)
  289. fetchInfo();
  290.  
  291. if (autoplay)
  292. return startPlaying(div);
  293.  
  294. div.addEventListener('click', clickHandler);
  295. div.addEventListener('mousedown', clickHandler);
  296. div.addEventListener('mouseenter', fetchInfo);
  297.  
  298. function fetchInfo(e) {
  299. div.removeEventListener('mouseenter', fetchInfo);
  300. GM_xmlhttpRequest({
  301. method: 'GET',
  302. url: 'https://www.youtube.com/get_video_info?video_id=' + id +
  303. '&hl=en_US&html5=1&el=embedded&eurl=' + encodeURIComponent(location.href),
  304. headers: {'Accept-Encoding': 'gzip'},
  305. context: div,
  306. onload: parseVideoInfo
  307. });
  308. }
  309. }
  310.  
  311. function adjustNodesIfNeeded(e) {
  312. if (!fytedom[0])
  313. return;
  314. if (adjustNodesIfNeeded.scheduled)
  315. clearTimeout(adjustNodesIfNeeded.scheduled);
  316. adjustNodesIfNeeded.scheduled = setTimeout(function() {
  317. adjustNodes(e);
  318. adjustNodesIfNeeded.scheduled = 0;
  319. }, 16);
  320. }
  321.  
  322. function adjustNodes(e, clickedContainer) {
  323. var force = !!clickedContainer;
  324. var nearest = force ? clickedContainer : null;
  325.  
  326. var vids = $$('.instant-youtube-container:not([pinned]):not([stub])');
  327.  
  328. if (!nearest && e.type != 'DOMContentLoaded') {
  329. var minDistance = window.innerHeight*3/4 |0;
  330. var nearTargetY = window.innerHeight/2;
  331. vids.forEach(function(n) {
  332. var bounds = n.getBoundingClientRect();
  333. var distance = Math.abs((bounds.bottom + bounds.top)/2 - nearTargetY);
  334. if (distance < minDistance) {
  335. minDistance = distance;
  336. nearest = n;
  337. }
  338. });
  339. }
  340.  
  341. if (nearest) {
  342. var bounds = nearest.getBoundingClientRect();
  343. var nearestCenterYpct = (bounds.top + bounds.bottom)/2 / window.innerHeight;
  344. }
  345.  
  346. var resized = false;
  347.  
  348. vids.forEach(function(n) {
  349. var size = calcContainerSize(n);
  350. var w = size.w, h = size.h;
  351.  
  352. // prevent parent clipping
  353. for (var e=n.parentElement, style; e; e=e.parentElement)
  354. if (e.style.overflow != 'visible' && (style=getComputedStyle(e)))
  355. if ((style.overflow+style.overflowX+style.overflowY).match(/hidden|scroll/))
  356. if (n.offsetTop < e.clientHeight / 2 && n.offsetTop + n.clientHeight > e.clientHeight)
  357. e.style.cssText = e.style.cssText.replace(/\boverflow(-[xy])?:[^;]+/g, '') +
  358. important('overflow:visible;overflow-x:visible;overflow-y:visible;');
  359.  
  360. if (force && Math.abs(w - parseFloat(n.style.maxWidth)) <= 2)
  361. return;
  362.  
  363. if (n.style.maxWidth != w + 'px') n.style.maxWidth = w + 'px';
  364. if (n.style.height != h + 'px') n.style.height = h + 'px';
  365. if (parseFloat(n.style.minWidth) > w) n.style.minWidth = n.style.maxWidth;
  366. if (parseFloat(n.style.minHeight) > h) n.style.minHeight = n.style.height;
  367.  
  368. fixThumbnailAR(n);
  369. resized = true;
  370. });
  371.  
  372. if (resized && nearest)
  373. setTimeout(function() {
  374. var bounds = nearest.getBoundingClientRect();
  375. var h = bounds.bottom - bounds.top;
  376. var projectedCenterY = nearestCenterYpct * window.innerHeight;
  377. var projectedTop = projectedCenterY - h/2;
  378. var safeTop = Math.min(Math.max(0, projectedTop), window.innerHeight - h);
  379. window.scrollBy(0, bounds.top - safeTop);
  380. }, 16);
  381. }
  382.  
  383. function calcContainerSize(div, origNode) {
  384. origNode = origNode || div;
  385. var w, h;
  386. var np = origNode.parentElement;
  387. var style = getComputedStyle(np);
  388. var parentWidth = parseFloat(style.width) - floatPadding(np, style, 'Left') - floatPadding(np, style, 'Right');
  389. switch (resizeMode) {
  390. case 'Original':
  391. if (div.FYTE.originalWidth == 320 && div.FYTE.originalHeight == 200) {
  392. w = parentWidth;
  393. h = parentWidth / 16 * 9;
  394. } else {
  395. w = div.FYTE.originalWidth;
  396. h = div.FYTE.originalHeight;
  397. }
  398. break;
  399. case 'Custom':
  400. w = resizeWidth;
  401. h = resizeHeight;
  402. break;
  403. case '1080p':
  404. case '720p':
  405. case '480p':
  406. case '360p':
  407. h = parseInt(resizeMode);
  408. w = h / 9 * 16;
  409. break;
  410. default: // fit-to-width mode
  411. var n = origNode;
  412. do {
  413. n = n.parentElement;
  414. // find parent node with nonzero width (i.e. independent of our video element)
  415. } while (n && !(w = n.clientWidth));
  416. if (w)
  417. h = w / 16 * 9;
  418. else {
  419. w = origNode.clientWidth;
  420. h = origNode.clientHeight;
  421. }
  422. }
  423. if (parentWidth > 0 && parentWidth < w) {
  424. h = parentWidth / w * h;
  425. w = parentWidth;
  426. }
  427. if (resizeMode == 'Fit to width' && h < div.FYTE.originalHeight*0.9)
  428. h = Math.min(div.FYTE.originalHeight, w / div.FYTE.originalWidth * div.FYTE.originalHeight);
  429.  
  430. return {w: window.chrome ? w : Math.round(w), h:h};
  431. }
  432.  
  433. function parseVideoInfo(response) {
  434. var div = response.context;
  435. var txt = response.responseText;
  436. var info = tryCatch(function() { return JSON.parse(txt.replace(/(\w+)=?(.*?)(&|$)/g, '"$1":"$2",').replace(/^(.+?),?$/, '{$1}')) }) || {};
  437. var cache = div.FYTE.cache;
  438. var shouldUpdateCache = false;
  439. var videoSources = [];
  440.  
  441. // parse width & height to adjust the thumbnail
  442. var m = decodeURIComponent(info.adaptive_fmts || '').match(/size=(\d+)x(\d+)\b/) ||
  443. decodeURIComponent(txt).match(/\/(\d+)x(\d+)\//);
  444.  
  445. if (m && (cache.videoWidth != (m[1]|0) || cache.videoHeight != (m[2]|0))) {
  446. fixThumbnailAR(div, m[1]|0, m[2]|0);
  447. cache.videoWidth = m[1]|0;
  448. cache.videoHeight = m[2]|0;
  449. shouldUpdateCache = true;
  450. }
  451.  
  452. // parse video sources
  453. if (info.url_encoded_fmt_stream_map && info.fmt_list) {
  454. var streams = {};
  455. decodeURIComponent(info.url_encoded_fmt_stream_map).split(',').forEach(function(stream) {
  456. var params = {};
  457. stream.split('&').forEach(function(kv) {
  458. params[kv.split('=')[0]] = decodeURIComponent(kv.split('=')[1]);
  459. });
  460. streams[params.itag] = params;
  461. });
  462. decodeURIComponent(info.fmt_list).split(',').forEach(function(fmt) {
  463. var itag = fmt.split('/')[0];
  464. var dimensions = fmt.split('/')[1];
  465. var stream = streams[itag];
  466. if (stream) {
  467. videoSources.push({
  468. src: stream.url + (stream.s ? '&signature=' + stream.s : ''),
  469. title: stream.quality + ', ' + dimensions + ', ' + stream.type
  470. });
  471. }
  472. });
  473. } else {
  474. var rx = /url=([^=]+?mime%3Dvideo%252F(?:mp4|webm)[^=]+?)(?:,quality|,itag|.u0026)/g;
  475. var text = decodeURIComponent(txt).split('url_encoded_fmt_stream_map')[1];
  476. while (m = rx.exec(text)) {
  477. videoSources.push({
  478. src: decodeURIComponent(decodeURIComponent(m[1]))
  479. });
  480. }
  481. }
  482.  
  483. var duration = div.FYTE.duration = info.length_seconds|0 || '';
  484. if (duration) {
  485. var d = new Date(null);
  486. d.setSeconds(duration);
  487. duration = d.toISOString().replace(/^.+?T[0:]{0,4}(.+?)\..+$/, '$1');
  488. if (cache.duration != duration) {
  489. cache.duration = duration;
  490. shouldUpdateCache = true;
  491. }
  492. duration = '<span>' + duration + '</span>';
  493. }
  494. var title = decodeURIComponent(info.title || info.reason || '').replace(/\+/g, ' ');
  495. if (title) {
  496. $(div, '.instant-youtube-title').innerHTML = (title ? '<strong>' + title + '</strong>' : '') + duration;
  497. if (cache.title != title) {
  498. cache.title = title;
  499. shouldUpdateCache = true;
  500. }
  501. }
  502. if (pinnable != 'off' && info.title)
  503. makeDraggable(div);
  504.  
  505. if (info.reason) {
  506. div.setAttribute('disabled', '');
  507. if (cache.reason != info.reason) {
  508. cache.reason = info.reason;
  509. shouldUpdateCache = true;
  510. }
  511. }
  512.  
  513. if (videoSources.length)
  514. div.FYTE.videoSources = videoSources;
  515.  
  516. if (info.storyboard_spec && div.FYTE.state != 'scheduled play') {
  517. m = decodeURIComponent(decodeURIComponent(info.storyboard_spec)).split('|');
  518. div.FYTE.storyboard = JSON.parse(m[m.length-1].replace(/^(\d+)#(\d+)#(\d+)#(\d+)#(\d+)#.+$/, '{"w":$1, "h":$2, "len":$3, "rows":$4, "cols":$5}'));
  519. if (div.FYTE.storyboard.w * div.FYTE.storyboard.h > 2000) {
  520. div.FYTE.storyboard.url = m[0].replace('$L/$N.jpg', (m.length-2) + '/M0.jpg?sigh=' + m[m.length-1].replace(/^.+?#([^#]+)$/, '$1'));
  521. $(div, '.instant-youtube-options-button').insertAdjacentHTML('beforebegin',
  522. '<div class="instant-youtube-storyboard"' + (showStoryboard ? '' : ' disabled') + '>' +
  523. important('<div style="width:' + (div.FYTE.storyboard.w-1) + 'px; height:' + div.FYTE.storyboard.h + 'px;') +
  524. '">&nbsp;</div>' +
  525. '</div>');
  526. if (showStoryboard)
  527. updateHoverHandler(div);
  528. }
  529. }
  530.  
  531. injectStylesIfNeeded();
  532.  
  533. if (div.FYTE.state == 'scheduled play')
  534. setTimeout(function() { startPlayingDirectly(div) }, 0);
  535.  
  536. div.FYTE.state = '';
  537.  
  538. var cover = decodeURIComponent(info.iurlmaxres || info.iurlhq || info.iurl || '').match(/[^\/]+$/);
  539. if (cover && cache.cover != cover[0]) {
  540. cache.cover = cover[0];
  541. shouldUpdateCache = true;
  542. }
  543. if (shouldUpdateCache)
  544. GM_setValue('cache-' + info.video_id, JSON.stringify(cache));
  545. }
  546.  
  547. function fixThumbnailAR(div, w, h) {
  548. var img = $(div, 'img');
  549. if (!img)
  550. return;
  551. var thw = img.naturalWidth, thh = img.naturalHeight;
  552. if (w && h) { // means thumbnail is still loading
  553. div.FYTE.cache.videoWidth = w;
  554. div.FYTE.cache.videoHeight = h;
  555. } else {
  556. w = div.FYTE.cache.videoWidth;
  557. h = div.FYTE.cache.videoHeight;
  558. if (!w || !h)
  559. return;
  560. }
  561. var divw = div.clientWidth, divh = div.clientHeight;
  562. // if both video and thumbnail are 4:3, fit the image to height
  563. //console.log(div, divw, divh, thw, thh, w, h, h/w*divw / divh - 1, thh/thw*divw / divh - 1);
  564. if (Math.abs(h/w*divw / divh - 1) > 0.05 && Math.abs(thh/thw*divw / divh - 1) > 0.05) {
  565. img.style.maxHeight = img.clientHeight + 'px';
  566. if (!div.FYTE.cache.videoWidth) // skip animation if thumbnail is already loaded
  567. img.style.transition = 'height 1s ease, margin-top 1s ease';
  568. setTimeout(function() {
  569. img.style.maxHeight = 'none';
  570. img.style.cssText += important(h/w >= divh/divw ? 'width:auto; height:100%;' : 'width:100%; height:auto;');
  571. setTimeout(function() {
  572. img.style.transition = '';
  573. }, 1000);
  574. }, 0);
  575. }
  576. }
  577.  
  578. function updateHoverHandler(div) {
  579. var sb = $(div, '.instant-youtube-storyboard');
  580. if (!showStoryboard) {
  581. if (!sb.getAttribute('disabled'))
  582. sb.setAttribute('disabled', '');
  583. return;
  584. }
  585. if (sb.hasAttribute('disabled'))
  586. sb.removeAttribute('disabled');
  587.  
  588. sb.addEventListener('click', storyboardClickHandler);
  589.  
  590. var oldIndex = null;
  591. var style = sb.firstElementChild.style;
  592. sb.addEventListener('mousemove', storyboardHoverHandler);
  593. sb.addEventListener('mouseout', storyboardHoverHandler);
  594.  
  595. div.addEventListener('mouseover', storyboardPreloader);
  596. div.addEventListener('mouseout', storyboardPreloader);
  597.  
  598. var spinner = document.createElement('span');
  599. spinner.className = 'instant-youtube-loading-spinner';
  600.  
  601. function storyboardClickHandler(e) {
  602. sb.removeEventListener('click', storyboardClickHandler);
  603. var offsetX = e.offsetX || e.clientX - this.getBoundingClientRect().left;
  604. div.FYTE.startAt = offsetX / this.clientWidth * div.FYTE.duration |0;
  605. div.FYTE.srcEmbedFixed = setUrlParams(div.FYTE.srcEmbedFixed, {start: div.FYTE.startAt});
  606. startPlaying(div, {alternateMode: e.shiftKey});
  607. }
  608.  
  609. function storyboardPreloader(e) {
  610. if (e.type == 'mouseout') {
  611. imageLoader.onload = null; imageLoader.src = '';
  612. spinner.remove();
  613. return;
  614. }
  615. if (!div.FYTE.storyboard || div.FYTE.storyboard.preloaded)
  616. return;
  617. var lastpart = (div.FYTE.storyboard.len-1)/(div.FYTE.storyboard.rows * div.FYTE.storyboard.cols) |0;
  618. if (lastpart <= 0)
  619. return;
  620. var part = 0;
  621. imageLoader.src = setStoryboardUrl(part++);
  622. imageLoader.onload = function() {
  623. if (part > lastpart) {
  624. div.FYTE.storyboard.preloaded = true;
  625. div.removeEventListener('mouseover', storyboardPreloader);
  626. div.removeEventListener('mouseout', storyboardPreloader);
  627. imageLoader.onload = null;
  628. imageLoader.src = '';
  629. spinner.remove();
  630. return;
  631. }
  632. imageLoader.src = setStoryboardUrl(part++);
  633. };
  634. }
  635.  
  636. function setStoryboardUrl(part) {
  637. return div.FYTE.storyboard.url.replace(/M\d+\.jpg\?/, 'M' + part + '.jpg?');
  638. }
  639.  
  640. function storyboardHoverHandler(e) {
  641. if (!showStoryboard || !div.FYTE.storyboard)
  642. return;
  643. if (e.type == 'mouseout')
  644. return imageLoader2.onload && imageLoader2.onload();
  645. var w = div.FYTE.storyboard.w;
  646. var h = div.FYTE.storyboard.h;
  647. var cols = div.FYTE.storyboard.cols;
  648. var rows = div.FYTE.storyboard.rows;
  649. var len = div.FYTE.storyboard.len;
  650. var partlen = rows * cols;
  651.  
  652. var offsetX = e.offsetX || e.clientX - this.getBoundingClientRect().left;
  653. var left = Math.min(this.clientWidth - w, Math.max(0, offsetX - w)) |0;
  654. if (!style.left || parseInt(style.left) != left) {
  655. style.left = left + 'px';
  656. if (spinner.parentElement)
  657. spinner.style.cssText = important('left:' + (left + w/2 - 10) + 'px; right:auto;');
  658. }
  659.  
  660. var index = Math.min(offsetX / this.clientWidth * (len+1) |0, len - 1);
  661. if (index == oldIndex)
  662. return;
  663.  
  664. var part = index/partlen|0;
  665. if (!oldIndex || part != (oldIndex/partlen|0)) {
  666. style.cssText = style.cssText.replace(/$|background-image[^;]+;/,
  667. 'background-image: url(' + setStoryboardUrl(part) + ')!important;');
  668. if (!div.FYTE.storyboard.preloaded) {
  669. if (spinner.timer)
  670. clearTimeout(spinner.timer);
  671. spinner.timer = setTimeout(function() {
  672. spinner.timer = 0;
  673. if (!imageLoader2.src)
  674. return;
  675. this.appendChild(spinner);
  676. spinner.style.cssText = important('left:' + (left + w/2 - 10) + 'px; right:auto;');
  677. }.bind(this), 50);
  678. imageLoader2.onload = function() {
  679. clearTimeout(spinner.timer);
  680. spinner.remove();
  681. spinner.timer = 0;
  682. imageLoader2.onload = null;
  683. imageLoader2.src = '';
  684. };
  685. imageLoader2.src = setStoryboardUrl(part);
  686. }
  687. }
  688.  
  689. oldIndex = index;
  690. index = index % partlen;
  691. style.backgroundPosition = '-' + (index % cols) * w + 'px -' + (index / cols |0) * h + 'px';
  692. }
  693. }
  694.  
  695. function clickHandler(e) {
  696. if (e.target.closest('a')
  697. || e.type == 'mousedown' && e.button != 1
  698. || e.type == 'click' && e.target.matches('.instant-youtube-options, .instant-youtube-options *'))
  699. return;
  700. if (e.type == 'click' && e.target.matches('.instant-youtube-options-button')) {
  701. showOptions(e);
  702. e.preventDefault();
  703. e.stopPropagation();
  704. return;
  705. }
  706.  
  707. e.preventDefault();
  708. e.stopPropagation();
  709. e.stopImmediatePropagation();
  710.  
  711. startPlaying(e.target.closest('.instant-youtube-container'), {
  712. alternateMode: e.shiftKey || e.target.matches('.instant-youtube-alternative'),
  713. fullscreen: e.button == 1,
  714. });
  715. }
  716.  
  717. function startPlaying(div, params) {
  718. div.removeEventListener('click', clickHandler);
  719. div.removeEventListener('mousedown', clickHandler);
  720.  
  721. $$remove(div, '.instant-youtube-alternative, .instant-youtube-storyboard, .instant-youtube-options-button');
  722. $(div, 'svg').outerHTML = '<span class="instant-youtube-loading-spinner"></span>';
  723.  
  724. if (pinnable != 'off') {
  725. makePinnable(div);
  726. if (params && params.pin)
  727. $(div, '[pin="' + params.pin + '"]').click();
  728. }
  729.  
  730. if (window != window.top)
  731. window.parent.postMessage('iframe-allowfs', '*');
  732.  
  733. if ((!!playDirectly + !!(params && params.alternateMode) == 1)
  734. && (div.FYTE.videoSources || div.FYTE.state == 'querying')) {
  735. if (div.FYTE.videoSources)
  736. startPlayingDirectly(div, params);
  737. else {
  738. // playback will start in parseVideoInfo
  739. div.FYTE.state = 'scheduled play';
  740. // fallback to iframe in 5s
  741. setTimeout(function() {
  742. if (div.FYTE.state) {
  743. div.FYTE.state = '';
  744. switchToIFrame.call(div, params);
  745. }
  746. }, 5000);
  747. }
  748. }
  749. else
  750. switchToIFrame.call(div, params);
  751. }
  752.  
  753. function startPlayingDirectly(div, params) {
  754. var video = document.createElement('video');
  755. video.controls = true;
  756. video.autoplay = true;
  757. video.style.cssText = important('position:absolute; left:0; top:0; right:0; bottom:0; padding:0; margin:auto; opacity:0; width:100%; height:100%;');
  758. video.className = 'instant-youtube-embed';
  759. video.volume = GM_getValue('volume', 0.5);
  760.  
  761. div.FYTE.videoSources.forEach(function(src) {
  762. var srcdom = video.appendChild(document.createElement('source'));
  763. Object.keys(src).forEach(function(k) { srcdom[k] = src[k] });
  764. srcdom.onerror = switchToIFrame.bind(div, params);
  765. });
  766.  
  767. overrideCSS($(div, 'img'), {transition: 'opacity 1s', opacity: '0'});
  768.  
  769. if (params && params.fullscreen) {
  770. div.firstElementChild.appendChild(video);
  771. div.setAttribute('playing', '');
  772. video.style.opacity = 1;
  773. goFullscreen(video);
  774. }
  775.  
  776. if (window.chrome) {
  777. video.addEventListener('click', function(e) {
  778. this.paused ? this.play() : this.pause();
  779. });
  780. }
  781.  
  782. video.interval = (function() {
  783. return setInterval(function() {
  784. if (video.volume != GM_getValue('volume', 0.5))
  785. GM_setValue('volume', video.volume);
  786. }, 1000);
  787. })();
  788.  
  789. var title = $(div, '.instant-youtube-title');
  790. if (title) {
  791. video.onpause = function() { title.removeAttribute('hidden') };
  792. video.onplay = function() { title.setAttribute('hidden', true) };
  793. }
  794.  
  795. video.onloadedmetadata = div.FYTE.startAt && function(e) {
  796. video.currentTime = div.FYTE.startAt;
  797. };
  798. video.onloadeddata = function(e) {
  799. pauseOtherVideos(video);
  800. if (params && params.fullscreen)
  801. return;
  802. div.setAttribute('playing', '');
  803. div.firstElementChild.appendChild(video);
  804. video.style.opacity = 1;
  805. };
  806. }
  807.  
  808. function switchToIFrame(params, e) {
  809. var div = this;
  810. var wrapper = div.firstElementChild;
  811. var fullscreen = params && params.fullscreen && !e;
  812. if (e instanceof Event) {
  813. console.log('[FYTE] Direct linking canceled on %s, switching to IFRAME player', div.FYTE.srcEmbed);
  814. var video = e.target ? e.target.closest('video') : e.path && e.path[e.path.length-1];
  815. while (video.lastElementChild)
  816. video.lastElementChild.remove();
  817. goFullscreen(video, false);
  818. video.remove();
  819. }
  820.  
  821. ($(div, '[pin]') || wrapper).insertAdjacentHTML(pinnable != 'off' ? 'beforebegin' : 'beforeend',
  822. '<iframe class="instant-youtube-embed" allowtransparency="true" src="' +
  823. setUrlParams(div.FYTE.srcEmbedFixed, {
  824. html5: 1,
  825. autoplay: 1,
  826. autohide: 2,
  827. border: 0,
  828. controls: 1,
  829. fs: 1,
  830. showinfo: 1,
  831. ssl: 1,
  832. theme: 'dark',
  833. enablejsapi: 1,
  834. FYTEfullscreen: fullscreen|0,
  835. }) + '" style="' + important('position:absolute; left:0; top:0; right:0; padding:0; margin:auto; opacity:0;') +
  836. '" frameborder="0" allowfullscreen width="100%" height="100%"></iframe>');
  837.  
  838. div.setAttribute('iframe', '');
  839. div.setAttribute('playing', '');
  840.  
  841. var iframe = $(div, 'iframe');
  842. if (fullscreen) {
  843. goFullscreen(iframe);
  844. iframe.style.opacity = 1;
  845. }
  846.  
  847. iframe.onload = function(e) {
  848. window.addEventListener('message', YTlistener);
  849. iframe.contentWindow.postMessage('{"event":"listening"}', '*');
  850. };
  851. setTimeout(function() {
  852. iframe.style.opacity = 1;
  853. window.removeEventListener('message', YTlistener);
  854. }, 5000);
  855.  
  856. function YTlistener(e) {
  857. if (e.source != iframe.contentWindow || !e.data)
  858. return;
  859. var data = JSON.parse(e.data);
  860. if (!data.info || data.info.playerState != 1)
  861. return;
  862. window.removeEventListener('message', YTlistener);
  863. pauseOtherVideos(iframe);
  864. iframe.style.opacity = 1;
  865. $$remove(div, 'span, a');
  866. $(div, 'img').style.display = 'none';
  867. }
  868. }
  869.  
  870. function setUrlParams(url, params) {
  871. var names = Object.keys(params);
  872. url = url.replace(new RegExp('[?&](' + names.join('|') + ')(=[^?&]*)?', 'gi'), '');
  873. return url +
  874. (url.indexOf('?') > 0 ? '&' : '?') +
  875. names.map(function(n) { return n + '=' + params[n] }).join('&');
  876. }
  877.  
  878. function pauseOtherVideos(activePlayer) {
  879. $$(activePlayer.ownerDocument, '.instant-youtube-embed').forEach(function(v) {
  880. if (v == activePlayer)
  881. return;
  882. switch (v.localName) {
  883. case 'video':
  884. if (!v.paused)
  885. v.pause();
  886. break;
  887. case 'iframe':
  888. try { v.contentWindow.postMessage('{"event":"command", "func":"pauseVideo", "args":""}', '*') } catch(e) {}
  889. break;
  890. }
  891. });
  892. }
  893.  
  894. function goFullscreen(el, enable) {
  895. if (enable !== false)
  896. el.webkitRequestFullScreen && el.webkitRequestFullScreen()
  897. || el.mozRequestFullScreen && el.mozRequestFullScreen()
  898. || el.requestFullScreen && el.requestFullScreen();
  899. else
  900. document.webkitCancelFullScreen && document.webkitCancelFullScreen()
  901. || document.mozCancelFullScreen && document.mozCancelFullScreen()
  902. || document.cancelFullScreen && document.cancelFullScreen();
  903. }
  904.  
  905. function makePinnable(div) {
  906. div.firstElementChild.insertAdjacentHTML('beforeend',
  907. '<div pin="top-left"></div><div pin="top-right"></div><div pin="bottom-right"></div><div pin="bottom-left"></div>');
  908. $$(div, '[pin]').forEach(function(pin) {
  909. if (pinnable == 'hide')
  910. pin.setAttribute('transparent', '');
  911. pin.onclick = function(e) {
  912. var pinIt = !div.hasAttribute('pinned') || !pin.hasAttribute('active');
  913. var corner = pin.getAttribute('pin');
  914. var video = $(div, 'video');
  915. if (pinIt) {
  916. $$(div, '[pin][active]').forEach(function(p) { p.removeAttribute('active') });
  917. pin.setAttribute('active', '');
  918. if (!div.FYTE.unpinnedStyle) {
  919. div.FYTE.unpinnedStyle = div.style.cssText;
  920. var stub = div.cloneNode();
  921. var img = $(div, 'img').cloneNode();
  922. img.style.opacity = 1;
  923. img.style.display = 'block';
  924. img.title = '';
  925. stub.appendChild(img);
  926. stub.onclick = function(e) { $(div, '[pin][active]').onclick(e) };
  927. stub.style.cssText += 'opacity:0.3!important;';
  928. stub.setAttribute('stub', '');
  929. div.FYTE.stub = stub;
  930. div.parentNode.insertBefore(stub, div);
  931. }
  932. div.style.cssText = important(
  933. 'position: fixed;' +
  934. 'contain: inherit;' +
  935. 'width: 400px;' +
  936. 'z-index: 999999999;' +
  937. 'height:' + (400 / div.FYTE.cache.videoWidth * div.FYTE.cache.videoHeight) + 'px;' +
  938. 'top:' + (corner.indexOf('top') >= 0 ? '0' : 'auto') + ';' +
  939. 'bottom:' + (corner.indexOf('bottom') >= 0 ? '0' : 'auto') + ';' +
  940. 'left:' + (corner.indexOf('left') >= 0 ? '0' : 'auto') + ';' +
  941. 'right:' + (corner.indexOf('right') >= 0 ? '0' : 'auto') + ';'
  942. );
  943. adjustPinnedOffset(div, div, corner);
  944. div.setAttribute('pinned', '');
  945. if (video && document.body)
  946. document.body.appendChild(div);
  947. }
  948. else { // unpin
  949. pin.removeAttribute('active');
  950. div.removeAttribute('pinned');
  951. div.style.cssText = div.FYTE.unpinnedStyle;
  952. div.FYTE.unpinnedStyle = '';
  953. if (div.FYTE.stub) {
  954. if (video && document.body)
  955. div.FYTE.stub.parentNode.replaceChild(div, div.FYTE.stub);
  956. div.FYTE.stub.remove();
  957. div.FYTE.stub = null;
  958. }
  959. }
  960. if (video && video.paused)
  961. video.play();
  962. };
  963. });
  964. }
  965.  
  966. function makeDraggable(div) {
  967. div.draggable = true;
  968. div.addEventListener('dragstart', function(e) {
  969. var offsetY = e.offsetY || e.clientY - div.getBoundingClientRect().top;
  970. if (offsetY > div.clientHeight - 30)
  971. return e.preventDefault();
  972.  
  973. e.dataTransfer.setData('text/plain', '');
  974.  
  975. var dropZone = document.createElement('div');
  976. var dropZoneHeight = 400 / div.FYTE.cache.videoWidth * div.FYTE.cache.videoHeight;
  977. dropZone.className = 'instant-youtube-dragndrop-placeholder';
  978.  
  979. document.body.addEventListener('dragenter', dragHandler);
  980. document.body.addEventListener('dragover', dragHandler);
  981. document.body.addEventListener('dragend', dragHandler);
  982. document.body.addEventListener('drop', dragHandler);
  983. function dragHandler(e) {
  984. e.stopImmediatePropagation();
  985. e.stopPropagation();
  986. e.preventDefault();
  987. switch (e.type) {
  988. case 'dragover':
  989. var playing = div.hasAttribute('playing');
  990. var stub = e.target.closest('.instant-youtube-container[stub]') == div.FYTE.stub && div.FYTE.stub;
  991. var gizmo = playing && !stub
  992. ? {left:0, top:0, right:innerWidth, bottom:innerHeight}
  993. : (stub || div).getBoundingClientRect();
  994. var x = e.clientX, y = e.clientY;
  995. var cx = (gizmo.left + gizmo.right) / 2;
  996. var cy = (gizmo.top + gizmo.bottom) / 2;
  997. var stay = !!stub || y >= cy-200 && y <= cy+200 && x >= cx-200 && x <= cx+200;
  998. overrideCSS(dropZone, {
  999. top: y < cy || stay ? '0' : 'auto',
  1000. bottom: y > cy || stay ? '0' : 'auto',
  1001. left: x < cx || stay ? '0' : 'auto',
  1002. right: x > cx || stay ? '0' : 'auto',
  1003. width: playing && stay && stub ? stub.clientWidth+'px' : '400px',
  1004. height: playing && stay && stub ? stub.clientHeight+'px' : dropZoneHeight + 'px',
  1005. margin: playing && stay ? 'auto' : '0',
  1006. position: !playing && stay || stub ? 'absolute' : 'fixed',
  1007. 'background-color': stub ? 'rgba(0,0,255,0.5)' : stay ? 'rgba(255,255,0,0.4)' : 'rgba(0,255,0,0.2)',
  1008. });
  1009. adjustPinnedOffset(dropZone, div);
  1010. (stay && !playing || stub ? (stub || div) : document.body).appendChild(dropZone);
  1011. break;
  1012. case 'dragend':
  1013. case 'drop':
  1014. var corner = calcPinnedCorner(dropZone);
  1015. dropZone.remove();
  1016. dropZone = null;
  1017. document.body.removeEventListener('dragenter', dragHandler);
  1018. document.body.removeEventListener('dragover', dragHandler);
  1019. document.body.removeEventListener('dragend', dragHandler);
  1020. document.body.removeEventListener('drop', dragHandler);
  1021. if (e.type == 'dragend')
  1022. break;
  1023. if (div.hasAttribute('playing'))
  1024. (corner ? $(div, '[pin="' + corner + '"]') : div.FYTE.stub).click();
  1025. else
  1026. startPlaying(div, {pin: corner});
  1027. }
  1028. }
  1029. });
  1030. }
  1031.  
  1032. function adjustPinnedOffset(el, self, corner) {
  1033. var offset = 0;
  1034. $$('.instant-youtube-container[pinned] [pin="' + (corner || calcPinnedCorner(el)) + '"][active]').forEach(function(pin) {
  1035. var container = pin.closest('[pinned]');
  1036. if (container != el && container != self) {
  1037. var bounds = container.getBoundingClientRect();
  1038. offset = Math.max(offset, el.style.top == '0px' ? bounds.bottom : innerHeight - bounds.top);
  1039. }
  1040. });
  1041. if (offset)
  1042. el.style[el.style.top == '0px' ? 'top' : 'bottom'] = offset + 'px';
  1043. }
  1044.  
  1045. function calcPinnedCorner(el) {
  1046. var t = el.style.top != 'auto';
  1047. var b = el.style.bottom != 'auto';
  1048. var l = el.style.left != 'auto';
  1049. var r = el.style.right != 'auto';
  1050. return t && b && l && r ? '' : (t ? 'top' : 'bottom') + '-' + (l ? 'left' : 'right');
  1051. }
  1052.  
  1053. function showOptions(e) {
  1054. var optionsButton = e.target;
  1055. translateHTML(optionsButton, 'afterend', '\
  1056. <div class="instant-youtube-options">\
  1057. <label tl style="width: 100% !important;">Size:<br>\
  1058. <select data-action="size-mode" style="width:20ex!important">\
  1059. <option tl value="Original">Original\
  1060. <option tl value="Fit to width">Fit to width\
  1061. <option>360p\
  1062. <option>480p\
  1063. <option>720p\
  1064. <option>1080p\
  1065. <option tl value="Custom">Custom...\
  1066. </select>\
  1067. </label>\
  1068. <label data-action="size-custom" ' + (resizeMode != 'Custom' ? 'disabled' : '') + '>\
  1069. <input type="number" min="320" max="9999" tl-placeholder="width" data-action="width" step="1" value="' + (resizeWidth||'') + '">\
  1070. x\
  1071. <input type="number" min="240" max="9999" tl-placeholder="height" data-action="height" step="1" value="' + (resizeHeight||'') + '">\
  1072. </label>\
  1073. <label tl="content,title" title="msgStoryboardTooltip">\
  1074. <input data-action="storyboard" type="checkbox" ' + (showStoryboard ? 'checked' : '') + '>\
  1075. Storyboard thumbs\
  1076. </label>\
  1077. <label tl="content,title" title="msgDirectTooltip">\
  1078. <input data-action="direct" type="checkbox" ' + (playDirectly ? 'checked' : '') + '>\
  1079. Play directly\
  1080. </label>\
  1081. <label tl="content,title" title="Do not process customized videos with enablejsapi=1 parameter (requires page reload)">\
  1082. <input data-action="safe" type="checkbox" ' + (skipCustom ? 'checked' : '') + '>\
  1083. Safe\
  1084. </label>\
  1085. <label tl="content,title" title="msgPinningTooltip">Pinning:\
  1086. <select data-action="pinnable">\
  1087. <option tl value="on">On\
  1088. <option tl value="hide">On, hidden\
  1089. <option tl value="off">Off\
  1090. </select>\
  1091. </label>\
  1092. <span data-action="buttons">\
  1093. <button tl data-action="ok">OK</button>\
  1094. <button tl data-action="cancel">Cancel</button>\
  1095. </span>\
  1096. </div>\
  1097. ');
  1098. var options = optionsButton.nextElementSibling;
  1099.  
  1100. options.addEventListener('keydown', function(e) {
  1101. if (e.target.localName == 'input' &&
  1102. !e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey && e.key.match(/[.,]/))
  1103. return false;
  1104. });
  1105.  
  1106. $(options, '[data-action="size-mode"]').value = resizeMode;
  1107. $(options, '[data-action="size-mode"]').addEventListener('change', function() {
  1108. var v = this.value != 'Custom';
  1109. var e = $(options, '[data-action="size-custom"]');
  1110. e.children[0].disabled = e.children[1].disabled = v;
  1111. v ? e.setAttribute('disabled', '') : e.removeAttribute('disabled');
  1112. });
  1113.  
  1114. $(options, '[data-action="pinnable"]').value = pinnable;
  1115.  
  1116. $(options, '[data-action="buttons"]').addEventListener('click', function(e) {
  1117. if (e.target.dataset.action != 'ok') {
  1118. options.remove();
  1119. return;
  1120. }
  1121. var v, shouldAdjust;
  1122. if (resizeMode != (v = $(options, '[data-action="size-mode"]').value)) {
  1123. GM_setValue('resize', resizeMode = v);
  1124. shouldAdjust = true;
  1125. }
  1126. if (resizeMode == 'Custom') {
  1127. var w = $(options, '[data-action="width"]').value |0;
  1128. var h = $(options, '[data-action="height"]').value |0;
  1129. if (resizeWidth != w || resizeHeight != h) {
  1130. updateCustomSize(w, h);
  1131. GM_setValue('width', resizeWidth);
  1132. GM_setValue('height', resizeHeight);
  1133. shouldAdjust = true;
  1134. }
  1135. }
  1136. if (showStoryboard != (v = $(options, '[data-action="storyboard"]').checked)) {
  1137. GM_setValue('showStoryboard', showStoryboard = v);
  1138. $$('.instant-youtube-container').forEach(updateHoverHandler);
  1139. }
  1140. if (playDirectly != (v = $(options, '[data-action="direct"]').checked)) {
  1141. GM_setValue('playHTML5', playDirectly = v);
  1142. $$('.instant-youtube-container .instant-youtube-alternative').forEach(function(e) {
  1143. e.textContent = playDirectly ? 'Play with Youtube player' : 'Play directly (up to 720p)';
  1144. });
  1145. }
  1146. if (skipCustom != (v = $(options, '[data-action="safe"]').checked)) {
  1147. GM_setValue('skipCustom', skipCustom = v);
  1148. }
  1149. if (pinnable != (v = $(options, '[data-action="pinnable"]').value)) {
  1150. GM_setValue('pinnable', pinnable = v);
  1151. }
  1152.  
  1153. options.remove();
  1154.  
  1155. if (shouldAdjust)
  1156. adjustNodes(e, e.target.closest('.instant-youtube-container'));
  1157. });
  1158. }
  1159.  
  1160. function updateCustomSize(w, h) {
  1161. resizeWidth = Math.min(9999, Math.max(320, w|0 || resizeWidth|0));
  1162. resizeHeight = Math.min(9999, Math.max(240, h|0 || resizeHeight|0));
  1163. }
  1164.  
  1165. function important(cssText) {
  1166. return cssText.replace(/;/g, '!important;');
  1167. }
  1168.  
  1169. function tryCatch(func) {
  1170. try {
  1171. return func();
  1172. } catch(e) {
  1173. console.log(e);
  1174. }
  1175. }
  1176.  
  1177. function getFunctionComment(fn) {
  1178. return fn.toString().match(/\/\*([\s\S]*?)\*\/\s*\}$/)[1];
  1179. }
  1180.  
  1181. function $(selORnode, sel) {
  1182. return sel ? selORnode.querySelector(sel)
  1183. : document.querySelector(selORnode);
  1184. }
  1185.  
  1186. function $$(selORnode, sel) {
  1187. return Array.prototype.slice.call(
  1188. sel ? selORnode.querySelectorAll(sel)
  1189. : document.querySelectorAll(selORnode));
  1190. }
  1191.  
  1192. function $$remove(selORnode, sel) {
  1193. Array.prototype.forEach.call(
  1194. sel ? selORnode.querySelectorAll(sel)
  1195. : document.querySelectorAll(selORnode),
  1196. function(e) { e.remove() }
  1197. );
  1198. }
  1199.  
  1200. function overrideCSS(e, params) {
  1201. var names = Object.keys(params);
  1202. var style = e.style.cssText.replace(new RegExp('(^|\s|;)(' + names.join('|') + ')(:[^;]+)', 'gi'), '$1');
  1203. e.style.cssText = style.replace(/[^;]\s*$/, '$&;').replace(/^\s*;\s*/, '') +
  1204. names.map(function(n) { return n + ':' + params[n] + '!important' }).join(';') + ';';
  1205. }
  1206.  
  1207. // fix dumb Firefox bug
  1208. function floatPadding(node, style, dir) {
  1209. var padding = style['padding' + dir];
  1210. if (padding.indexOf('%') < 0)
  1211. return parseFloat(padding);
  1212. return parseFloat(padding) * (parseFloat(style.width) || node.clientWidth) / 100;
  1213. }
  1214.  
  1215. function translateHTML(baseElement, place, html) {
  1216. var tmp = document.createElement('div');
  1217. tmp.innerHTML = html;
  1218. $$(tmp, '[tl]').forEach(function(node) {
  1219. (node.getAttribute('tl') || 'content').split(',').forEach(function(what) {
  1220. var child, src, tl;
  1221. if (what == 'content') {
  1222. for (var i = node.childNodes.length-1, n; (i>=0) && (n=node.childNodes[i]); i--) {
  1223. if (n.nodeType == Node.TEXT_NODE && n.textContent.trim()) {
  1224. child = n;
  1225. break;
  1226. }
  1227. }
  1228. } else
  1229. child = node.getAttributeNode(what);
  1230. if (!child)
  1231. return;
  1232. src = child.textContent;
  1233. srcTrimmed = src.trim();
  1234. tl = src.replace(srcTrimmed, _(srcTrimmed));
  1235. if (src != tl)
  1236. child.textContent = tl;
  1237. });
  1238. });
  1239. baseElement.insertAdjacentHTML(place, tmp.innerHTML);
  1240. }
  1241.  
  1242. function initTL(src) {
  1243. var tlSource = {
  1244. 'watch on Youtube': {
  1245. 'ru': 'открыть на Youtube',
  1246. },
  1247. 'Play with Youtube player': {
  1248. 'ru': 'Включить плеер Youtube',
  1249. },
  1250. 'Play directly (up to 720p)': {
  1251. 'ru': 'Включить напрямую (макс. 720p)',
  1252. },
  1253. 'Shift-click to use alternative player': {
  1254. 'ru': 'Shift-клик для смены типа плеера',
  1255. },
  1256. 'Options': {
  1257. 'ru': 'Опции',
  1258. },
  1259. 'Size:': {
  1260. 'ru': 'Размер:',
  1261. },
  1262. 'Original': {
  1263. 'ru': 'Исходный',
  1264. },
  1265. 'Fit to width': {
  1266. 'ru': 'На всю ширину',
  1267. },
  1268. 'Custom...': {
  1269. 'ru': 'Настроить...',
  1270. },
  1271. 'width': {
  1272. 'ru': 'ширина',
  1273. },
  1274. 'height': {
  1275. 'ru': 'высота',
  1276. },
  1277. 'Storyboard thumbs': {
  1278. 'ru': 'Раскадровка',
  1279. },
  1280. 'msgStoryboardTooltip': {
  1281. 'en': 'Show storyboard preview on mouse hover at the bottom',
  1282. 'ru': 'Показывать миникадры при наведении мыши на низ кавер-картинки',
  1283. },
  1284. 'Play directly': {
  1285. 'ru': 'Плеер браузера',
  1286. },
  1287. 'msgDirectTooltip': {
  1288. 'en': 'Shift-clicking thumbnails will use alternative player',
  1289. 'ru': 'Удерживайте клавишу Shift при щелчке на картинке для альтернативного плеера',
  1290. },
  1291. 'Safe': {
  1292. 'ru': 'Консервативный режим',
  1293. },
  1294. 'Pinning': {
  1295. 'ru': 'Закрепление',
  1296. },
  1297. 'msgPinningTooltip': {
  1298. 'en': 'Enable corner pinning controls when a video is playing. \nTo restore the video click the active corner pin or the original video placeholder.',
  1299. 'ru': 'Включить шпильки по углам для закрепления видео во время просмотра. \nДля отмены можно нажать еще раз на активированный уголЪ или на заглушку, где исходно было видео',
  1300. },
  1301. 'On': {
  1302. 'ru': 'Да',
  1303. },
  1304. 'On, hide': {
  1305. 'ru': 'Да, невидимые',
  1306. },
  1307. 'Off': {
  1308. 'ru': 'Нет',
  1309. },
  1310. 'msgSafe': {
  1311. 'en': 'Do not process customized videos with enablejsapi=1 parameter (requires page reload)',
  1312. 'ru': 'Не обрабатывать нестандартные видео с параметром enablejsapi=1 (подействует после обновления страницы)',
  1313. },
  1314. 'OK': {
  1315. 'ru': 'ОК',
  1316. },
  1317. 'Cancel': {
  1318. 'ru': 'Оменить',
  1319. },
  1320. };
  1321. var browserLang = navigator.language || navigator.languages && navigator.languages[0] || '';
  1322. var browserLangMajor = browserLang.replace(/-.+/, '');
  1323. var tl = {};
  1324. Object.keys(tlSource).forEach(function(k) {
  1325. var langs = tlSource[k];
  1326. var text = langs[browserLang] || langs[browserLangMajor];
  1327. if (text)
  1328. tl[k] = text;
  1329. });
  1330. return function(src) { return tl[src] || src };
  1331. }
  1332.  
  1333. function injectStylesIfNeeded(force) {
  1334. if (!fytedom[0] && !force)
  1335. return;
  1336. var styledom = $('style#instant-youtube-styles');
  1337. if (styledom) {
  1338. // move our rules to the end of HEAD to increase CSS specificity
  1339. if (styledom.nextElementSibling && document.head)
  1340. document.head.insertBefore(styledom, null);
  1341. return;
  1342. }
  1343. styledom = (document.head || document.documentElement).appendChild(document.createElement('style'));
  1344. styledom.id = 'instant-youtube-styles';
  1345. styledom.textContent = important(getFunctionComment(function() { /*
  1346. .instant-youtube-container {
  1347. contain: strict;
  1348. position: relative;
  1349. overflow: hidden;
  1350. cursor: pointer;
  1351. padding: 0;
  1352. margin: auto;
  1353. font: normal 14px/1.0 sans-serif, Arial, Helvetica, Verdana;
  1354. text-align: center;
  1355. background: black;
  1356. }
  1357. .instant-youtube-container[disabled] {
  1358. background: #888;
  1359. }
  1360. .instant-youtube-container[disabled] .instant-youtube-storyboard {
  1361. display: none;
  1362. }
  1363. .instant-youtube-container[pinned] {
  1364. box-shadow: 0 0 30px black;
  1365. }
  1366. .instant-youtube-container[playing] {
  1367. contain: inherit;
  1368. }
  1369. .instant-youtube-wrapper {
  1370. width: 100%;
  1371. height: 100%;
  1372. }
  1373. .instant-youtube-play-button {
  1374. display: block;
  1375. position: absolute;
  1376. width: 85px;
  1377. height: 60px;
  1378. left: 0;
  1379. right: 0;
  1380. top: 0;
  1381. bottom: 0;
  1382. margin: auto;
  1383. }
  1384. .instant-youtube-loading-spinner {
  1385. display: block;
  1386. position: absolute;
  1387. width: 20px;
  1388. height: 20px;
  1389. left: 0;
  1390. right: 0;
  1391. top: 0;
  1392. bottom: 0;
  1393. padding: 0;
  1394. margin: auto;
  1395. pointer-events: none;
  1396. background: url("data:image/gif;base64,R0lGODlhFAAUAJEDAMzMzLOzs39/f////yH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgADACwAAAAAFAAUAAACPJyPqcuNItyCUJoQBo0ANIxpXOctYHaQpYkiHfM2cUrCNT0nqr4uudsz/IC5na/2Mh4Hu+HR6YBaplRDAQAh+QQFCgADACwEAAIADAAGAAACFpwdcYupC8BwSogR46xWZHl0l8ZYQwEAIfkEBQoAAwAsCAACAAoACgAAAhccMKl2uHxGCCvO+eTNmishcCCYjWEZFgAh+QQFCgADACwMAAQABgAMAAACFxwweaebhl4K4VE6r61DiOd5SfiN5VAAACH5BAUKAAMALAgACAAKAAoAAAIYnD8AeKqcHIwwhGntEWLkO3CcB4biNEIFACH5BAUKAAMALAQADAAMAAYAAAIWnDSpAHa4GHgohCHbGdbipnBdSHphAQAh+QQFCgADACwCAAgACgAKAAACF5w0qXa4fF6KUoVQ75UaA7Bs3yeNYAkWACH5BAUKAAMALAIABAAGAAwAAAIXnCU2iMfaRghqTmMp1moAoHyfIYIkWAAAOw==");
  1397. }
  1398. .instant-youtube-container:hover .ytp-large-play-button-svg {
  1399. fill: #CC181E;
  1400. }
  1401. .instant-youtube-alternative {
  1402. display: block;
  1403. position: absolute;
  1404. width: 20em;
  1405. height: 20px;
  1406. top: 50%;
  1407. left: 0;
  1408. right: 0;
  1409. margin: 60px auto;
  1410. padding: 0;
  1411. border: none;
  1412. text-align: center;
  1413. text-decoration: none;
  1414. text-shadow: 1px 1px 3px black;
  1415. font-weight: bold;
  1416. color: white;
  1417. z-index: 8;
  1418. font-weight: normal;
  1419. font-size: 12px;
  1420. }
  1421. .instant-youtube-alternative:hover {
  1422. text-decoration: underline;
  1423. color: white;
  1424. background: transparent;
  1425. }
  1426. .instant-youtube-embed {
  1427. z-index: 10;
  1428. background: transparent;
  1429. }
  1430. .instant-youtube-title {
  1431. z-index: 20;
  1432. display: block;
  1433. position: absolute;
  1434. width: auto;
  1435. top: 0;
  1436. left: 0;
  1437. right: 0;
  1438. margin: 0;
  1439. padding: 7px;
  1440. border: none;
  1441. text-shadow: 1px 1px 2px black;
  1442. text-align: center;
  1443. text-decoration: none;
  1444. color: white;
  1445. background-color: rgba(0, 0, 0, 0.5);
  1446. }
  1447. .instant-youtube-title strong {
  1448. font: bold 14px/1.0 sans-serif, Arial, Helvetica, Verdana;
  1449. }
  1450. .instant-youtube-title strong:after {
  1451. content: " - $tl:'watch on Youtube'";
  1452. font-weight: normal;
  1453. margin-right: 1ex;
  1454. }
  1455. .instant-youtube-title span {
  1456. color: inherit;
  1457. }
  1458. .instant-youtube-title span:before {
  1459. content: "(";
  1460. }
  1461. .instant-youtube-title span:after {
  1462. content: ")";
  1463. }
  1464. @-webkit-keyframes instant-youtube-fadein {
  1465. from { opacity: 0 }
  1466. to { opacity: 1 }
  1467. }
  1468. @-moz-keyframes instant-youtube-fadein {
  1469. from { opacity: 0 }
  1470. to { opacity: 1 }
  1471. }
  1472. @keyframes instant-youtube-fadein {
  1473. from { opacity: 0 }
  1474. to { opacity: 1 }
  1475. }
  1476. .instant-youtube-container:not(:hover) .instant-youtube-title[hidden] {
  1477. display: none;
  1478. margin: 0;
  1479. }
  1480. .instant-youtube-title:hover {
  1481. text-decoration: underline;
  1482. }
  1483. .instant-youtube-title strong {
  1484. color: white;
  1485. }
  1486. .instant-youtube-options-button {
  1487. opacity: 0.6;
  1488. position: absolute;
  1489. right: 0;
  1490. bottom: 0;
  1491. margin: 0;
  1492. padding: 1.5ex 2ex;
  1493. font-size: 11px;
  1494. text-shadow: 1px 1px 2px black;
  1495. color: white;
  1496. }
  1497. .instant-youtube-options-button:hover {
  1498. opacity: 1;
  1499. background: rgba(0, 0, 0, 0.5);
  1500. }
  1501. .instant-youtube-options {
  1502. display: flex;
  1503. position: absolute;
  1504. right: 0;
  1505. bottom: 0;
  1506. margin: 0;
  1507. padding: 2ex 1ex 2ex 2ex;
  1508. flex-direction: column;
  1509. align-items: flex-start;
  1510. line-height: 1.5;
  1511. text-align: left;
  1512. opacity: 1;
  1513. color: white;
  1514. background: black;
  1515. }
  1516. .instant-youtube-options * {
  1517. width: auto;
  1518. height: auto;
  1519. margin: 0;
  1520. padding: 0;
  1521. font: inherit;
  1522. font-size: 13px;
  1523. vertical-align: middle;
  1524. text-transform: none;
  1525. text-align: left;
  1526. border-radius: 0;
  1527. text-decoration: none;
  1528. color: white;
  1529. background: black;
  1530. }
  1531. .instant-youtube-options > label {
  1532. margin-top: 1ex;
  1533. }
  1534. .instant-youtube-options > label > * {
  1535. display: inline;
  1536. }
  1537. .instant-youtube-options select {
  1538. padding: .5ex .25ex;
  1539. border: 1px solid #444;
  1540. -webkit-appearance: menulist;
  1541. }
  1542. .instant-youtube-options [data-action="size-custom"] input {
  1543. width: 9ex;
  1544. padding: .5ex .5ex .4ex;
  1545. border: 1px solid #666;
  1546. }
  1547. .instant-youtube-options [data-action="buttons"] {
  1548. margin-top: 1em;
  1549. }
  1550. .instant-youtube-options button {
  1551. margin: 0 1ex 0 0;
  1552. padding: .5ex 2ex;
  1553. border: 2px solid gray;
  1554. font-weight: bold;
  1555. }
  1556. .instant-youtube-options button:hover {
  1557. border-color: white;
  1558. }
  1559. .instant-youtube-options > [disabled] {
  1560. opacity: 0.25;
  1561. }
  1562. .instant-youtube-storyboard {
  1563. height: 33%;
  1564. max-height: 90px;
  1565. display: block;
  1566. position: absolute;
  1567. left: 0;
  1568. right: 0;
  1569. bottom: 0;
  1570. overflow: visible;
  1571. overflow-x: visible;
  1572. overflow-y: visible;
  1573. }
  1574. .instant-youtube-storyboard:hover {
  1575. background-color: rgba(0,0,0,0.3);
  1576. }
  1577. .instant-youtube-storyboard[disabled] {
  1578. display:none;
  1579. }
  1580. .instant-youtube-storyboard div {
  1581. display: block;
  1582. position: absolute;
  1583. bottom: 0px;
  1584. pointer-events: none;
  1585. border: 3px solid #888;
  1586. box-shadow: 2px 2px 10px black;
  1587. transition: opacity .25s ease;
  1588. background-color: transparent;
  1589. background-origin: content-box;
  1590. opacity: 0;
  1591. }
  1592. .instant-youtube-storyboard:hover div {
  1593. opacity: 1;
  1594. }
  1595. .instant-youtube-container [pin] {
  1596. position: absolute;
  1597. width: 0;
  1598. height: 0;
  1599. margin: 0;
  1600. padding: 0;
  1601. top: auto; bottom: auto; left: auto; right: auto;
  1602. border-style: solid;
  1603. transition: opacity 2.5s ease-in, opacity 0.4s ease-out;
  1604. opacity: 0;
  1605. z-index: 100;
  1606. }
  1607. .instant-youtube-container[playing]:hover [pin]:not([transparent]) {
  1608. opacity: 1;
  1609. }
  1610. .instant-youtube-container[playing] [pin]:hover {
  1611. cursor: alias;
  1612. opacity: 1;
  1613. transition: opacity 0s;
  1614. }
  1615. .instant-youtube-container [pin=top-left][active] { border-top-color: green; }
  1616. .instant-youtube-container [pin=top-left]:hover { border-top-color: #fc0; }
  1617. .instant-youtube-container [pin=top-left] {
  1618. top: 0; left: 0;
  1619. border-width: 10px 10px 0 0;
  1620. border-color: red transparent transparent transparent;
  1621. }
  1622. .instant-youtube-container [pin=top-right][active] { border-right-color: green; }
  1623. .instant-youtube-container [pin=top-right]:hover { border-right-color: #fc0; }
  1624. .instant-youtube-container [pin=top-right] {
  1625. top: 0; right: 0;
  1626. border-width: 0 10px 10px 0;
  1627. border-color: transparent red transparent transparent;
  1628. }
  1629. .instant-youtube-container [pin=bottom-right][active] { border-bottom-color: green; }
  1630. .instant-youtube-container [pin=bottom-right]:hover { border-bottom-color: #fc0; }
  1631. .instant-youtube-container [pin=bottom-right] {
  1632. bottom: 0; right: 0;
  1633. border-width: 0 0 10px 10px;
  1634. border-color: transparent transparent red transparent;
  1635. }
  1636. .instant-youtube-container [pin=bottom-left][active] { border-left-color: green; }
  1637. .instant-youtube-container [pin=bottom-left]:hover { border-left-color: #fc0; }
  1638. .instant-youtube-container [pin=bottom-left] {
  1639. bottom: 0; left: 0;
  1640. border-width: 10px 0 0 10px;
  1641. border-color: transparent transparent transparent red;
  1642. }
  1643. .instant-youtube-dragndrop-placeholder {
  1644. z-index: 999999999;
  1645. margin: 0;
  1646. padding: 0;
  1647. background: rgba(0, 255, 0, 0.1);
  1648. border: 2px dotted green;
  1649. box-sizing: border-box;
  1650. pointer-events: none;
  1651. }
  1652. */}).replace(/\$tl:'(.+?)'/g, function(m, m1) { return _(m1) })
  1653. );
  1654. }