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