Resize YT To Window Size

Moves the YouTube video to the top of the website and resizes it to the window size.

As of 2015-05-28. See the latest version.

  1. // ==UserScript==
  2. // @name Resize YT To Window Size
  3. // @description Moves the YouTube video to the top of the website and resizes it to the window size.
  4. // @author Chris H (Zren / Shade)
  5. // @icon https://youtube.com/favicon.ico
  6. // @homepageURL https://github.com/Zren/ResizeYoutubePlayerToWindowSize/
  7. // @namespace http://xshade.ca
  8. // @version 65
  9. // @include http*://*.youtube.com/*
  10. // @include http*://youtube.com/*
  11. // @include http*://*.youtu.be/*
  12. // @include http*://youtu.be/*
  13. // ==/UserScript==
  14.  
  15. // Github: https://github.com/Zren/ResizeYoutubePlayerToWindowSize
  16. // GreasyFork: https://greasyfork.org/scripts/811-resize-yt-to-window-size
  17. // OpenUserJS.org: https://openuserjs.org/scripts/zren/Resize_YT_To_Window_Size
  18. // Userscripts.org: http://userscripts-mirror.org/scripts/show/153699
  19.  
  20. (function (window) {
  21. "use strict";
  22. //--- Imported Globals
  23. // yt
  24. // ytcenter
  25. // ytplayer
  26. var uw = window.top;
  27.  
  28. //--- Already Loaded?
  29. // GreaseMonkey loads this script twice for some reason.
  30. if (uw.ytwp) return;
  31.  
  32. //--- Utils
  33. function isStringType(obj) { return typeof obj === 'string'; }
  34. function isArrayType(obj) { return obj instanceof Array; }
  35. function isObjectType(obj) { return typeof obj === 'object'; }
  36. function isUndefined(obj) { return typeof obj === 'undefined'; }
  37. function buildVenderPropertyDict(propertyNames, value) {
  38. var d = {};
  39. for (var i in propertyNames)
  40. d[propertyNames[i]] = value;
  41. return d;
  42. }
  43.  
  44. //--- jQuery
  45. // Based on jQuery
  46. // https://github.com/jquery/jquery/blob/master/src/manipulation.js
  47. var core_rnotwhite = /\S+/g;
  48. var rclass = /[\t\r\n\f]/g;
  49. var rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g;
  50.  
  51. var jQuery = {
  52. trim: function( text ) {
  53. return (text || "").replace( rtrim, "" );
  54. },
  55. addClass: function( elem, value ) {
  56. var classes, cur, clazz, j,
  57. proceed = typeof value === "string" && value;
  58.  
  59. if ( proceed ) {
  60. // The disjunction here is for better compressibility (see removeClass)
  61. classes = ( value || "" ).match( core_rnotwhite ) || [];
  62.  
  63. cur = elem.nodeType === 1 && ( elem.className ?
  64. ( " " + elem.className + " " ).replace( rclass, " " ) :
  65. " "
  66. );
  67.  
  68. if ( cur ) {
  69. j = 0;
  70. while ( (clazz = classes[j++]) ) {
  71. if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
  72. cur += clazz + " ";
  73. }
  74. }
  75. elem.className = jQuery.trim( cur );
  76. }
  77. }
  78. },
  79. removeClass: function( elem, value ) {
  80. var classes, cur, clazz, j,
  81. proceed = arguments.length === 0 || typeof value === "string" && value;
  82.  
  83. if ( proceed ) {
  84. classes = ( value || "" ).match( core_rnotwhite ) || [];
  85.  
  86. // This expression is here for better compressibility (see addClass)
  87. cur = elem.nodeType === 1 && ( elem.className ?
  88. ( " " + elem.className + " " ).replace( rclass, " " ) :
  89. ""
  90. );
  91.  
  92. if ( cur ) {
  93. j = 0;
  94. while ( (clazz = classes[j++]) ) {
  95. // Remove *all* instances
  96. while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
  97. cur = cur.replace( " " + clazz + " ", " " );
  98. }
  99. }
  100. elem.className = value ? jQuery.trim( cur ) : "";
  101. }
  102. }
  103. }
  104. };
  105.  
  106.  
  107. //--- Stylesheet
  108. var JSStyleSheet = function(id) {
  109. this.id = id;
  110. this.stylesheet = '';
  111. };
  112.  
  113. JSStyleSheet.prototype.buildRule = function(selector, styles) {
  114. var s = "";
  115. for (var key in styles) {
  116. s += "\t" + key + ": " + styles[key] + ";\n";
  117. }
  118. return selector + " {\n" + s + "}\n";
  119. };
  120.  
  121. JSStyleSheet.prototype.appendRule = function(selector, k, v) {
  122. if (isArrayType(selector))
  123. selector = selector.join(',\n');
  124. var newStyle;
  125. if (!isUndefined(k) && !isUndefined(v) && isStringType(k)) { // v can be any type (as we stringify it).
  126. var d = {};
  127. d[k] = v;
  128. newStyle = this.buildRule(selector, d);
  129. } else if (!isUndefined(k) && isUndefined(v) && isObjectType(k)) {
  130. newStyle = this.buildRule(selector, k);
  131. } else {
  132. // Invalid Arguments
  133. console.log('Illegal arguments', arguments);
  134. return;
  135. }
  136.  
  137. this.stylesheet += newStyle;
  138. };
  139.  
  140. JSStyleSheet.injectIntoHeader = function(injectedStyleId, stylesheet) {
  141. var styleElement = document.getElementById(injectedStyleId);
  142. if (!styleElement) {
  143. styleElement = document.createElement('style');
  144. styleElement.type = 'text/css';
  145. styleElement.id = injectedStyleId;
  146. document.getElementsByTagName('head')[0].appendChild(styleElement);
  147. }
  148. styleElement.appendChild(document.createTextNode(stylesheet));
  149. };
  150.  
  151. JSStyleSheet.prototype.injectIntoHeader = function(injectedStyleId, stylesheet) {
  152. JSStyleSheet.injectIntoHeader(this.id, this.stylesheet);
  153. };
  154.  
  155. //--- Constants
  156. var scriptShortName = 'ytwp'; // YT Window Player
  157. var scriptStyleId = scriptShortName + '-style'; // ytwp-style
  158. var scriptBodyClassId = scriptShortName + '-window-player'; // .ytwp-window-player
  159. var viewingVideoClassId = scriptShortName + '-viewing-video'; // .ytwp-viewing-video
  160. var topOfPageClassId = scriptShortName + '-scrolltop'; // .ytwp-scrolltop
  161. var scriptBodyClassSelector = 'body.' + scriptBodyClassId; // body.ytwp-window-player
  162.  
  163. var videoContainerId = 'player';
  164. var videoContainerPlacemarkerId = scriptShortName + '-placemarker'; // ytwp-placemarker
  165.  
  166. var transitionProperties = ["transition", "-ms-transition", "-moz-transition", "-webkit-transition", "-o-transition"];
  167. var transformProperties = ["transform", "-ms-transform", "-moz-transform", "-webkit-transform", "-o-transform"];
  168.  
  169. //--- YTWP
  170. var ytwp = uw.ytwp = {
  171. scriptShortName: scriptShortName, // YT Window Player
  172. log_: function(logger, args) { logger.apply(console, ['[' + this.scriptShortName + '] '].concat(Array.prototype.slice.call(args))); return 1; },
  173. log: function() { return this.log_(console.log, arguments); },
  174. error: function() { return this.log_(console.error, arguments); },
  175.  
  176. initialized: false,
  177. pageReady: false,
  178. watchPage: false,
  179. };
  180.  
  181. ytwp.util = {
  182. isWatchUrl: function (url) {
  183. if (!url)
  184. url = uw.location.href;
  185. return url.match(/https?:\/\/(www\.)?youtube.com\/watch\?/);
  186. }
  187. };
  188.  
  189. var Html5PlayerFix = {
  190. YTRect: null,
  191. YTApplication: null,
  192. playerInstances: null,
  193. moviePlayerElement: null,
  194. };
  195. Html5PlayerFix.getPlayerRect = function() {
  196. return new Html5PlayerFix.YTRect(Html5PlayerFix.moviePlayerElement.clientWidth, Html5PlayerFix.moviePlayerElement.clientHeight);
  197. };
  198. Html5PlayerFix.getApplicationClass = function() {
  199. if (Html5PlayerFix.YTApplication === null) {
  200. var testEl = document.createElement('div');
  201. var testAppInstance = uw.yt.player.Application.create(testEl, {});
  202. Html5PlayerFix.YTApplication = testAppInstance.constructor;
  203.  
  204. // Cleanup testAppInstance
  205. var playerInstances = Html5PlayerFix.getPlayerInstances();
  206.  
  207. var testAppInstanceKey = null;
  208. Object.keys(playerInstances).forEach(function(key) {
  209. if (playerInstances[key] === testAppInstance) {
  210. testAppInstanceKey = key;
  211. }
  212. });
  213. testAppInstance.dispose();
  214. delete playerInstances[testAppInstanceKey];
  215. }
  216.  
  217.  
  218. return Html5PlayerFix.YTApplication;
  219. };
  220. Html5PlayerFix.getPlayerInstances = function() {
  221. if (Html5PlayerFix.playerInstances === null) {
  222. var YTApplication = Html5PlayerFix.getApplicationClass();
  223. if (YTApplication === null)
  224. return null;
  225.  
  226. // Use yt.player.Application.create to find the playerInstancesKey.
  227. // function (a,b){try{var c=t$.B(a);if(t$.j[c]){try{t$.j[c].dispose()}catch(d){cg(d)}t$.j[c]=null}var e=new t$(a,b);Ji(e,function(){t$.j[c]=null});return t$.j[c]=e}catch(g){throw cg(g),g;}}
  228. var appCreateRegex = /^function \(a,b\)\{try\{var c=([a-zA-Z_$][\w_$]*)\.([a-zA-Z_$][\w_$]*)\(a\);if\(([a-zA-Z_$][\w_$]*)\.([a-zA-Z_$][\w_$]*)\[c\]\)/;
  229. var fnString = yt.player.Application.create.toString();
  230. var m = appCreateRegex.exec(fnString);
  231. if (m) {
  232. var playerInstancesKey = m[4];
  233. Html5PlayerFix.playerInstances = YTApplication[playerInstancesKey];
  234. } else {
  235. ytwp.error('Error trying to find playerInstancesKey.', fnString);
  236. }
  237. Html5PlayerFix.playerInstances = YTApplication.j;
  238. }
  239.  
  240. return Html5PlayerFix.playerInstances;
  241. };
  242. Html5PlayerFix.getPlayerInstance = function() {
  243. if (!ytwp.ytapp) {
  244. var playerInstances = Html5PlayerFix.getPlayerInstances();
  245. ytwp.log('playerInstances', playerInstances);
  246. var appInstance = null;
  247. var appInstanceKey = null;
  248. Object.keys(playerInstances).forEach(function(key) {
  249. appInstanceKey = key;
  250. appInstance = playerInstances[key];
  251. });
  252. ytwp.ytapp = appInstance;
  253. }
  254. return ytwp.ytapp;
  255. };
  256. Html5PlayerFix.autohideControls = function() {
  257. var moviePlayerElement = document.getElementById('movie_player');
  258. if (!moviePlayerElement) return;
  259. // ytwp.log(moviePlayerElement.classList);
  260. jQuery.removeClass(moviePlayerElement, 'autohide-controlbar autominimize-controls-aspect autohide-controls-fullscreenonly autohide-controls hide-controls-when-cued autominimize-progress-bar autominimize-progress-bar-fullscreenonly autohide-controlbar-fullscreenonly autohide-controls-aspect autohide-controls-fullscreen autominimize-progress-bar-non-aspect');
  261. jQuery.addClass(moviePlayerElement, 'autominimize-progress-bar autohide-controls hide-controls-when-cued');
  262. // ytwp.log(moviePlayerElement.classList);
  263. };
  264. Html5PlayerFix.update = function() {
  265. if (!Html5PlayerFix.playerInstances)
  266. return;
  267. for (var key in Html5PlayerFix.playerInstances) {
  268. var playerInstance = Html5PlayerFix.playerInstances[key];
  269. Html5PlayerFix.updatePlayerInstance(playerInstance);
  270. }
  271. };
  272. Html5PlayerFix.updatePlayerInstance = function(app) {
  273. if (!app) {
  274. return;
  275. }
  276.  
  277. var moviePlayerElement = document.getElementById('movie_player');
  278. var moviePlayer = null;
  279. var moviePlayerKey = null;
  280.  
  281. // function (a){var b=this.j.X(),c=n$.L.xb.call(this);a||"detailpage"!=b.ma||b.ib||b.experiments.T||(c.height+=30);return c}
  282. // function (a){var b=this.app.X(),c=n$.M.xb.call(this);a||!JK(b)||b.ab||b.experiments.U||(c.height+=30);return c}
  283. var clientRectFnRegex1 = /^(function \(a\)\{var b=this\.([a-zA-Z_$][\w_$]*)\.([a-zA-Z_$][\w_$]*)\(\)).*(\|\|\(c\.height\+=30\);return c})$/;
  284. // function (){var a=this.A.U();if(window.matchMedia){if((a.wb||a.Fb)&&window.matchMedia("(width: "+window.innerWidth+"px) and (height: "+window.innerHeight+"px)").matches)return new H(window.innerWidth,window.innerHeight);if("detailpage"==a.ja&&"blazer"!=a.j&&!a.Fb){a=a.experiments.A;if(window.matchMedia(S6.C).matches)return new H(426,a?280:240);var b=this.A.ha;if(window.matchMedia(b?S6.o:S6.j).matches)return new H(1280,a?760:720);if(b||window.matchMedia(S6.A).matches)return new H(854,a?520:480);if(window.matchMedia(S6.B).matches)return new H(640,a?400:360)}}return new H(this.element.clientWidth,this.element.clientHeight)}
  285. var clientRectFnRegex2 = /^(function \()(.|\n)*(return new ([a-zA-Z_$][\w_$]*)\(this\.element\.clientWidth,this\.element\.clientHeight\)})$/;
  286. var clientRectFn = null;
  287. var clientRectFnKey = null;
  288.  
  289. var fnAlreadyReplacedCount = 0;
  290.  
  291. Object.keys(app).forEach(function(key1) {
  292. var val1 = app[key1];//console.log(key1, val1);
  293. if (typeof val1 === 'object' && val1 !== null && val1.element === moviePlayerElement) {
  294. moviePlayer = val1;
  295. moviePlayerKey = key1;
  296.  
  297. Object.keys(moviePlayer.constructor.prototype).forEach(function(key2) {
  298. var val2 = moviePlayer[key2];//console.log(key1, key2, val2);
  299. if (typeof val2 === 'function') {
  300. var fnString = val2.toString();
  301. // console.log(fnString);
  302. if (clientRectFn === null && (clientRectFnRegex1.test(fnString) || clientRectFnRegex2.test(fnString))) {
  303. clientRectFn = val2;
  304. clientRectFnKey = key2;
  305. } else if (val2 === Html5PlayerFix.getPlayerRect) {
  306. fnAlreadyReplacedCount += 1;
  307. } else {
  308. // console.log(key1, key2, val2, '[Not Used]');
  309. }
  310. }
  311. });
  312. }
  313. });
  314.  
  315. if (fnAlreadyReplacedCount > 0) {
  316. return;
  317. }
  318.  
  319. if (moviePlayer === null || clientRectFn === null) {
  320. console.log('[ytwp] ', '[Error]', 'HTML5 Player has changed or there\'s multiple playerInstances and this one has been destroyed.');
  321. console.log('moviePlayer', moviePlayerKey, moviePlayer);
  322. console.log('clientRectFn', clientRectFnKey, clientRectFn);
  323. console.log('fnAlreadyReplacedCount', fnAlreadyReplacedCount);
  324. return;
  325. }
  326. Html5PlayerFix.moviePlayerElement = moviePlayerElement;
  327. Html5PlayerFix.YTRect = moviePlayer[clientRectFnKey].call(moviePlayer).constructor;
  328.  
  329. moviePlayer[clientRectFnKey] = Html5PlayerFix.getPlayerRect;
  330. };
  331. ytwp.Html5PlayerFix = Html5PlayerFix;
  332.  
  333. ytwp.event = {
  334. init: function() {
  335. ytwp.log('init');
  336. if (!ytwp.initialized) {
  337. ytwp.isWatchPage = ytwp.util.isWatchUrl();
  338. if (ytwp.isWatchPage) {
  339. ytwp.event.initStyle();
  340. ytwp.event.initScroller();
  341. ytwp.initialized = true;
  342. ytwp.pageReady = false;
  343. }
  344. }
  345. ytwp.event.onWatchInit();
  346. ytwp.event.html5PlayerFix();
  347. },
  348. initScroller: function() {
  349. // Register listener & Call it now.
  350. unsafeWindow.addEventListener('scroll', ytwp.event.onScroll, false);
  351. unsafeWindow.addEventListener('resize', ytwp.event.onScroll, false);
  352. ytwp.event.onScroll();
  353. },
  354. onScroll: function() {
  355. var viewportHeight = document.documentElement.clientHeight;
  356.  
  357. // topOfPageClassId
  358. if (unsafeWindow.scrollY == 0) {
  359. jQuery.addClass(document.body, topOfPageClassId);
  360. } else {
  361. jQuery.removeClass(document.body, topOfPageClassId);
  362. }
  363.  
  364. // viewingVideoClassId
  365. if (unsafeWindow.scrollY <= viewportHeight) {
  366. jQuery.addClass(document.body, viewingVideoClassId);
  367. } else {
  368. jQuery.removeClass(document.body, viewingVideoClassId);
  369. }
  370. },
  371. initStyle: function() {
  372. ytwp.log('initStyle');
  373. ytwp.style = new JSStyleSheet(scriptStyleId);
  374. ytwp.event.buildStylesheet();
  375. ytwp.style.injectIntoHeader();
  376. },
  377. buildStylesheet: function() {
  378. ytwp.log('buildStylesheet');
  379. //--- Video Player
  380.  
  381. //
  382. var d;
  383. d = buildVenderPropertyDict(transitionProperties, 'left 0s linear, padding-left 0s linear');
  384. d['padding'] = '0 !important';
  385. d['margin'] = '0 !important';
  386. ytwp.style.appendRule([
  387. scriptBodyClassSelector + ' #player',
  388. scriptBodyClassSelector + '.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible #player',
  389. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player',
  390. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player-legacy',
  391. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #watch7-main-container',
  392. ], d);
  393. //
  394. d = buildVenderPropertyDict(transitionProperties, 'width 0s linear, left 0s linear');
  395.  
  396. // Bugfix for Firefox
  397. // Parts of the header (search box) are hidden under the player.
  398. // Firefox doesn't seem to be using the fixed header+guide yet.
  399. d['float'] = 'initial';
  400.  
  401. ytwp.style.appendRule(scriptBodyClassSelector + ' #player-api', d);
  402.  
  403. // Theatre mode
  404. ytwp.style.appendRule(scriptBodyClassSelector + ' .watch-stage-mode #player .player-api', {
  405. 'left': 'initial',
  406. 'margin-left': 'initial',
  407. });
  408.  
  409. // !important is mainly for simplicity, but is needed to override the !important styling when the Guide is open due to:
  410. // .sidebar-collapsed #watch7-video, .sidebar-collapsed #watch7-main, .sidebar-collapsed .watch7-playlist { width: 945px!important; }
  411. // Also, Youtube Center resizes #player at element level.
  412. ytwp.style.appendRule(
  413. [
  414. scriptBodyClassSelector + ' #player',
  415. scriptBodyClassSelector + ' #movie_player',
  416. scriptBodyClassSelector + ' #player-mole-container',
  417. scriptBodyClassSelector + ' .html5-video-container',
  418. scriptBodyClassSelector + ' .html5-main-video',
  419. ],
  420. {
  421. 'width': '100% !important',
  422. 'min-width': '100% !important',
  423. 'max-width': '100% !important',
  424. 'height': '100% !important',
  425. 'min-height': '100% !important',
  426. 'max-height': '100% !important',
  427. }
  428. );
  429.  
  430. ytwp.style.appendRule(
  431. [
  432. scriptBodyClassSelector + ' #player',
  433. scriptBodyClassSelector + ' .html5-main-video',
  434. ],
  435. {
  436. 'top': '0 !important',
  437. 'right': '0 !important',
  438. 'bottom': '0 !important',
  439. 'left': '0 !important',
  440. }
  441. );
  442. // Resize #player-unavailable, #player-api
  443. // Using min/max width/height will keep
  444. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-width', 'width', '100% !important');
  445. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height', 'height', '100% !important');
  446.  
  447. //--- Move Video Player
  448. ytwp.style.appendRule(scriptBodyClassSelector + ' #player', {
  449. 'position': 'absolute',
  450. // Already top:0; left: 0;
  451. });
  452. ytwp.style.appendRule(scriptBodyClassSelector, { // body
  453. 'margin-top': '100vh',
  454. });
  455.  
  456.  
  457. //--- Sidebar
  458. // Remove the transition delay as you can see it moving on page load.
  459. d = buildVenderPropertyDict(transitionProperties, 'margin-top 0s linear, padding-top 0s linear');
  460. d['margin-top'] = '0 !important';
  461. d['top'] = '0 !important';
  462. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-sidebar', d);
  463.  
  464. ytwp.style.appendRule(scriptBodyClassSelector + '.cardified-page #watch7-sidebar-contents', 'padding-top', '0');
  465.  
  466. //--- Absolutely position the fixed header.
  467. // Masthead
  468. d = buildVenderPropertyDict(transitionProperties, 'top 0s linear !important');
  469. ytwp.style.appendRule(scriptBodyClassSelector + '.hide-header-transition #masthead-positioner', d);
  470. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #masthead-positioner', {
  471. 'position': 'absolute',
  472. 'top': '100% !important'
  473. });
  474.  
  475. // Guide
  476. // When watching the video, we need to line it up with the masthead.
  477. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #appbar-guide-menu', {
  478. 'display': 'initial',
  479. 'position': 'absolute',
  480. 'top': '100% !important' // Masthead height
  481. });
  482. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #page.watch #guide', {
  483. 'display': 'initial',
  484. 'margin': '0',
  485. 'position': 'initial'
  486. });
  487.  
  488. //---
  489. // Hide Scrollbars
  490. ytwp.style.appendRule(scriptBodyClassSelector + '.' + topOfPageClassId, 'overflow-x', 'hidden');
  491.  
  492.  
  493. //--- Fix Other Possible Style Issues
  494. ytwp.style.appendRule(scriptBodyClassSelector + ' #placeholder-player', 'display', 'none');
  495. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch-sidebar-spacer', 'display', 'none');
  496. ytwp.style.appendRule(scriptBodyClassSelector + ' .skip-nav', 'display', 'none');
  497.  
  498. //--- Whitespace Leftover From Moving The Video
  499. ytwp.style.appendRule(scriptBodyClassSelector + ' #page.watch', 'padding-top', '0');
  500. ytwp.style.appendRule(scriptBodyClassSelector + ' .player-branded-banner', 'height', '0');
  501.  
  502. //--- Playlist Bar
  503. ytwp.style.appendRule([
  504. scriptBodyClassSelector + ' #placeholder-playlist',
  505. scriptBodyClassSelector + ' #player .player-height#watch-appbar-playlist',
  506. ], 'height', '490px !important');
  507. d = buildVenderPropertyDict(transitionProperties, 'transform 0s linear');
  508. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch-appbar-playlist', d);
  509. d = buildVenderPropertyDict(transformProperties, 'translateY(0px)');
  510. d['margin-left'] = '0';
  511. d['top'] = 'calc(100vh + 60px)';
  512. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height#watch-appbar-playlist', d);
  513. ytwp.style.appendRule(scriptBodyClassSelector + ' .playlist-videos-list', 'height', '430px');
  514. },
  515. onWatchInit: function() {
  516. ytwp.log('onWatchInit');
  517. if (!ytwp.initialized) return;
  518. if (ytwp.pageReady) return;
  519.  
  520. ytwp.event.addBodyClass();
  521. ytwp.pageReady = true;
  522. },
  523. onDispose: function() {
  524. ytwp.log('onDispose');
  525. ytwp.initialized = false;
  526. ytwp.pageReady = false;
  527. ytwp.isWatchPage = false;
  528. ytwp.ytapp = null;
  529. },
  530. addBodyClass: function() {
  531. // Insert CSS Into the body so people can style around the effects of this script.
  532. jQuery.addClass(document.body, scriptBodyClassId);
  533. ytwp.log('Applied ' + scriptBodyClassSelector);
  534. },
  535. html5PlayerFix: function() {
  536. ytwp.log('html5PlayerFix');
  537.  
  538. // https://github.com/YePpHa/YouTubeCenter/issues/1083
  539. if (!uw.ytcenter
  540. && (!ytwp.ytapp)
  541. && (uw.ytplayer && uw.ytplayer.config)
  542. && (uw.yt && uw.yt.player && uw.yt.player.Application && uw.yt.player.Application.create)
  543. ) {
  544. ytwp.ytapp = Html5PlayerFix.getPlayerInstance();
  545. }
  546.  
  547. Html5PlayerFix.update();
  548. Html5PlayerFix.autohideControls();
  549. },
  550.  
  551. };
  552.  
  553.  
  554. ytwp.pubsubListeners = {
  555. 'init': function() { // Not always called
  556. ytwp.event.init();
  557. },
  558. 'init-watch': function() { // Not always called
  559. ytwp.event.init();
  560. },
  561. 'player-added': function() { // Not always called
  562. // Usually called after init-watch, however this is called before init when going from channel -> watch page.
  563. // The init event is when the body element resets all it's classes.
  564. ytwp.event.init();
  565. },
  566. // 'player-resize': function() {},
  567. // 'player-playback-start': function() {},
  568. 'appbar-guide-delay-load': function() {
  569. // Listen to a later event that is always called in case the others are missed.
  570. ytwp.event.init();
  571.  
  572. // Channel -> /watch
  573. if (ytwp.util.isWatchUrl())
  574. ytwp.event.addBodyClass();
  575. },
  576. // 'dispose-watch': function() {},
  577. 'dispose': function() {
  578. ytwp.event.onDispose();
  579. }
  580. };
  581.  
  582. ytwp.registerYoutubeListeners = function() {
  583. ytwp.registerYoutubePubSubListeners();
  584. };
  585.  
  586. ytwp.registerYoutubePubSubListeners = function() {
  587. // Subscribe
  588. for (var eventName in ytwp.pubsubListeners) {
  589. var eventListener = ytwp.pubsubListeners[eventName];
  590. uw.yt.pubsub.instance_.subscribe(eventName, eventListener);
  591. }
  592. };
  593.  
  594. ytwp.main = function() {
  595. try {
  596. ytwp.registerYoutubeListeners();
  597. } catch(e) {
  598. ytwp.error("Could not hook yt.pubsub", e);
  599. setTimeout(ytwp.main, 1000);
  600. }
  601. ytwp.event.init();
  602. };
  603.  
  604. ytwp.main();
  605. })(typeof unsafeWindow !== 'undefined' ? unsafeWindow : window);