Resize YT To Window Size

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

目前為 2015-05-06 提交的版本,檢視 最新版本

  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 63
  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.  
  168. //--- YTWP
  169. var ytwp = uw.ytwp = {
  170. scriptShortName: scriptShortName, // YT Window Player
  171. log_: function(logger, args) { logger.apply(console, ['[' + this.scriptShortName + '] '].concat(Array.prototype.slice.call(args))); return 1; },
  172. log: function() { return this.log_(console.log, arguments); },
  173. error: function() { return this.log_(console.error, arguments); },
  174.  
  175. initialized: false,
  176. pageReady: false,
  177. watchPage: false,
  178. };
  179.  
  180. ytwp.util = {
  181. isWatchUrl: function (url) {
  182. if (!url)
  183. url = uw.location.href;
  184. return url.match(/https?:\/\/(www\.)?youtube.com\/watch\?/);
  185. }
  186. };
  187.  
  188. var Html5PlayerFix = {
  189. YTRect: null,
  190. YTApplication: null,
  191. playerInstances: null,
  192. moviePlayerElement: null,
  193. };
  194. Html5PlayerFix.getPlayerRect = function() {
  195. return new Html5PlayerFix.YTRect(Html5PlayerFix.moviePlayerElement.clientWidth, Html5PlayerFix.moviePlayerElement.clientHeight);
  196. };
  197. Html5PlayerFix.getApplicationClass = function() {
  198. if (Html5PlayerFix.YTApplication === null) {
  199. var testEl = document.createElement('div');
  200. var testAppInstance = uw.yt.player.Application.create(testEl, {});
  201. Html5PlayerFix.YTApplication = testAppInstance.constructor;
  202.  
  203. // Cleanup testAppInstance
  204. var playerInstances = Html5PlayerFix.getPlayerInstances();
  205.  
  206. var testAppInstanceKey = null;
  207. Object.keys(playerInstances).forEach(function(key) {
  208. if (playerInstances[key] === testAppInstance) {
  209. testAppInstanceKey = key;
  210. }
  211. });
  212. testAppInstance.dispose();
  213. delete playerInstances[testAppInstanceKey];
  214. }
  215.  
  216.  
  217. return Html5PlayerFix.YTApplication;
  218. };
  219. Html5PlayerFix.getPlayerInstances = function() {
  220. if (Html5PlayerFix.playerInstances === null) {
  221. var YTApplication = Html5PlayerFix.getApplicationClass();
  222. if (YTApplication === null)
  223. return null;
  224.  
  225. // Use yt.player.Application.create to find the playerInstancesKey.
  226. // 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;}}
  227. 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\]\)/;
  228. var fnString = yt.player.Application.create.toString();
  229. var m = appCreateRegex.exec(fnString);
  230. if (m) {
  231. var playerInstancesKey = m[4];
  232. Html5PlayerFix.playerInstances = YTApplication[playerInstancesKey];
  233. } else {
  234. ytwp.error('Error trying to find playerInstancesKey.', fnString);
  235. }
  236. Html5PlayerFix.playerInstances = YTApplication.j;
  237. }
  238.  
  239. return Html5PlayerFix.playerInstances;
  240. };
  241. Html5PlayerFix.getPlayerInstance = function() {
  242. if (!ytwp.ytapp) {
  243. var playerInstances = Html5PlayerFix.getPlayerInstances();
  244. ytwp.log('playerInstances', playerInstances);
  245. var appInstance = null;
  246. var appInstanceKey = null;
  247. Object.keys(playerInstances).forEach(function(key) {
  248. appInstanceKey = key;
  249. appInstance = playerInstances[key];
  250. });
  251. ytwp.ytapp = appInstance;
  252. }
  253. return ytwp.ytapp;
  254. };
  255. Html5PlayerFix.autohideControls = function() {
  256. var moviePlayerElement = document.getElementById('movie_player');
  257. if (!moviePlayerElement) return;
  258. // ytwp.log(moviePlayerElement.classList);
  259. 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');
  260. jQuery.addClass(moviePlayerElement, 'autominimize-progress-bar autohide-controls hide-controls-when-cued');
  261. // ytwp.log(moviePlayerElement.classList);
  262. };
  263. Html5PlayerFix.update = function() {
  264. if (!Html5PlayerFix.playerInstances)
  265. return;
  266. for (var key in Html5PlayerFix.playerInstances) {
  267. var playerInstance = Html5PlayerFix.playerInstances[key];
  268. Html5PlayerFix.updatePlayerInstance(playerInstance);
  269. }
  270. };
  271. Html5PlayerFix.updatePlayerInstance = function(app) {
  272. if (!app) {
  273. return;
  274. }
  275.  
  276. var moviePlayerElement = document.getElementById('movie_player');
  277. var moviePlayer = null;
  278. var moviePlayerKey = null;
  279.  
  280. // 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}
  281. var clientRectFnRegex1 = /^(function \(a\)\{var b=this\.([a-zA-Z_$][\w_$]*)\.([a-zA-Z_$][\w_$]*)\(\)).*("detailpage"!=).*(return c})$/;
  282. // 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)}
  283. var clientRectFnRegex2 = /^(function \()(.|\n)*(return new ([a-zA-Z_$][\w_$]*)\(this\.element\.clientWidth,this\.element\.clientHeight\)})$/;
  284. var clientRectFn = null;
  285. var clientRectFnKey = null;
  286.  
  287. var fnAlreadyReplacedCount = 0;
  288.  
  289. Object.keys(app).forEach(function(key1) {
  290. var val1 = app[key1];//console.log(key1, val1);
  291. if (typeof val1 === 'object' && val1 !== null && val1.element === moviePlayerElement) {
  292. moviePlayer = val1;
  293. moviePlayerKey = key1;
  294.  
  295. Object.keys(moviePlayer.constructor.prototype).forEach(function(key2) {
  296. var val2 = moviePlayer[key2];//console.log(key1, key2, val2);
  297. if (typeof val2 === 'function') {
  298. var fnString = val2.toString();
  299. // console.log(fnString);
  300. if (clientRectFn === null && (clientRectFnRegex1.test(fnString) || clientRectFnRegex2.test(fnString))) {
  301. clientRectFn = val2;
  302. clientRectFnKey = key2;
  303. } else if (val2 === Html5PlayerFix.getPlayerRect) {
  304. fnAlreadyReplacedCount += 1;
  305. } else {
  306. // console.log(key1, key2, val2, '[Not Used]');
  307. }
  308. }
  309. });
  310. }
  311. });
  312.  
  313. if (fnAlreadyReplacedCount > 0) {
  314. return;
  315. }
  316.  
  317. if (moviePlayer === null || clientRectFn === null) {
  318. console.log('[ytwp] ', '[Error]', 'HTML5 Player has changed or there\'s multiple playerInstances and this one has been destroyed.');
  319. console.log('moviePlayer', moviePlayerKey, moviePlayer);
  320. console.log('clientRectFn', clientRectFnKey, clientRectFn);
  321. console.log('fnAlreadyReplacedCount', fnAlreadyReplacedCount);
  322. return;
  323. }
  324. Html5PlayerFix.moviePlayerElement = moviePlayerElement;
  325. Html5PlayerFix.YTRect = moviePlayer[clientRectFnKey].call(moviePlayer).constructor;
  326.  
  327. moviePlayer[clientRectFnKey] = Html5PlayerFix.getPlayerRect;
  328. };
  329. ytwp.Html5PlayerFix = Html5PlayerFix;
  330.  
  331. ytwp.event = {
  332. init: function() {
  333. ytwp.log('init');
  334. if (!ytwp.initialized) {
  335. ytwp.isWatchPage = ytwp.util.isWatchUrl();
  336. if (ytwp.isWatchPage) {
  337. ytwp.event.initStyle();
  338. ytwp.event.initScroller();
  339. ytwp.initialized = true;
  340. ytwp.pageReady = false;
  341. }
  342. }
  343. ytwp.event.onWatchInit();
  344. ytwp.event.html5PlayerFix();
  345. },
  346. initScroller: function() {
  347. // Register listener & Call it now.
  348. unsafeWindow.addEventListener('scroll', ytwp.event.onScroll, false);
  349. unsafeWindow.addEventListener('resize', ytwp.event.onScroll, false);
  350. ytwp.event.onScroll();
  351. },
  352. onScroll: function() {
  353. var viewportHeight = document.documentElement.clientHeight;
  354.  
  355. // topOfPageClassId
  356. if (unsafeWindow.scrollY == 0) {
  357. jQuery.addClass(document.body, topOfPageClassId);
  358. } else {
  359. jQuery.removeClass(document.body, topOfPageClassId);
  360. }
  361.  
  362. // viewingVideoClassId
  363. if (unsafeWindow.scrollY <= viewportHeight) {
  364. jQuery.addClass(document.body, viewingVideoClassId);
  365. } else {
  366. jQuery.removeClass(document.body, viewingVideoClassId);
  367. }
  368. },
  369. initStyle: function() {
  370. ytwp.log('initStyle');
  371. ytwp.style = new JSStyleSheet(scriptStyleId);
  372. ytwp.event.buildStylesheet();
  373. ytwp.style.injectIntoHeader();
  374. },
  375. buildStylesheet: function() {
  376. ytwp.log('buildStylesheet');
  377. //--- Video Player
  378.  
  379. //
  380. var d;
  381. d = buildVenderPropertyDict(transitionProperties, 'left 0s linear, padding-left 0s linear');
  382. d['padding'] = '0 !important';
  383. d['margin'] = '0 !important';
  384. ytwp.style.appendRule([
  385. scriptBodyClassSelector + ' #player',
  386. scriptBodyClassSelector + '.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible #player',
  387. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player',
  388. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player-legacy',
  389. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #watch7-main-container',
  390. ], d);
  391. //
  392. d = buildVenderPropertyDict(transitionProperties, 'width 0s linear, left 0s linear');
  393.  
  394. // Bugfix for Firefox
  395. // Parts of the header (search box) are hidden under the player.
  396. // Firefox doesn't seem to be using the fixed header+guide yet.
  397. d['float'] = 'initial';
  398.  
  399. ytwp.style.appendRule(scriptBodyClassSelector + ' #player-api', d);
  400.  
  401. // Theatre mode
  402. ytwp.style.appendRule(scriptBodyClassSelector + ' .watch-stage-mode #player .player-api', {
  403. 'left': 'initial',
  404. 'margin-left': 'initial',
  405. });
  406.  
  407. // !important is mainly for simplicity, but is needed to override the !important styling when the Guide is open due to:
  408. // .sidebar-collapsed #watch7-video, .sidebar-collapsed #watch7-main, .sidebar-collapsed .watch7-playlist { width: 945px!important; }
  409. // Also, Youtube Center resizes #player at element level.
  410. ytwp.style.appendRule(
  411. [
  412. scriptBodyClassSelector + ' #player',
  413. scriptBodyClassSelector + ' #movie_player',
  414. scriptBodyClassSelector + ' #player-mole-container',
  415. scriptBodyClassSelector + ' .html5-video-container',
  416. scriptBodyClassSelector + ' .html5-main-video',
  417. ],
  418. {
  419. 'width': '100% !important',
  420. 'min-width': '100% !important',
  421. 'max-width': '100% !important',
  422. 'height': '100% !important',
  423. 'min-height': '100% !important',
  424. 'max-height': '100% !important',
  425. }
  426. );
  427.  
  428. ytwp.style.appendRule(
  429. [
  430. scriptBodyClassSelector + ' #player',
  431. scriptBodyClassSelector + ' .html5-main-video',
  432. ],
  433. {
  434. 'top': '0 !important',
  435. 'right': '0 !important',
  436. 'bottom': '0 !important',
  437. 'left': '0 !important',
  438. }
  439. );
  440. // Resize #player-unavailable, #player-api
  441. // Using min/max width/height will keep
  442. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-width', 'width', '100% !important');
  443. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height', 'height', '100% !important');
  444.  
  445. //--- Move Video Player
  446. ytwp.style.appendRule(scriptBodyClassSelector + ' #player', {
  447. 'position': 'absolute',
  448. // Already top:0; left: 0;
  449. });
  450. ytwp.style.appendRule(scriptBodyClassSelector, { // body
  451. 'margin-top': '100vh',
  452. });
  453.  
  454.  
  455. //--- Sidebar
  456. // Remove the transition delay as you can see it moving on page load.
  457. d = buildVenderPropertyDict(transitionProperties, 'margin-top 0s linear, padding-top 0s linear');
  458. d['margin-top'] = '0 !important';
  459. d['top'] = '0 !important';
  460. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-sidebar', d);
  461.  
  462. ytwp.style.appendRule(scriptBodyClassSelector + '.cardified-page #watch7-sidebar-contents', 'padding-top', '0');
  463.  
  464. //--- Absolutely position the fixed header.
  465. // Masthead
  466. d = buildVenderPropertyDict(transitionProperties, 'top 0s linear');
  467. ytwp.style.appendRule(scriptBodyClassSelector + '.hide-header-transition #masthead-positioner', d);
  468. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #masthead-positioner', {
  469. 'position': 'absolute',
  470. 'top': '100% !important'
  471. });
  472.  
  473. // Guide
  474. // When watching the video, we need to line it up with the masthead.
  475. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #appbar-guide-menu', {
  476. 'display': 'initial',
  477. 'position': 'absolute',
  478. 'top': '100% !important' // Masthead height
  479. });
  480. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #page.watch #guide', {
  481. 'display': 'initial',
  482. 'margin': '0',
  483. 'position': 'initial'
  484. });
  485.  
  486. //---
  487. // Hide Scrollbars
  488. ytwp.style.appendRule(scriptBodyClassSelector + '.' + topOfPageClassId, 'overflow-x', 'hidden');
  489.  
  490.  
  491. //--- Fix Other Possible Style Issues
  492. ytwp.style.appendRule(scriptBodyClassSelector + ' #placeholder-player', 'display', 'none');
  493. ytwp.style.appendRule(scriptBodyClassSelector + ' .skip-nav', 'display', 'none');
  494.  
  495. //--- Whitespace Leftover From Moving The Video
  496. ytwp.style.appendRule(scriptBodyClassSelector + ' #page.watch', 'padding-top', '0');
  497. ytwp.style.appendRule(scriptBodyClassSelector + ' .player-branded-banner', 'height', '0');
  498.  
  499. //--- Playlist Bar
  500. //ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-playlist-tray-container', "margin", "-15px -10px 20px -10px");
  501. ytwp.style.appendRule(scriptBodyClassSelector + ' .watch7-playlist-bar-left', 'width', '640px !important'); // Same width as .watch-content
  502. ytwp.style.appendRule([
  503. scriptBodyClassSelector + ' .playlist',
  504. scriptBodyClassSelector + ' .playlist .watch7-playlist-bar',
  505. ], 'max-width', '1040px'); // Same width as .watch-content (640px) + .watch-sidebar (300-400px).
  506. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-playlist-tray-container', {
  507. "margin-top": "-15px",
  508. "height": "287px !important", // 65 (playlist tile) * 4 + 27 (trim on bottom)
  509. "margin-bottom": "15px"
  510. });
  511. ytwp.style.appendRule([
  512. scriptBodyClassSelector + '.cardified-page #watch7-playlist-tray-container + #watch7-sidebar-contents', // Pre Oct 26
  513. scriptBodyClassSelector + '.cardified-page #watch-appbar-playlist + #watch7-sidebar-contents', // Post Oct 26
  514. ], 'padding-top', '15px');
  515.  
  516. // YT Center
  517. ytwp.style.appendRule(scriptBodyClassSelector + ' #player', 'margin-bottom', '0 !important');
  518. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-playlist-tray-container', {
  519. 'left': 'initial !important',
  520. 'width': 'initial !important'
  521. });
  522. ytwp.style.appendRule(scriptBodyClassSelector + ' .watch7-playlist-bar-right', 'width', '363px !important');
  523. },
  524. onWatchInit: function() {
  525. ytwp.log('onWatchInit');
  526. if (!ytwp.initialized) return;
  527. if (ytwp.pageReady) return;
  528.  
  529. ytwp.event.addBodyClass();
  530. ytwp.pageReady = true;
  531. },
  532. onDispose: function() {
  533. ytwp.log('onDispose');
  534. ytwp.initialized = false;
  535. ytwp.pageReady = false;
  536. ytwp.isWatchPage = false;
  537. ytwp.ytapp = null;
  538. },
  539. addBodyClass: function() {
  540. // Insert CSS Into the body so people can style around the effects of this script.
  541. jQuery.addClass(document.body, scriptBodyClassId);
  542. ytwp.log('Applied ' + scriptBodyClassSelector);
  543. },
  544. html5PlayerFix: function() {
  545. ytwp.log('html5PlayerFix');
  546.  
  547. // https://github.com/YePpHa/YouTubeCenter/issues/1083
  548. if (!uw.ytcenter
  549. && (!ytwp.ytapp)
  550. && (uw.ytplayer && uw.ytplayer.config)
  551. && (uw.yt && uw.yt.player && uw.yt.player.Application && uw.yt.player.Application.create)
  552. ) {
  553. ytwp.ytapp = Html5PlayerFix.getPlayerInstance();
  554. }
  555.  
  556. Html5PlayerFix.update();
  557. Html5PlayerFix.autohideControls();
  558. },
  559.  
  560. };
  561.  
  562.  
  563. ytwp.pubsubListeners = {
  564. 'init': function() { // Not always called
  565. ytwp.event.init();
  566. },
  567. 'init-watch': function() { // Not always called
  568. ytwp.event.init();
  569. },
  570. 'player-added': function() { // Not always called
  571. // Usually called after init-watch, however this is called before init when going from channel -> watch page.
  572. // The init event is when the body element resets all it's classes.
  573. ytwp.event.init();
  574. },
  575. // 'player-resize': function() {},
  576. // 'player-playback-start': function() {},
  577. 'appbar-guide-delay-load': function() {
  578. // Listen to a later event that is always called in case the others are missed.
  579. ytwp.event.init();
  580.  
  581. // Channel -> /watch
  582. if (ytwp.util.isWatchUrl())
  583. ytwp.event.addBodyClass();
  584. },
  585. // 'dispose-watch': function() {},
  586. 'dispose': function() {
  587. ytwp.event.onDispose();
  588. }
  589. };
  590.  
  591. ytwp.registerYoutubeListeners = function() {
  592. ytwp.registerYoutubePubSubListeners();
  593. };
  594.  
  595. ytwp.registerYoutubePubSubListeners = function() {
  596. // Subscribe
  597. for (var eventName in ytwp.pubsubListeners) {
  598. var eventListener = ytwp.pubsubListeners[eventName];
  599. uw.yt.pubsub.instance_.subscribe(eventName, eventListener);
  600. }
  601. };
  602.  
  603. ytwp.main = function() {
  604. try {
  605. ytwp.registerYoutubeListeners();
  606. } catch(e) {
  607. ytwp.error("Could not hook yt.pubsub", e);
  608. setTimeout(ytwp.main, 1000);
  609. }
  610. ytwp.event.init();
  611. };
  612.  
  613. ytwp.main();
  614. })(typeof unsafeWindow !== 'undefined' ? unsafeWindow : window);