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. A fast simple HTML5 direct playback (720p max) can be selected if available for the video.

当前为 2016-08-07 提交的版本,查看 最新版本

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