Fast Youtube embedded player

Fast HTML5 direct playback at 720p is used when selected and available. The script also 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.

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

  1. // ==UserScript==
  2. // @name Fast Youtube embedded player
  3. // @description Fast HTML5 direct playback at 720p is used when selected and available. The script also 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.
  4. // @version 1.5.4
  5. // @include *
  6. // @exclude https://www.youtube.com/*
  7. // @author wOxxOm
  8. // @namespace wOxxOm.scripts
  9. // @license MIT License
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @grant GM_xmlhttpRequest
  14. // @connect www.youtube.com
  15. // @connect youtube.com
  16. // @run-at document-start
  17. // ==/UserScript==
  18.  
  19. /* jshint lastsemic:true, multistr:true, laxbreak:true, -W030, -W041, -W084 */
  20.  
  21. var resizeToFit = GM_getValue('resize', true);
  22. var playHTML5 = GM_getValue('playHTML5', false);
  23. var skipCustom = GM_getValue('skipCustom', false);
  24.  
  25. var embedSelector;
  26. initEmbedSelector();
  27.  
  28. function initEmbedSelector() {
  29. embedSelector = 'iframe[src*="youtube.com/embed"]~~~, embed[src*="youtube.com/v"]~~~'
  30. .replace(/~~~/g, skipCustom ? ':not([src*="enablejsapi=1"])' : '');
  31. }
  32.  
  33. processEmbeds(document.querySelectorAll(embedSelector));
  34.  
  35. document.addEventListener('DOMContentLoaded', function() {
  36. if (resizeToFit)
  37. setTimeout(adjustNodes, 0);
  38. injectStylesIfNeeded();
  39. });
  40.  
  41. window.addEventListener('resize', function() {
  42. if (resizeToFit)
  43. setTimeout(adjustNodes, 0);
  44. });
  45.  
  46. var mutQueue = [];
  47. new MutationObserver(function(mutations) {
  48. mutQueue.push(mutations);
  49. if (mutations.length < 100)
  50. processQueue();
  51. else
  52. setTimeout(processQueue, 0);
  53. }).observe(document, {subtree:true, childList:true});
  54.  
  55. function processQueue() {
  56. while (mutQueue.length) {
  57. var mutationBatch = mutQueue.shift();
  58. for (var m=0, ml=mutationBatch.length, mutation; (m<ml) && (mutation=mutationBatch[m]); m++) {
  59. for (var n=0, nodes=mutation.addedNodes, nl=nodes.length, node; (n<nl) && (node=nodes[n]); n++) {
  60. if (node.nodeType != 1) // skip non-ELEMENT_NODE
  61. continue;
  62. if (node.localName == 'iframe' || node.localName == 'embed') {
  63. if (node.matches(embedSelector))
  64. processEmbeds([node]);
  65. }
  66. else if (node.children.length) {
  67. var embeds = node.querySelectorAll(embedSelector);
  68. if (embeds.length)
  69. processEmbeds(embeds);
  70. }
  71. }
  72. }
  73. }
  74. }
  75.  
  76. function processEmbeds(nodes) {
  77. for (var i=0, nl=nodes.length, n; i<nl && (n=nodes[i]); i++) {
  78. if (!n.parentNode ||
  79. n.className.indexOf('instant-youtube-') >= 0 ||
  80. n.src.indexOf('autoplay=1') > 0 ||
  81. n.onload && getComputedStyle(n.parentNode).display == 'none' // skip some retarded loaders
  82. )
  83. continue;
  84.  
  85. var id = n.src.match(/(?:embed\/|v[=\/])([^\s,.()\[\]?]+?)(?:[&?\/].*|$)/);
  86. if (!id)
  87. continue;
  88. id = id[1];
  89.  
  90. // np = parent node with nonzero width (i.e. independent of our video element), used in fit-to-width mode
  91. var np = n.parentNode, npw;
  92. while (np && !(npw=np.clientWidth))
  93. np = np.parentNode;
  94.  
  95. var containerWidth = resizeToFit ? npw : n.clientWidth;
  96. var containerHeight = resizeToFit ? npw / 16 * 9 : n.clientHeight;
  97.  
  98. var div = document.createElement('div');
  99. div.className = 'instant-youtube-container';
  100. div.srcEmbed = n.src;
  101. div.style.maxWidth = containerWidth + 'px';
  102. div.style.height = containerHeight + 'px';
  103. div.originalWidth = n.width;
  104. div.originalHeight = n.height;
  105. div.videoID = id;
  106.  
  107. var wrapper = div.appendChild(document.createElement('div'));
  108. wrapper.className = 'instant-youtube-wrapper';
  109.  
  110. var img = wrapper.appendChild(document.createElement('img'));
  111. img.className = 'instant-youtube-thumbnail';
  112. img.src = 'https://i.ytimg.com/vi/' + id + '/maxresdefault.jpg';
  113. img.style.cssText = 'max-width:100%; margin:0 0 0 0;';
  114. img.title = 'Shift-click to use alternative player';
  115. img.onload = function(e) {
  116. var img = e.target;
  117. if (img.naturalWidth <= 120)
  118. return img.onerror(e);
  119. var fitToWidth = true;
  120. if (img.naturalHeight) {
  121. var ratio = img.naturalWidth / img.naturalHeight;
  122. if (ratio > 4.1/3 && ratio < 16/9.1) {
  123. img.style.cssText += 'width:auto!important; height:100%!important';
  124. fitToWidth = false;
  125. }
  126. }
  127. if (fitToWidth) {
  128. img.style.cssText += 'width:100%!important; height:auto!important';
  129. img.style.marginTop = ((img.parentNode.clientHeight - img.clientHeight) / 2).toFixed(1) + 'px';
  130. }
  131. img.style.setProperty('opacity', '1');
  132. if (img.parentNode.iframeHasLoader)
  133. img.parentNode.parentNode.style.display = '';
  134. };
  135. img.onerror = function(e) {
  136. var img = e.target;
  137. if (img.src.indexOf('maxresdefault') > 0)
  138. img.src = img.src.replace('maxresdefault','hqdefault');
  139. };
  140.  
  141. GM_xmlhttpRequest({
  142. method: 'GET',
  143. url: div.srcEmbed.replace(/\/(embed\/|v[=\/])/, '/watch?v='),
  144. context: div,
  145. onload: parseWatchPage
  146. });
  147.  
  148. wrapper.insertAdjacentHTML('beforeend', '\
  149. <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>\
  150. <span class="instant-youtube-link">' + (playHTML5 ? 'Play with Youtube player' : 'Play directly (up to 720p)') + '</span>\
  151. <div class="instant-youtube-options">\
  152. <label>Resize to fit <input data-action="resize" type="checkbox"' + (resizeToFit ? ' checked' : '') + '></label>\
  153. <label title="Tip: shift-clicking thumbnails will use alternative player">\
  154. Play directly <input data-action="direct" type="checkbox"' + (playHTML5 ? ' checked' : '') + '></label>\
  155. <label title="Do not process customized videos with enablejsapi=1 parameter (requires page reload)">Safe <input data-action="safe" type="checkbox"' + (skipCustom ? ' checked' : '') + '></label>\
  156. </div>\
  157. ');
  158.  
  159. if (n.parentNode.localName == 'object')
  160. n = n.parentNode;
  161. n.parentNode.insertBefore(div, n);
  162. n.remove();
  163.  
  164. div.addEventListener('click', clickHandler);
  165. }
  166.  
  167. injectStylesIfNeeded();
  168. return true;
  169. }
  170.  
  171. function adjustNodes() {
  172. var nearest = null, minDistance = window.innerHeight;
  173. var vids = [].slice.call(document.getElementsByClassName('instant-youtube-container'));
  174. vids.forEach(function(n) {
  175. var bounds = n.getBoundingClientRect();
  176. var distance = Math.abs((bounds.bottom + bounds.top)/2 - window.innerHeight/2);
  177. if (distance < minDistance) {
  178. minDistance = distance;
  179. nearest = n;
  180. }
  181. });
  182. var resized = false;
  183. vids.forEach(function(n) {
  184. if (Math.abs(n.parentNode.clientWidth - parseFloat(n.style.maxWidth)) > 2) {
  185. var img = n.getElementsByClassName('instant-youtube-thumbnail')[0];
  186. var npw = n.parentNode.clientWidth;
  187. var nph = npw / 16 * 9;
  188. n.style.maxWidth = img.style.width = npw + 'px';
  189. n.style.height = nph + 'px';
  190. img.style.marginLeft = Math.round((npw - nph / 9 * 16) / 2) + 'px';
  191. img.style.marginTop = ((nph - img.clientHeight) / 2).toFixed(1) + 'px';
  192. resized = true;
  193. }
  194. });
  195. if (resized && nearest)
  196. setTimeout(function() {
  197. nearest.scrollIntoView();
  198. }, 100);
  199. }
  200.  
  201. function parseWatchPage(response) {
  202. var div = response.context;
  203. var txt = response.responseText;
  204.  
  205. // parse width & height to adjust the thumbnail
  206. var w = txt.match(/<meta property="og:video:width" content="(\d+)">/);
  207. var h = txt.match(/<meta property="og:video:height" content="(\d+)">/);
  208. if (w && h) {
  209. var img = div.querySelector('img');
  210. w = w[1]|0; var thw = img.naturalWidth, divw = div.clientWidth;
  211. h = h[1]|0; var thh = img.naturalHeight, divh = div.clientHeight;
  212. // if both video and thumbnail are 4:3, fit the image to height
  213. if (Math.abs(h/w*divw / divh - 1) > 0.05 && thw && thh && Math.abs(thh/thw*divw / divh - 1) > 0.05) {
  214. img.style.cssText = img.style.cssText.replace(/\bheight:.*?;/, 'height:' + img.clientHeight + 'px!important;');
  215. img.style.transition = 'height 1s ease, margin-top 1s ease';
  216. setTimeout(function() {
  217. img.style.cssText += 'width:auto!important; height:100%!important';
  218. img.style.marginTop = '0';
  219. setTimeout(function() {
  220. img.style.transition = '';
  221. }, 1000);
  222. }, 0);
  223. }
  224. }
  225.  
  226. // parse video sources
  227. var m = txt.match(/ytplayer\.config\s*=\s*(\{.+?\});\s*ytplayer\.load/);
  228. var videoInfo = [];
  229. if (m) {
  230. var cfg = JSON.parse(m[1]), streams = {};
  231. cfg.args.url_encoded_fmt_stream_map.split(',').forEach(function(stream) {
  232. var params = {};
  233. stream.split('&').forEach(function(kv) {
  234. params[kv.split('=')[0]] = decodeURIComponent(kv.split('=')[1]);
  235. });
  236. streams[params.itag] = params;
  237. });
  238. cfg.args.fmt_list.split(',').forEach(function(fmt) {
  239. var itag = fmt.split('/')[0];
  240. var dimensions = fmt.split('/')[1];
  241. var stream = streams[itag];
  242. if (stream) {
  243. videoInfo.push({
  244. src: stream.url,
  245. title: stream.quality + ', ' + dimensions + ', ' + stream.type
  246. });
  247. }
  248. });
  249. } else {
  250. var rx = /url=([^=]+?mime%3Dvideo%252F(?:mp4|webm)[^=]+?)(?:,quality|,itag|.u0026)/g;
  251. var text = txt.split('url_encoded_fmt_stream_map')[1];
  252. while (m = rx.exec(text)) {
  253. videoInfo.push({
  254. src: decodeURIComponent(decodeURIComponent(m[1]))
  255. });
  256. }
  257. }
  258.  
  259. var title = txt.match(/<title>(.+?)(?:\s*-\s*YouTube)?<\/title>/);
  260. if (title) {
  261. var duration = txt.match(/<meta itemprop="duration" content="\D*(\d+.*?)S?">/);
  262. var a = div.firstElementChild.appendChild(document.createElement('a'));
  263. a.className = 'instant-youtube-persistent-title';
  264. a.innerHTML = '<strong>' + title[1] + '</strong>' +
  265. (duration ? '<span>' + duration[1].replace(/[HM]/, ':0').replace(/\b0(\d\d)/, '$1') + '</span>' : '');
  266. a.href = 'https://www.youtube.com/watch?v=' + div.videoID;
  267. a.target = '_blank';
  268. ['animation', 'webkitAnimation', 'mozAnimation'].some(function(prop) {
  269. if (prop in a.style) {
  270. a.style[prop] = 'instant-youtube-fadein 1s ease-in';
  271. setTimeout(function() { a.style[prop] = '' }, 1000);
  272. return true;
  273. }
  274. });
  275. }
  276.  
  277. if (videoInfo.length)
  278. div.videoInfo = videoInfo;
  279.  
  280. injectStylesIfNeeded();
  281. }
  282.  
  283. function clickHandler(e) {
  284. if (e.target.href)
  285. return;
  286. if (e.target.closest('.instant-youtube-options'))
  287. return options(e);
  288. div = e.target.closest('.instant-youtube-container');
  289. div.removeEventListener('click', clickHandler);
  290. div.querySelector('svg').outerHTML = '<span class="instant-youtube-loading-button"></span>';
  291.  
  292. var alternateMode = e.shiftKey || e.target.className == 'instant-youtube-link';
  293. if (div.videoInfo && (!!playHTML5 + !!alternateMode == 1))
  294. playDirectly(div);
  295. else
  296. switchToIFrame.call(div);
  297. }
  298.  
  299. function playDirectly(div) {
  300. div.querySelector('.instant-youtube-options').style.display = 'none';
  301. div.querySelector('.instant-youtube-link').style.display = 'none';
  302.  
  303. var video = document.createElement('video');
  304. video.controls = true;
  305. video.autoplay = true;
  306. video.style.cssText = 'width:'+div.clientWidth+'px!important; height:'+div.clientHeight+'px!important;';
  307. video.className = 'instant-youtube-embed';
  308. video.volume = GM_getValue('volume', 0.5);
  309.  
  310. div.videoInfo.forEach(function(src) {
  311. var srcdom = video.appendChild(document.createElement('source'));
  312. Object.keys(src).forEach(function(k) { srcdom[k] = src[k] });
  313. srcdom.onerror = switchToIFrame.bind(div);
  314. });
  315.  
  316.  
  317. if (window.chrome) {
  318. video.addEventListener('click', function(e) {
  319. this.paused ? this.play() : this.pause();
  320. });
  321. }
  322. video.interval = (function() {
  323. return setInterval(function() {
  324. if (video.volume != GM_setValue('volume', 0.5))
  325. GM_setValue('volume', video.volume);
  326. }, 1000);
  327. })();
  328. var title = div.querySelector('.instant-youtube-persistent-title');
  329. if (title) {
  330. video.onpause = function() { title.removeAttribute('hidden') };
  331. video.onplay = function() { title.setAttribute('hidden', true) };
  332. }
  333. video.onloadeddata = function(e) {
  334. pauseOtherVideos(this);
  335. div.firstElementChild.appendChild(this);
  336. this.style.opacity = 1;
  337. var img = div.querySelector('img');
  338. img.style.transition = 'opacity 1s';
  339. img.style.opacity = 0;
  340. };
  341. }
  342.  
  343. function switchToIFrame(e) {
  344. var div = this;
  345. if (e) console.log('Direct linking failed on %s, switching to IFRAME player', div.srcEmbed);
  346. var iframeHTML = '<iframe class="instant-youtube-embed" allowtransparency="true" src="' +
  347. div.srcEmbed.replace('/v/', '/embed/') +
  348. (div.srcEmbed.indexOf('?') > 0 ? '&' : '?') +
  349. 'html5=1' +
  350. '&autoplay=1' +
  351. '&autohide=2' +
  352. '&border=0' +
  353. '&controls=1' +
  354. '&fs=1' +
  355. '&showinfo=1' +
  356. '&ssl=1' +
  357. '&theme=dark' +
  358. '&enablejsapi=1' +
  359. '" frameborder="0" allowfullscreen width="' + div.clientWidth + '" height="' + div.clientHeight + '"></iframe>';
  360. div.firstElementChild.insertAdjacentHTML('beforeend', iframeHTML);
  361.  
  362. div.firstElementChild.lastElementChild.onload = function() {
  363. pauseOtherVideos(this);
  364. this.style.opacity = 1;
  365.  
  366. var div = this.closest('.instant-youtube-container');
  367. div.setAttribute('iframe', '');
  368. setTimeout(function() {
  369. div.querySelector('img').style.display = 'none';
  370. var title = div.querySelector('.instant-youtube-persistent-title');
  371. if (title)
  372. title.remove();
  373. }, 2000);
  374. };
  375. if (e && e.target) {
  376. var video = e.target.parentNode;
  377. while (video.lastElementChild)
  378. video.lastElementChild.remove();
  379. }
  380. }
  381.  
  382. function pauseOtherVideos(activePlayer) {
  383. [].forEach.call(activePlayer.ownerDocument.getElementsByClassName('instant-youtube-embed'), function(v) {
  384. if (v == activePlayer)
  385. return;
  386. switch (v.localName) {
  387. case 'video':
  388. if (!v.paused)
  389. v.pause();
  390. break;
  391. case 'iframe':
  392. (function() { try { v.contentWindow.postMessage('{"event":"command", "func":"pauseVideo", "args":""}', '*') } catch(e) {} })();
  393. break;
  394. }
  395. });
  396. }
  397.  
  398. function options(e) {
  399. var action = e.target.dataset.action;
  400. var state = e.target.checked;
  401. switch (action) {
  402. case 'resize':
  403. resizeToFit = state;
  404. GM_setValue('resize', resizeToFit);
  405. [].forEach.call(document.querySelectorAll('div.instant-youtube-container'), function(n) {
  406. var w = n.originalWidth, h = n.originalHeight, img = n.querySelector('img');
  407. if (resizeToFit) {
  408. for (var np=n.parentNode, npw; np && !(npw=np.clientWidth); np=np.parentNode) {}
  409. w = npw;
  410. h = npw / 16 * 9;
  411. }
  412. n.style.maxWidth = w + 'px';
  413. n.style.height = h + 'px';
  414. img.style.width = (h / 9 * 16) + 'px';
  415. img.style.marginLeft = Math.round((w - h / 9 * 16) / 2) + 'px';
  416. img.style.marginTop = ((h - img.clientHeight) / 2).toFixed(1) + 'px';
  417. n.querySelector('[data-action="resize"]').checked = resizeToFit;
  418. var video = n.querySelector('video');
  419. if (video) {
  420. video.width = w;
  421. video.height = h;
  422. }
  423. });
  424. break;
  425. case 'direct':
  426. playHTML5 = state;
  427. GM_setValue('playHTML5', playHTML5);
  428. [].forEach.call(document.querySelectorAll('div.instant-youtube-container'), function(div) {
  429. div.querySelector('span.instant-youtube-link').textContent = playHTML5 ? 'Play with Youtube player' : 'Play directly (up to 720p)';
  430. div.querySelector('[data-action="direct"]').checked = playHTML5;
  431. });
  432. break;
  433. case 'safe':
  434. skipCustom = state;
  435. GM_setValue('skipCustom', skipCustom);
  436. initEmbedSelector();
  437. [].forEach.call(document.querySelectorAll('div.instant-youtube-container [data-action="safe"]'), function(e) {
  438. e.checked = skipCustom;
  439. });
  440. break;
  441. }
  442. }
  443.  
  444. function injectStylesIfNeeded() {
  445. if (document.head.innerHTML.indexOf('.instant-youtube-container') > 0)
  446. return;
  447. GM_addStyle('\
  448. .instant-youtube-container {contain:strict; position:relative; overflow:hidden; cursor:pointer; background-color:black; padding:0; margin:0; font:normal 14px/1.0 sans-serif,Arial,Helvetica,Verdana; text-align:center}\
  449. .instant-youtube-container .instant-youtube-wrapper {width:100%; height:100%}\
  450. .instant-youtube-container .instant-youtube-thumbnail {transition:opacity 0.1s ease-out; opacity:0; padding:0; margin:0}\
  451. .instant-youtube-container .instant-youtube-play-button {position:absolute; left:0; right:0; top:0; bottom:0; margin:auto; width:85px; height:60px}\
  452. .instant-youtube-container .instant-youtube-loading-button {position:absolute; left:0; right:0; top:0; bottom:0; padding:0; margin:auto; display:block; width:20px; height:20px; background: url("data:image/gif;base64,R0lGODlhFAAUAJEDAMzMzLOzs39/f////yH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgADACwAAAAAFAAUAAACPJyPqcuNItyCUJoQBo0ANIxpXOctYHaQpYkiHfM2cUrCNT0nqr4uudsz/IC5na/2Mh4Hu+HR6YBaplRDAQAh+QQFCgADACwEAAIADAAGAAACFpwdcYupC8BwSogR46xWZHl0l8ZYQwEAIfkEBQoAAwAsCAACAAoACgAAAhccMKl2uHxGCCvO+eTNmishcCCYjWEZFgAh+QQFCgADACwMAAQABgAMAAACFxwweaebhl4K4VE6r61DiOd5SfiN5VAAACH5BAUKAAMALAgACAAKAAoAAAIYnD8AeKqcHIwwhGntEWLkO3CcB4biNEIFACH5BAUKAAMALAQADAAMAAYAAAIWnDSpAHa4GHgohCHbGdbipnBdSHphAQAh+QQFCgADACwCAAgACgAKAAACF5w0qXa4fF6KUoVQ75UaA7Bs3yeNYAkWACH5BAUKAAMALAIABAAGAAwAAAIXnCU2iMfaRghqTmMp1moAoHyfIYIkWAAAOw==")}\
  453. .instant-youtube-container:hover .ytp-large-play-button-svg {fill:#CC181E}\
  454. .instant-youtube-container .instant-youtube-link, .instant-youtube-container .instant-youtube-link:link, .instant-youtube-container .instant-youtube-link:visited, .instant-youtube-container .instant-youtube-link:active, .instant-youtube-container .instant-youtube-link:focus {\
  455. position:absolute; top:50%; left:0; right:0; width:20em; height:1.7em; margin:60px auto; padding:0; border:none; \
  456. display:block; text-align:center; text-decoration:none; color:white; text-shadow:1px 1px 3px black; font-weight:bold;\
  457. }\
  458. .instant-youtube-container span.instant-youtube-link {font-weight:normal; font-size:12px}\
  459. .instant-youtube-container .instant-youtube-link:hover {color:white; text-decoration:underline; background:transparent}\
  460. .instant-youtube-container .instant-youtube-embed {position:absolute; left:0; top:0; padding:0; margin:0; height:inherit!important; opacity:0; transition:opacity 2s!important}\
  461. .instant-youtube-container iframe {z-index:10}\
  462. .instant-youtube-container .instant-youtube-persistent-title {\
  463. display:block; z-index:9; background-color:rgba(0,0,0,0.5); color:white;\
  464. width:100%; height: 1.9em; top:0; left:0; right:0; position:absolute; z-index: 9;\
  465. color:white; text-shadow:1px 1px 2px black; text-align:center; text-decoration:none;\
  466. margin:0; padding:0.5em 0.5em 0.2em; border:none;\
  467. }\
  468. .instant-youtube-container .instant-youtube-persistent-title strong:after {content:" - watch on Youtube"; font-weight:normal; margin-right:1ex}\
  469. .instant-youtube-container .instant-youtube-persistent-title span {color:inherit}\
  470. .instant-youtube-container .instant-youtube-persistent-title span:before {content:"("}\
  471. .instant-youtube-container .instant-youtube-persistent-title span:after {content:")"}\
  472. @-webkit-keyframes instant-youtube-fadein { from {opacity:0} to {opacity:1} }\
  473. @-moz-keyframes instant-youtube-fadein { from {opacity:0} to {opacity:1} }\
  474. @keyframes instant-youtube-fadein { from {opacity:0} to {opacity:1} }\
  475. .instant-youtube-container:not(:hover) .instant-youtube-persistent-title[hidden] {display:none; margin:0}\
  476. .instant-youtube-container .instant-youtube-persistent-title:hover {text-decoration:underline}\
  477. .instant-youtube-container .instant-youtube-persistent-title strong {color:white}\
  478. .instant-youtube-container .instant-youtube-options {position:absolute; right:2px; bottom:0; color:white; text-shadow:1px 1px 2px black; padding:0; margin:0; opacity:0.6}\
  479. .instant-youtube-container .instant-youtube-options:hover {opacity:1; background:rgba(0,0,0,0.5); padding-left:1ex;}\
  480. .instant-youtube-container .instant-youtube-options * {display:inline; color:white; font-size:13px; vertical-align:middle; padding:0; margin:0}\
  481. ');
  482. }