Resize YT To Window Size

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

当前为 2015-12-20 提交的版本,查看 最新版本

  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 75
  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.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. // Object.keys(app).forEach(function(key1) {
  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.  
  342. if (fnAlreadyReplacedCount > 0) {
  343. // return;
  344. }
  345.  
  346. if (moviePlayer === null || clientRectFn === null) {
  347. console.log('[ytwp] ', '[Error]', 'HTML5 Player has changed or there\'s multiple playerInstances and this one has been destroyed.');
  348. console.log('moviePlayer', moviePlayerKey, moviePlayer);
  349. console.log('clientRectFn', clientRectFnKey, clientRectFn);
  350. console.log('fnAlreadyReplacedCount', fnAlreadyReplacedCount);
  351. if (moviePlayer === null) {
  352. console.log('Debugging: moviePlayer');
  353. var table = [];
  354. Object.keys(app).forEach(function(key1) {
  355. var val1 = app[key1];
  356. table.push({
  357. key: key1,
  358. element: typeof val1 === 'object' && val1 !== null && val1.element === moviePlayerElement,
  359. val: val1,
  360. });
  361. });
  362. console.table(table);
  363. }
  364. if (moviePlayer != null) {
  365. console.log('Debugging: clientRectFn');
  366. var table = [];
  367. for (var key2 in moviePlayer) {
  368. var val2 = moviePlayer[key2];
  369. table.push({
  370. key: key2,
  371. returns: moviePlayer[key2] && moviePlayer[key2].toString().indexOf('return'),
  372. src: moviePlayer[key2] && moviePlayer[key2].toString(),
  373. });
  374. }
  375. console.table(table);
  376. }
  377. return;
  378. }
  379. ytwp.html5.setRectFn(app, moviePlayerKey, clientRectFnKey);
  380.  
  381. if (applyFnKey) {
  382. app[applyFnKey]('resize');
  383. } else {
  384. ytwp.log('applyFn not found');
  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. ytwp.event.initStyle();
  397. ytwp.event.initScroller();
  398. ytwp.initialized = true;
  399. ytwp.pageReady = false;
  400. }
  401. }
  402. ytwp.event.onWatchInit();
  403. ytwp.event.html5PlayerFix();
  404. },
  405. initScroller: function() {
  406. // Register listener & Call it now.
  407. uw.addEventListener('scroll', ytwp.event.onScroll, false);
  408. uw.addEventListener('resize', ytwp.event.onScroll, false);
  409. ytwp.event.onScroll();
  410. },
  411. onScroll: function() {
  412. var viewportHeight = document.documentElement.clientHeight;
  413.  
  414. // topOfPageClassId
  415. if (uw.scrollY == 0) {
  416. jQuery.addClass(document.body, topOfPageClassId);
  417. } else {
  418. jQuery.removeClass(document.body, topOfPageClassId);
  419. }
  420.  
  421. // viewingVideoClassId
  422. if (uw.scrollY <= viewportHeight) {
  423. jQuery.addClass(document.body, viewingVideoClassId);
  424. } else {
  425. jQuery.removeClass(document.body, viewingVideoClassId);
  426. }
  427. },
  428. initStyle: function() {
  429. ytwp.log('initStyle');
  430. ytwp.style = new JSStyleSheet(scriptStyleId);
  431. ytwp.event.buildStylesheet();
  432. ytwp.style.injectIntoHeader();
  433. },
  434. buildStylesheet: function() {
  435. ytwp.log('buildStylesheet');
  436. //--- Video Player
  437.  
  438. //
  439. var d;
  440. d = buildVenderPropertyDict(transitionProperties, 'left 0s linear, padding-left 0s linear');
  441. d['padding'] = '0 !important';
  442. d['margin'] = '0 !important';
  443. ytwp.style.appendRule([
  444. scriptBodyClassSelector + ' #player',
  445. scriptBodyClassSelector + '.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible #player',
  446. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player',
  447. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #player-legacy',
  448. scriptBodyClassSelector + '.ltr.ytcenter-site-center.ytcenter-non-resize.ytcenter-guide-visible.guide-collapsed #watch7-main-container',
  449. ], d);
  450. //
  451. d = buildVenderPropertyDict(transitionProperties, 'width 0s linear, left 0s linear');
  452.  
  453. // Bugfix for Firefox
  454. // Parts of the header (search box) are hidden under the player.
  455. // Firefox doesn't seem to be using the fixed header+guide yet.
  456. d['float'] = 'initial';
  457.  
  458. // Skinny mode
  459. d['left'] = 0;
  460. d['margin-left'] = 0;
  461.  
  462. ytwp.style.appendRule(scriptBodyClassSelector + ' #player-api', d);
  463.  
  464. // Theatre mode
  465. ytwp.style.appendRule(scriptBodyClassSelector + ' .watch-stage-mode #player .player-api', {
  466. 'left': 'initial',
  467. 'margin-left': 'initial',
  468. });
  469. // Hide the cinema/wide mode button since it's useless.
  470. //ytwp.style.appendRule(scriptBodyClassSelector + ' #movie_player .ytp-size-button', 'display', 'none');
  471.  
  472. // !important is mainly for simplicity, but is needed to override the !important styling when the Guide is open due to:
  473. // .sidebar-collapsed #watch7-video, .sidebar-collapsed #watch7-main, .sidebar-collapsed .watch7-playlist { width: 945px!important; }
  474. // Also, Youtube Center resizes #player at element level.
  475. ytwp.style.appendRule(
  476. [
  477. scriptBodyClassSelector + ' #player',
  478. scriptBodyClassSelector + ' #movie_player',
  479. scriptBodyClassSelector + ' #player-mole-container',
  480. scriptBodyClassSelector + ' .html5-video-container',
  481. scriptBodyClassSelector + ' .html5-main-video',
  482. ],
  483. {
  484. 'width': '100% !important',
  485. 'min-width': '100% !important',
  486. 'max-width': '100% !important',
  487. 'height': '100% !important',
  488. 'min-height': '100% !important',
  489. 'max-height': '100% !important',
  490. }
  491. );
  492.  
  493. ytwp.style.appendRule(
  494. [
  495. scriptBodyClassSelector + ' #player',
  496. scriptBodyClassSelector + ' .html5-main-video',
  497. ],
  498. {
  499. 'top': '0 !important',
  500. 'right': '0 !important',
  501. 'bottom': '0 !important',
  502. 'left': '0 !important',
  503. }
  504. );
  505. // Resize #player-unavailable, #player-api
  506. // Using min/max width/height will keep
  507. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-width', 'width', '100% !important');
  508. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height', 'height', '100% !important');
  509.  
  510. // Ad
  511. ytwp.style.appendRule(scriptBodyClassSelector + ' .html5-video-player .ad-container-single-media-element-annotations', 'top', '0');
  512.  
  513. //--- Move Video Player
  514. ytwp.style.appendRule(scriptBodyClassSelector + ' #player', {
  515. 'position': 'absolute',
  516. // Already top:0; left: 0;
  517. });
  518. ytwp.style.appendRule(scriptBodyClassSelector, { // body
  519. 'margin-top': '100vh',
  520. });
  521.  
  522.  
  523. //--- Sidebar
  524. // Remove the transition delay as you can see it moving on page load.
  525. d = buildVenderPropertyDict(transitionProperties, 'margin-top 0s linear, padding-top 0s linear');
  526. d['margin-top'] = '0 !important';
  527. d['top'] = '0 !important';
  528. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch7-sidebar', d);
  529.  
  530. ytwp.style.appendRule(scriptBodyClassSelector + '.cardified-page #watch7-sidebar-contents', 'padding-top', '0');
  531.  
  532. //--- Absolutely position the fixed header.
  533. // Masthead
  534. d = buildVenderPropertyDict(transitionProperties, 'top 0s linear !important');
  535. ytwp.style.appendRule(scriptBodyClassSelector + '.hide-header-transition #masthead-positioner', d);
  536. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #masthead-positioner', {
  537. 'position': 'absolute',
  538. 'top': '100% !important'
  539. });
  540.  
  541. // Guide
  542. // When watching the video, we need to line it up with the masthead.
  543. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #appbar-guide-menu', {
  544. 'display': 'initial',
  545. 'position': 'absolute',
  546. 'top': '100% !important' // Masthead height
  547. });
  548. ytwp.style.appendRule(scriptBodyClassSelector + '.' + viewingVideoClassId + ' #page.watch #guide', {
  549. 'display': 'initial',
  550. 'margin': '0',
  551. 'position': 'initial'
  552. });
  553.  
  554. //---
  555. // Hide Scrollbars
  556. ytwp.style.appendRule(scriptBodyClassSelector + '.' + topOfPageClassId, 'overflow-x', 'hidden');
  557.  
  558.  
  559. //--- Fix Other Possible Style Issues
  560. ytwp.style.appendRule(scriptBodyClassSelector + ' #placeholder-player', 'display', 'none');
  561. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch-sidebar-spacer', 'display', 'none');
  562. ytwp.style.appendRule(scriptBodyClassSelector + ' .skip-nav', 'display', 'none');
  563.  
  564. //--- Whitespace Leftover From Moving The Video
  565. ytwp.style.appendRule(scriptBodyClassSelector + ' #page.watch', 'padding-top', '0');
  566. ytwp.style.appendRule(scriptBodyClassSelector + ' .player-branded-banner', 'height', '0');
  567.  
  568. //--- Youtube+ Compatiblity
  569. ytwp.style.appendRule(scriptBodyClassSelector + ' #body-container', 'position', 'static');
  570. ytwp.style.appendRule('.part_static_size:not(.content-snap-width-skinny-mode) ' + scriptBodyClassSelector + ' .watch-non-stage-mode #player-playlist', 'width', '1066px');
  571.  
  572. //--- Playlist Bar
  573. ytwp.style.appendRule([
  574. scriptBodyClassSelector + ' #placeholder-playlist',
  575. scriptBodyClassSelector + ' #player .player-height#watch-appbar-playlist',
  576. ], {
  577. 'height': '540px !important',
  578. 'max-height': '540px !important',
  579. });
  580.  
  581. d = buildVenderPropertyDict(transitionProperties, 'transform 0s linear');
  582. ytwp.style.appendRule(scriptBodyClassSelector + ' #watch-appbar-playlist', d);
  583. d = buildVenderPropertyDict(transformProperties, 'translateY(0px)');
  584. d['margin-left'] = '0';
  585. d['top'] = 'calc(100vh + 60px)';
  586. ytwp.style.appendRule(scriptBodyClassSelector + ' #player .player-height#watch-appbar-playlist', d);
  587. ytwp.style.appendRule(scriptBodyClassSelector + ' .playlist-videos-list', {
  588. 'max-height': '470px !important',
  589. 'height': 'initial !important',
  590. });
  591. },
  592. onWatchInit: function() {
  593. ytwp.log('onWatchInit');
  594. if (!ytwp.initialized) return;
  595. if (ytwp.pageReady) return;
  596.  
  597. ytwp.event.addBodyClass();
  598. ytwp.pageReady = true;
  599. },
  600. onDispose: function() {
  601. ytwp.log('onDispose');
  602. ytwp.initialized = false;
  603. ytwp.pageReady = false;
  604. ytwp.isWatchPage = false;
  605. ytwp.html5.app = null;
  606. },
  607. addBodyClass: function() {
  608. // Insert CSS Into the body so people can style around the effects of this script.
  609. jQuery.addClass(document.body, scriptBodyClassId);
  610. ytwp.log('Applied ' + scriptBodyClassSelector);
  611. },
  612. html5PlayerFix: function() {
  613. ytwp.log('html5PlayerFix');
  614.  
  615. try {
  616. if (!uw.ytcenter // Youtube Center
  617. && !uw.html5Patched // Youtube+
  618. && (!ytwp.html5.app)
  619. && (uw.ytplayer && uw.ytplayer.config)
  620. && (uw.yt && uw.yt.player && uw.yt.player.Application && uw.yt.player.Application.create)
  621. ) {
  622. ytwp.html5.app = ytwp.html5.getPlayerInstance();
  623. }
  624.  
  625. ytwp.html5.update();
  626. ytwp.html5.autohideControls();
  627. } catch (e) {
  628. ytwp.error(e);
  629. }
  630. },
  631.  
  632. };
  633.  
  634.  
  635. ytwp.pubsubListeners = {
  636. 'init': function() { // Not always called
  637. ytwp.event.init();
  638. },
  639. 'init-watch': function() { // Not always called
  640. ytwp.event.init();
  641. },
  642. 'player-added': function() { // Not always called
  643. // Usually called after init-watch, however this is called before init when going from channel -> watch page.
  644. // The init event is when the body element resets all it's classes.
  645. ytwp.event.init();
  646. },
  647. // 'player-resize': function() {},
  648. // 'player-playback-start': function() {},
  649. 'appbar-guide-delay-load': function() {
  650. // Listen to a later event that is always called in case the others are missed.
  651. ytwp.event.init();
  652.  
  653. // Channel -> /watch
  654. if (ytwp.util.isWatchUrl())
  655. ytwp.event.addBodyClass();
  656. },
  657. // 'dispose-watch': function() {},
  658. 'dispose': function() {
  659. ytwp.event.onDispose();
  660. }
  661. };
  662.  
  663. ytwp.registerYoutubeListeners = function() {
  664. ytwp.registerYoutubePubSubListeners();
  665. };
  666.  
  667. ytwp.registerYoutubePubSubListeners = function() {
  668. // Subscribe
  669. for (var eventName in ytwp.pubsubListeners) {
  670. var eventListener = ytwp.pubsubListeners[eventName];
  671. uw.yt.pubsub.instance_.subscribe(eventName, eventListener);
  672. }
  673. };
  674.  
  675. ytwp.main = function() {
  676. try {
  677. ytwp.registerYoutubeListeners();
  678. } catch(e) {
  679. ytwp.error("Could not hook yt.pubsub", e);
  680. setTimeout(ytwp.main, 1000);
  681. }
  682. ytwp.event.init();
  683. };
  684.  
  685. ytwp.main();
  686. })(typeof unsafeWindow !== 'undefined' ? unsafeWindow : window);

QingJ © 2025

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