Resize YT To Window Size

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

目前为 2015-12-24 提交的版本。查看 最新版本

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