Resize YT To Window Size

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

当前为 2016-02-16 提交的版本,查看 最新版本

  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 79
  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://gf.qytechs.cn/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;
  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. var moviePlayerElement = ytwp.html5.moviePlayerElement || document.getElementById('movie_player');
  199. return new ytwp.html5.YTRect(moviePlayerElement.clientWidth, moviePlayerElement.clientHeight);
  200. };
  201. ytwp.html5.getApplicationClass = function() {
  202. if (ytwp.html5.YTApplication === null) {
  203. var testEl = document.createElement('div');
  204. var testAppInstance = uw.yt.player.Application.create(testEl, {});
  205. // var testAppInstance = uw.yt.player.Application.create("player-api", uw.ytplayer.config);
  206. ytwp.html5.YTApplication = testAppInstance.constructor;
  207.  
  208. // Cleanup testAppInstance
  209. var playerInstances = ytwp.html5.getPlayerInstances();
  210.  
  211. var testAppInstanceKey = null;
  212. Object.keys(playerInstances).forEach(function(key) {
  213. if (playerInstances[key] === testAppInstance) {
  214. testAppInstanceKey = key;
  215. }
  216. });
  217. testAppInstance.dispose();
  218. delete playerInstances[testAppInstanceKey];
  219. }
  220. return ytwp.html5.YTApplication;
  221. };
  222. ytwp.html5.getPlayerInstances = function() {
  223. if (ytwp.html5.playerInstances === null) {
  224. var YTApplication = ytwp.html5.getApplicationClass();
  225. if (YTApplication === null)
  226. return null;
  227.  
  228. // Use yt.player.Application.create to find the playerInstancesKey.
  229. // 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;}}
  230. 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\]\)/;
  231. var fnString = yt.player.Application.create.toString();
  232. var m = appCreateRegex.exec(fnString);
  233. if (m) {
  234. var playerInstancesKey = m[4];
  235. ytwp.html5.playerInstances = YTApplication[playerInstancesKey];
  236. } else {
  237. ytwp.error('Error trying to find playerInstancesKey.', fnString);
  238. }
  239. ytwp.html5.playerInstances = YTApplication[playerInstancesKey];
  240. }
  241.  
  242. return ytwp.html5.playerInstances;
  243. };
  244. ytwp.html5.getPlayerInstance = function() {
  245. if (!ytwp.html5.app) {
  246. var playerInstances = ytwp.html5.getPlayerInstances();
  247. ytwp.log('playerInstances', playerInstances);
  248. var appInstance = null;
  249. var appInstanceKey = null;
  250. Object.keys(playerInstances).forEach(function(key) {
  251. appInstanceKey = key;
  252. appInstance = playerInstances[key];
  253. });
  254. ytwp.html5.app = appInstance;
  255. }
  256. return ytwp.html5.app;
  257. };
  258. ytwp.html5.autohideControls = function() {
  259. var moviePlayerElement = document.getElementById('movie_player');
  260. if (!moviePlayerElement) return;
  261. // ytwp.log(moviePlayerElement.classList);
  262. 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');
  263. jQuery.addClass(moviePlayerElement, 'autominimize-progress-bar autohide-controls hide-controls-when-cued');
  264. // ytwp.log(moviePlayerElement.classList);
  265. };
  266. ytwp.html5.update = function() {
  267. if (!ytwp.html5.playerInstances)
  268. return;
  269. for (var key in ytwp.html5.playerInstances) {
  270. var playerInstance = ytwp.html5.playerInstances[key];
  271. ytwp.html5.updatePlayerInstance(playerInstance);
  272. }
  273. };
  274. ytwp.html5.replaceClientRect = function(app, moviePlayerKey, clientRectFnKey) {
  275. var moviePlayer = app[moviePlayerKey];
  276. ytwp.html5.moviePlayerElement = moviePlayer.element;
  277. ytwp.html5.YTRect = moviePlayer[clientRectFnKey].call(moviePlayer).constructor;
  278. moviePlayer[clientRectFnKey] = ytwp.html5.getPlayerRect;
  279. };
  280. ytwp.html5.setRectFn = function(app, moviePlayerKey, clientRectFnKey) {
  281. ytwp.html5.moviePlayerElement = document.getElementById('movie_player');
  282. var moviePlayer = app[moviePlayerKey];
  283. ytwp.html5.YTRect = moviePlayer[clientRectFnKey].call(moviePlayer).constructor;
  284. moviePlayer.constructor.prototype[clientRectFnKey] = ytwp.html5.getPlayerRect;
  285. };
  286. ytwp.html5.updatePlayerInstance = function(app) {
  287. if (!app) {
  288. return;
  289. }
  290.  
  291. var moviePlayerElement = document.getElementById('movie_player');
  292. var moviePlayer = null;
  293. var moviePlayerKey = null;
  294.  
  295. // function (a,b){return this.isDisposed()?!1:this.R.P.apply(this.R,arguments)}
  296. 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\)\}$/;
  297. var applyFnKey = null;
  298.  
  299.  
  300. // 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}
  301. // 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}
  302. var clientRectFnRegex1 = /^(function \(a\)\{var b=this\.([a-zA-Z_$][\w_$]*)\.([a-zA-Z_$][\w_$]*)\(\)).*(\|\|\(c\.height\+=30\);return c})$/;
  303. // 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)}
  304. var clientRectFnRegex2 = /^(function \()(.|\n)*(return new ([a-zA-Z_$][\w_$]*)\(this\.element\.clientWidth,this\.element\.clientHeight\)})$/;
  305. var clientRectFn = null;
  306. var clientRectFnKey = null;
  307.  
  308. var fnAlreadyReplacedCount = 0;
  309.  
  310. for (var key1 in app) {
  311. var val1 = app[key1];//console.log(key1, val1);
  312. if (typeof val1 === 'object' && val1 !== null && val1.element === moviePlayerElement) {
  313. moviePlayer = val1;
  314. moviePlayerKey = key1;
  315.  
  316. for (var key2 in moviePlayer) {
  317. var val2 = moviePlayer[key2];//console.log(key1, key2, val2);
  318. if (typeof val2 === 'function') {
  319. var fnString = val2.toString();
  320. // console.log(fnString);
  321. if (clientRectFn === null && (clientRectFnRegex1.test(fnString) || clientRectFnRegex2.test(fnString))) {
  322. clientRectFn = val2;
  323. clientRectFnKey = key2;
  324. } else if (val2 === ytwp.html5.getPlayerRect) {
  325. fnAlreadyReplacedCount += 1;
  326. clientRectFn = val2;
  327. clientRectFnKey = key2;
  328. } else {
  329. // console.log(key1, key2, val2, '[Not Used]');
  330. }
  331. }
  332. }
  333. } else if (typeof val1 === 'function') {
  334. var fnString = val1.toString();
  335. if (applyFnRegex.test(fnString)) {
  336. applyFnKey = key1;
  337. }
  338. }
  339. }
  340.  
  341. if (fnAlreadyReplacedCount > 0) {
  342. // return;
  343. }
  344.  
  345. if (moviePlayer === null || clientRectFn === null) {
  346. console.log('[ytwp] ', '[Error]', 'HTML5 Player has changed or there\'s multiple playerInstances and this one has been destroyed.');
  347. console.log('moviePlayer', moviePlayerKey, moviePlayer);
  348. console.log('clientRectFn', clientRectFnKey, clientRectFn);
  349. console.log('fnAlreadyReplacedCount', fnAlreadyReplacedCount);
  350. if (moviePlayer === null) {
  351. console.log('Debugging: moviePlayer');
  352. var table = [];
  353. Object.keys(app).forEach(function(key1) {
  354. var val1 = app[key1];
  355. table.push({
  356. key: key1,
  357. element: typeof val1 === 'object' && val1 !== null && val1.element === moviePlayerElement,
  358. val: val1,
  359. });
  360. });
  361. console.table(table);
  362. }
  363. if (moviePlayer != null) {
  364. console.log('Debugging: clientRectFn');
  365. var table = [];
  366. for (var key2 in moviePlayer) {
  367. var val2 = moviePlayer[key2];
  368. table.push({
  369. key: key2,
  370. returns: moviePlayer[key2] && moviePlayer[key2].toString().indexOf('return'),
  371. src: moviePlayer[key2] && moviePlayer[key2].toString(),
  372. });
  373. }
  374. console.table(table);
  375. }
  376. return;
  377. }
  378. ytwp.html5.setRectFn(app, moviePlayerKey, clientRectFnKey);
  379.  
  380. if (applyFnKey) {
  381. app[applyFnKey]('resize', ytwp.html5.getPlayerRect());
  382. } else {
  383. ytwp.log('applyFn not found');
  384. app.ma.S('resize', ytwp.html5.getPlayerRect()); // tempfix
  385. }
  386. };
  387.  
  388.  
  389.  
  390. ytwp.event = {
  391. init: function() {
  392. ytwp.log('init');
  393. if (!ytwp.initialized) {
  394. ytwp.isWatchPage = ytwp.util.isWatchUrl();
  395. if (ytwp.isWatchPage) {
  396. if (!document.getElementById(scriptStyleId)) {
  397. ytwp.event.initStyle();
  398. }
  399. ytwp.event.initScroller();
  400. ytwp.initialized = true;
  401. ytwp.pageReady = false;
  402. }
  403. }
  404. ytwp.event.onWatchInit();
  405. ytwp.event.html5PlayerFix();
  406. },
  407. initScroller: function() {
  408. // Register listener & Call it now.
  409. uw.addEventListener('scroll', ytwp.event.onScroll, false);
  410. uw.addEventListener('resize', ytwp.event.onScroll, false);
  411. ytwp.event.onScroll();
  412. },
  413. onScroll: function() {
  414. var viewportHeight = document.documentElement.clientHeight;
  415.  
  416. // topOfPageClassId
  417. if (uw.scrollY == 0) {
  418. jQuery.addClass(document.body, topOfPageClassId);
  419. //var player = document.getElementById('movie_player');
  420. //if (player)
  421. // player.focus();
  422. } else {
  423. jQuery.removeClass(document.body, topOfPageClassId);
  424. }
  425.  
  426. // viewingVideoClassId
  427. if (uw.scrollY <= viewportHeight) {
  428. jQuery.addClass(document.body, viewingVideoClassId);
  429. } else {
  430. jQuery.removeClass(document.body, viewingVideoClassId);
  431. }
  432. },
  433. initStyle: function() {
  434. ytwp.log('initStyle');
  435. ytwp.style = new JSStyleSheet(scriptStyleId);
  436. ytwp.event.buildStylesheet();
  437. // Duplicate stylesheet targeting data-spf-name if enabled.
  438. if (uw.spf) {
  439. var temp = scriptBodyClassSelector;
  440. scriptBodyClassSelector = 'body[data-spf-name="watch"]';
  441. ytwp.event.buildStylesheet();
  442. ytwp.style.appendRule('body[data-spf-name="watch"]:not(.ytwp-window-player) #masthead-positioner', {
  443. 'position': 'absolute',
  444. 'top': '100% !important'
  445. });
  446. }
  447. ytwp.style.injectIntoHeader();
  448. },
  449. buildStylesheet: function() {
  450. ytwp.log('buildStylesheet');
  451. //--- Video Player
  452. var d;
  453. d = buildVenderPropertyDict(transitionProperties, 'left 0s linear, padding-left 0s linear');
  454. d['padding'] = '0 !important';
  455. d['margin'] = '0 !important';
  456. ytwp.style.appendRule([
  457. scriptBodyClassSelector + ' #player',
  458. scriptBodyClassSelector + '.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible #player',
  459. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player',
  460. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player-legacy',
  461. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #watch7-main-container',
  462. ], d);
  463. //
  464. d = buildVenderPropertyDict(transitionProperties, 'width 0s linear, left 0s linear');
  465.  
  466. // Bugfix for Firefox
  467. // Parts of the header (search box) are hidden under the player.
  468. // Firefox doesn't seem to be using the fixed header+guide yet.
  469. d['float'] = 'initial';
  470.  
  471. // Skinny mode
  472. d['left'] = 0;
  473. d['margin-left'] = 0;
  474.  
  475. ytwp.style.appendRule(scriptBodyClassSelector + ' #player-api', d);
  476.  
  477. // Theatre mode
  478. ytwp.style.appendRule(scriptBodyClassSelector + ' .watch-stage-mode #player .player-api', {
  479. 'left': 'initial',
  480. 'margin-left': 'initial',
  481. });
  482. // Hide the cinema/wide mode button since it's useless.
  483. //ytwp.style.appendRule(scriptBodyClassSelector + ' #movie_player .ytp-size-button', 'display', 'none');
  484.  
  485. // !important is mainly for simplicity, but is needed to override the !important styling when the Guide is open due to:
  486. // .sidebar-collapsed #watch7-video, .sidebar-collapsed #watch7-main, .sidebar-collapsed .watch7-playlist { width: 945px!important; }
  487. // Also, Youtube Center resizes #player at element level.
  488. // Don't resize if Youtube+'s html.floater is detected.
  489. ytwp.style.appendRule(
  490. [
  491. scriptBodyClassSelector + ' #player',
  492. 'html:not(.floater) ' + scriptBodyClassSelector + ' #movie_player',
  493. scriptBodyClassSelector + ' #player-mole-container',
  494. 'html:not(.floater) ' + scriptBodyClassSelector + ' .html5-video-container',
  495. 'html:not(.floater) ' + scriptBodyClassSelector + ' .html5-main-video',
  496. ],
  497. {
  498. 'width': '100% !important',
  499. 'min-width': '100% !important',
  500. 'max-width': '100% !important',
  501. 'height': '100% !important',
  502. 'min-height': '100% !important',
  503. 'max-height': '100% !important',
  504. }
  505. );
  506.  
  507. ytwp.style.appendRule(
  508. [
  509. scriptBodyClassSelector + ' #player',
  510. scriptBodyClassSelector + ' .html5-main-video',
  511. ],
  512. {
  513. 'top': '0 !important',
  514. 'right': '0 !important',
  515. 'bottom': '0 !important',
  516. 'left': '0 !important',
  517. }
  518. );
  519. // Resize #player-unavailable, #player-api
  520. // Using min/max width/height will keep
  521. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-width', 'width', '100% !important');
  522. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height', 'height', '100% !important');
  523.  
  524. // Fix video overlays
  525. ytwp.style.appendRule([
  526. scriptBodyClassSelector + ' .html5-video-player .ad-container-single-media-element-annotations', // Ad
  527. scriptBodyClassSelector + ' .html5-video-player .ytp-upnext', // Autoplay Next Video
  528. ], 'top', '0');
  529.  
  530. //--- Move Video Player
  531. ytwp.style.appendRule(scriptBodyClassSelector + ' #player', {
  532. 'position': 'absolute',
  533. // Already top:0; left: 0;
  534. });
  535. ytwp.style.appendRule(scriptBodyClassSelector, { // body
  536. 'margin-top': '100vh',
  537. });
  538.  
  539.  
  540. //--- Sidebar
  541. // Remove the transition delay as you can see it moving on page load.
  542. d = buildVenderPropertyDict(transitionProperties, 'margin-top 0s linear, padding-top 0s linear');
  543. d['margin-top'] = '0 !important';
  544. d['top'] = '0 !important';
  545. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-sidebar', d);
  546.  
  547. ytwp.style.appendRule(scriptBodyClassSelector + '.cardified-page #watch7-sidebar-contents', 'padding-top', '0');
  548.  
  549. //--- Absolutely position the fixed header.
  550. // Masthead
  551. d = buildVenderPropertyDict(transitionProperties, 'top 0s linear !important');
  552. ytwp.style.appendRule(scriptBodyClassSelector + '.hide-header-transition #masthead-positioner', d);
  553. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #masthead-positioner', {
  554. 'position': 'absolute',
  555. 'top': '100% !important'
  556. });
  557. // Lower masthead below Youtube+'s html.floater
  558. ytwp.style.appendRule('html.floater ' + scriptBodyClassSelector + '.' + viewingVideoClassId + ' #masthead-positioner', {
  559. 'z-index': '5',
  560. });
  561.  
  562. // Guide
  563. // When watching the video, we need to line it up with the masthead.
  564. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #appbar-guide-menu', {
  565. 'display': 'initial',
  566. 'position': 'absolute',
  567. 'top': '100% !important' // Masthead height
  568. });
  569. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #page.watch #guide', {
  570. 'display': 'initial',
  571. 'margin': '0',
  572. 'position': 'initial'
  573. });
  574.  
  575. //---
  576. // Hide Scrollbars
  577. ytwp.style.appendRule(scriptBodyClassSelector + '.' + topOfPageClassId, 'overflow-x', 'hidden');
  578.  
  579.  
  580. //--- Fix Other Possible Style Issues
  581. ytwp.style.appendRule(scriptBodyClassSelector + ' #placeholder-player', 'display', 'none');
  582. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch-sidebar-spacer', 'display', 'none');
  583. ytwp.style.appendRule(scriptBodyClassSelector + ' .skip-nav', 'display', 'none');
  584.  
  585. //--- Whitespace Leftover From Moving The Video
  586. ytwp.style.appendRule(scriptBodyClassSelector + ' #page.watch', 'padding-top', '0');
  587. ytwp.style.appendRule(scriptBodyClassSelector + ' .player-branded-banner', 'height', '0');
  588.  
  589. //--- Youtube+ Compatiblity
  590. ytwp.style.appendRule(scriptBodyClassSelector + ' #body-container', 'position', 'static');
  591. ytwp.style.appendRule('.part_static_size:not(.content-snap-width-skinny-mode) ' + scriptBodyClassSelector + ' .watch-non-stage-mode #player-playlist', 'width', '1066px');
  592.  
  593. //--- Playlist Bar
  594. ytwp.style.appendRule([
  595. scriptBodyClassSelector + ' #placeholder-playlist',
  596. scriptBodyClassSelector + ' #player .player-height#watch-appbar-playlist',
  597. ], {
  598. 'height': '540px !important',
  599. 'max-height': '540px !important',
  600. });
  601.  
  602. d = buildVenderPropertyDict(transitionProperties, 'transform 0s linear');
  603. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch-appbar-playlist', d);
  604. d = buildVenderPropertyDict(transformProperties, 'translateY(0px)');
  605. d['margin-left'] = '0';
  606. d['top'] = 'calc(100vh + 60px)';
  607. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height#watch-appbar-playlist', d);
  608. ytwp.style.appendRule(scriptBodyClassSelector + ' .playlist-videos-list', {
  609. 'max-height': '470px !important',
  610. 'height': 'initial !important',
  611. });
  612. },
  613. onWatchInit: function() {
  614. ytwp.log('onWatchInit');
  615. if (!ytwp.initialized) return;
  616. if (ytwp.pageReady) return;
  617.  
  618. ytwp.event.addBodyClass();
  619. ytwp.pageReady = true;
  620. },
  621. onDispose: function() {
  622. ytwp.log('onDispose');
  623. ytwp.initialized = false;
  624. ytwp.pageReady = false;
  625. ytwp.isWatchPage = false;
  626. ytwp.html5.app = null;
  627. // ytwp.html5.YTRect = null;
  628. ytwp.html5.YTApplication = null;
  629. ytwp.html5.playerInstances = null;
  630. //ytwp.html5.moviePlayerElement = null;
  631. },
  632. addBodyClass: function() {
  633. // Insert CSS Into the body so people can style around the effects of this script.
  634. jQuery.addClass(document.body, scriptBodyClassId);
  635. ytwp.log('Applied ' + scriptBodyClassSelector);
  636. },
  637. html5PlayerFix: function() {
  638. ytwp.log('html5PlayerFix');
  639.  
  640. try {
  641. if (!uw.ytcenter // Youtube Center
  642. && !uw.html5Patched // Youtube+
  643. && (!ytwp.html5.app)
  644. && (uw.ytplayer && uw.ytplayer.config)
  645. && (uw.yt && uw.yt.player && uw.yt.player.Application && uw.yt.player.Application.create)
  646. ) {
  647. ytwp.html5.app = ytwp.html5.getPlayerInstance();
  648. }
  649.  
  650. ytwp.html5.update();
  651. ytwp.html5.autohideControls();
  652. } catch (e) {
  653. ytwp.error(e);
  654. }
  655. },
  656.  
  657. };
  658.  
  659.  
  660. ytwp.pubsubListeners = {
  661. 'init': function() { // Not always called
  662. ytwp.event.init();
  663. },
  664. 'init-watch': function() { // Not always called
  665. ytwp.event.init();
  666. },
  667. 'player-added': function() { // Not always called
  668. // Usually called after init-watch, however this is called before init when going from channel -> watch page.
  669. // The init event is when the body element resets all it's classes.
  670. ytwp.event.init();
  671. },
  672. // 'player-resize': function() {},
  673. // 'player-playback-start': function() {},
  674. 'appbar-guide-delay-load': function() {
  675. // Listen to a later event that is always called in case the others are missed.
  676. ytwp.event.init();
  677.  
  678. // Channel -> /watch
  679. if (ytwp.util.isWatchUrl())
  680. ytwp.event.addBodyClass();
  681. },
  682. // 'dispose-watch': function() {},
  683. 'dispose': function() {
  684. ytwp.event.onDispose();
  685. }
  686. };
  687.  
  688. ytwp.registerYoutubeListeners = function() {
  689. ytwp.registerYoutubePubSubListeners();
  690. };
  691.  
  692. ytwp.registerYoutubePubSubListeners = function() {
  693. // Subscribe
  694. for (var eventName in ytwp.pubsubListeners) {
  695. var eventListener = ytwp.pubsubListeners[eventName];
  696. uw.yt.pubsub.instance_.subscribe(eventName, eventListener);
  697. }
  698. };
  699.  
  700. ytwp.main = function() {
  701. try {
  702. ytwp.registerYoutubeListeners();
  703. } catch(e) {
  704. ytwp.error("Could not hook yt.pubsub", e);
  705. setTimeout(ytwp.main, 1000);
  706. }
  707. ytwp.event.init();
  708. };
  709.  
  710. ytwp.main();
  711. })(typeof unsafeWindow !== 'undefined' ? unsafeWindow : window);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址