FYTE /Fast YouTube Embedded/ Player

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

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

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