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