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