ykh5p

改善优酷官方html5播放器播放体验

目前為 2017-09-06 提交的版本,檢視 最新版本

  1. 'use strict';
  2.  
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4.  
  5. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6.  
  7. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8.  
  9. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  10.  
  11. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12.  
  13. // ==UserScript==
  14. // @name ykh5p
  15. // @namespace https://github.com/gooyie/ykh5p
  16. // @homepageURL https://github.com/gooyie/ykh5p
  17. // @supportURL https://github.com/gooyie/ykh5p/issues
  18. // @version 0.9.3
  19. // @description 改善优酷官方html5播放器播放体验
  20. // @author gooyie
  21. // @license MIT License
  22. //
  23. // @include *://v.youku.com/*
  24. // @grant GM_info
  25. // @grant GM_addStyle
  26. // @grant unsafeWindow
  27. // @run-at document-start
  28. // ==/UserScript==
  29.  
  30. (function () {
  31. 'use strict';
  32.  
  33. /* eslint-disable no-console */
  34.  
  35. var Logger = function () {
  36. function Logger() {
  37. _classCallCheck(this, Logger);
  38. }
  39.  
  40. _createClass(Logger, null, [{
  41. key: 'log',
  42. value: function log() {
  43. var _console;
  44.  
  45. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  46. args[_key] = arguments[_key];
  47. }
  48.  
  49. (_console = console).log.apply(_console, ['%c' + this.tag + '%c' + args.shift(), 'color: #fff; background: #2FB3FF', ''].concat(args));
  50. }
  51. }, {
  52. key: 'info',
  53. value: function info() {
  54. var _console2;
  55.  
  56. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  57. args[_key2] = arguments[_key2];
  58. }
  59.  
  60. (_console2 = console).info.apply(_console2, [this.tag + args.shift()].concat(args));
  61. }
  62. }, {
  63. key: 'debug',
  64. value: function debug() {
  65. var _console3;
  66.  
  67. for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  68. args[_key3] = arguments[_key3];
  69. }
  70.  
  71. (_console3 = console).debug.apply(_console3, [this.tag + args.shift()].concat(args));
  72. }
  73. }, {
  74. key: 'warn',
  75. value: function warn() {
  76. var _console4;
  77.  
  78. for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  79. args[_key4] = arguments[_key4];
  80. }
  81.  
  82. (_console4 = console).warn.apply(_console4, [this.tag + args.shift()].concat(args));
  83. }
  84. }, {
  85. key: 'error',
  86. value: function error() {
  87. var _console5;
  88.  
  89. for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  90. args[_key5] = arguments[_key5];
  91. }
  92.  
  93. (_console5 = console).error.apply(_console5, [this.tag + args.shift()].concat(args));
  94. }
  95. }, {
  96. key: 'tag',
  97. get: function get() {
  98. return '[' + GM_info.script.name + ']';
  99. }
  100. }]);
  101.  
  102. return Logger;
  103. }();
  104. /* eslint-enable no-console */
  105.  
  106. var Hooker = function () {
  107. function Hooker() {
  108. _classCallCheck(this, Hooker);
  109. }
  110.  
  111. _createClass(Hooker, null, [{
  112. key: 'hookCall',
  113. value: function hookCall() {
  114. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  115.  
  116. var call = Function.prototype.call;
  117. Function.prototype.call = function () {
  118. for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  119. args[_key6] = arguments[_key6];
  120. }
  121.  
  122. var ret = call.apply(this, args);
  123. try {
  124. if (args) cb.apply(undefined, args);
  125. } catch (err) {
  126. Logger.error(err.stack);
  127. }
  128. return ret;
  129. };
  130.  
  131. Function.prototype.call.toString = Function.prototype.call.toLocaleString = function () {
  132. return 'function call() { [native code] }';
  133. };
  134. }
  135. }, {
  136. key: '_isEsModule',
  137. value: function _isEsModule(obj) {
  138. return obj && obj.__esModule;
  139. }
  140. }, {
  141. key: '_isFuction',
  142. value: function _isFuction(arg) {
  143. return 'function' === typeof arg;
  144. }
  145. }, {
  146. key: '_isModuleCall',
  147. value: function _isModuleCall(args) {
  148. // module.exports, module, module.exports, require
  149. return args.length === 4 && args[1] instanceof Object && args[1].hasOwnProperty('exports');
  150. }
  151. }, {
  152. key: 'hookModuleCall',
  153. value: function hookModuleCall() {
  154. var _this = this;
  155.  
  156. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  157.  
  158. this.hookCall(function () {
  159. for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  160. args[_key7] = arguments[_key7];
  161. }
  162.  
  163. if (_this._isModuleCall(args)) cb.apply(undefined, args);
  164. });
  165. }
  166. }, {
  167. key: '_isUpsModuleCall',
  168. value: function _isUpsModuleCall() {
  169. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  170.  
  171. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('getServieceUrl') && /\.id\s*=\s*"ups"/.test(exports.default.toString());
  172. }
  173. }, {
  174. key: 'hookUps',
  175. value: function hookUps() {
  176. var _this2 = this;
  177.  
  178. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  179.  
  180. this.hookModuleCall(function () {
  181. for (var _len8 = arguments.length, args = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
  182. args[_key8] = arguments[_key8];
  183. }
  184.  
  185. if (_this2._isUpsModuleCall(args[1].exports)) cb(args[1].exports);
  186. });
  187. }
  188. }, {
  189. key: 'hookUpsOnComplete',
  190. value: function hookUpsOnComplete() {
  191. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  192.  
  193. this.hookUps(function (exports) {
  194. var onComplete = exports.default.prototype.onComplete;
  195. exports.default.prototype.onComplete = function (res) {
  196. cb(res);
  197. onComplete.apply(this, [res]);
  198. };
  199. });
  200. }
  201. }, {
  202. key: '_isLogoModuleCall',
  203. value: function _isLogoModuleCall() {
  204. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  205.  
  206. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('reset') && /logo\.style\.display/.test(exports.default.prototype.reset.toString());
  207. }
  208. }, {
  209. key: 'hookLogo',
  210. value: function hookLogo() {
  211. var _this3 = this;
  212.  
  213. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  214.  
  215. this.hookModuleCall(function () {
  216. for (var _len9 = arguments.length, args = Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
  217. args[_key9] = arguments[_key9];
  218. }
  219.  
  220. if (_this3._isLogoModuleCall(args[1].exports)) cb(args[1].exports);
  221. });
  222. }
  223. }, {
  224. key: '_isSettingModuleCall',
  225. value: function _isSettingModuleCall() {
  226. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  227.  
  228. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('setQuality');
  229. }
  230. }, {
  231. key: 'hookSetting',
  232. value: function hookSetting() {
  233. var _this4 = this;
  234.  
  235. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  236.  
  237. this.hookModuleCall(function () {
  238. for (var _len10 = arguments.length, args = Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
  239. args[_key10] = arguments[_key10];
  240. }
  241.  
  242. if (_this4._isSettingModuleCall(args[1].exports)) cb(args[1].exports);
  243. });
  244. }
  245. }, {
  246. key: 'hookRenderQulaity',
  247. value: function hookRenderQulaity() {
  248. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  249.  
  250. Hooker.hookSetting(function (exports) {
  251. var renderQulaity = exports.default.prototype.renderQulaity;
  252. exports.default.prototype.renderQulaity = function (qualitys) {
  253. cb(qualitys, this);
  254. renderQulaity.apply(this, [qualitys]);
  255. };
  256. });
  257. }
  258. }, {
  259. key: 'hookSetCurrentQuality',
  260. value: function hookSetCurrentQuality() {
  261. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  262.  
  263. Hooker.hookSetting(function (exports) {
  264. var setCurrentQuality = exports.default.prototype.setCurrentQuality;
  265. exports.default.prototype.setCurrentQuality = function () {
  266. cb(this);
  267. setCurrentQuality.apply(this);
  268. };
  269. });
  270. }
  271. }, {
  272. key: '_isPlayerModuleCall',
  273. value: function _isPlayerModuleCall() {
  274. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  275.  
  276. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('_resetPlayer');
  277. }
  278. }, {
  279. key: 'hookPlayer',
  280. value: function hookPlayer() {
  281. var _this5 = this;
  282.  
  283. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  284.  
  285. this.hookModuleCall(function () {
  286. for (var _len11 = arguments.length, args = Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
  287. args[_key11] = arguments[_key11];
  288. }
  289.  
  290. if (_this5._isPlayerModuleCall(args[1].exports)) cb(args[1].exports);
  291. });
  292. }
  293. }, {
  294. key: 'hookInitPlayerEvent',
  295. value: function hookInitPlayerEvent() {
  296. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  297.  
  298. Hooker.hookPlayer(function (exports) {
  299. var _initPlayerEvent = exports.default.prototype._initPlayerEvent;
  300. exports.default.prototype._initPlayerEvent = function () {
  301. cb(this);
  302. _initPlayerEvent.apply(this);
  303. };
  304. });
  305. }
  306. }, {
  307. key: 'hookResetPlayerAfter',
  308. value: function hookResetPlayerAfter() {
  309. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  310.  
  311. Hooker.hookPlayer(function (exports) {
  312. var _resetPlayer = exports.default.prototype._resetPlayer;
  313. exports.default.prototype._resetPlayer = function () {
  314. try {
  315. _resetPlayer.apply(this);
  316. } catch (err) {
  317. // 忽略 ykSDK.destroyAd 异常
  318. if (!err.stack.includes('destroyAd')) throw err;
  319. }
  320. cb(this);
  321. };
  322. });
  323. }
  324. }, {
  325. key: '_isKeyShortcutsModuleCall',
  326. value: function _isKeyShortcutsModuleCall() {
  327. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  328.  
  329. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('registerEvents');
  330. }
  331. }, {
  332. key: 'hookKeyShortcuts',
  333. value: function hookKeyShortcuts() {
  334. var _this6 = this;
  335.  
  336. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  337.  
  338. this.hookModuleCall(function () {
  339. for (var _len12 = arguments.length, args = Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
  340. args[_key12] = arguments[_key12];
  341. }
  342.  
  343. if (_this6._isKeyShortcutsModuleCall(args[1].exports)) cb(args[1].exports);
  344. });
  345. }
  346. }, {
  347. key: '_isTipsModuleCall',
  348. value: function _isTipsModuleCall() {
  349. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  350.  
  351. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('showHintTips');
  352. }
  353. }, {
  354. key: 'hookTips',
  355. value: function hookTips() {
  356. var _this7 = this;
  357.  
  358. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  359.  
  360. this.hookModuleCall(function () {
  361. for (var _len13 = arguments.length, args = Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
  362. args[_key13] = arguments[_key13];
  363. }
  364.  
  365. if (_this7._isTipsModuleCall(args[1].exports)) cb(args[1].exports);
  366. });
  367. }
  368. }, {
  369. key: '_isAdServiceModuleCall',
  370. value: function _isAdServiceModuleCall() {
  371. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  372.  
  373. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('requestAdData');
  374. }
  375. }, {
  376. key: 'hookAdService',
  377. value: function hookAdService() {
  378. var _this8 = this;
  379.  
  380. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  381.  
  382. this.hookModuleCall(function () {
  383. for (var _len14 = arguments.length, args = Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
  384. args[_key14] = arguments[_key14];
  385. }
  386.  
  387. if (_this8._isAdServiceModuleCall(args[1].exports)) cb(args[1].exports);
  388. });
  389. }
  390. }, {
  391. key: '_isTopAreaModuleCall',
  392. value: function _isTopAreaModuleCall() {
  393. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  394.  
  395. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('_timerHandler');
  396. }
  397. }, {
  398. key: 'hookTopArea',
  399. value: function hookTopArea() {
  400. var _this9 = this;
  401.  
  402. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  403.  
  404. this.hookModuleCall(function () {
  405. for (var _len15 = arguments.length, args = Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
  406. args[_key15] = arguments[_key15];
  407. }
  408.  
  409. if (_this9._isTopAreaModuleCall(args[1].exports)) cb(args[1].exports);
  410. });
  411. }
  412. }, {
  413. key: 'hookTopAreaAddEvent',
  414. value: function hookTopAreaAddEvent() {
  415. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  416.  
  417. Hooker.hookTopArea(function (exports) {
  418. var _addEvent = exports.default.prototype._addEvent;
  419. exports.default.prototype._addEvent = function () {
  420. cb(this);
  421. _addEvent.apply(this);
  422. };
  423. });
  424. }
  425. }, {
  426. key: '_isPreviewLayerModuleCall',
  427. value: function _isPreviewLayerModuleCall() {
  428. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  429.  
  430. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('setPreviewShow');
  431. }
  432. }, {
  433. key: 'hookPreviewLayer',
  434. value: function hookPreviewLayer() {
  435. var _this10 = this;
  436.  
  437. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  438.  
  439. this.hookModuleCall(function () {
  440. for (var _len16 = arguments.length, args = Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
  441. args[_key16] = arguments[_key16];
  442. }
  443.  
  444. if (_this10._isPreviewLayerModuleCall(args[1].exports)) cb(args[1].exports);
  445. });
  446. }
  447. }, {
  448. key: 'hookPreviewLayerBind',
  449. value: function hookPreviewLayerBind() {
  450. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  451.  
  452. Hooker.hookPreviewLayer(function (exports) {
  453. var bind = exports.default.prototype.bind;
  454. exports.default.prototype.bind = function () {
  455. cb(this);
  456. bind.apply(this);
  457. };
  458. });
  459. }
  460. }, {
  461. key: '_isSettingSeriesComponentModuleCall',
  462. value: function _isSettingSeriesComponentModuleCall() {
  463. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  464.  
  465. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('_addEvent') && exports.default.prototype._addEvent.toString().includes('seriesliseLayer');
  466. }
  467. }, {
  468. key: 'hookSettingSeries',
  469. value: function hookSettingSeries() {
  470. var _this11 = this;
  471.  
  472. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  473.  
  474. this.hookModuleCall(function () {
  475. for (var _len17 = arguments.length, args = Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
  476. args[_key17] = arguments[_key17];
  477. }
  478.  
  479. if (_this11._isSettingSeriesComponentModuleCall(args[1].exports)) cb(args[1].exports);
  480. });
  481. }
  482. }, {
  483. key: '_isGlobalModuleCall',
  484. value: function _isGlobalModuleCall() {
  485. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  486.  
  487. return this._isEsModule(exports) && this._isFuction(exports.default) && exports.default.prototype && exports.default.prototype.hasOwnProperty('resetConfig');
  488. }
  489. }, {
  490. key: 'hookGlobal',
  491. value: function hookGlobal() {
  492. var _this12 = this;
  493.  
  494. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  495.  
  496. this.hookModuleCall(function () {
  497. for (var _len18 = arguments.length, args = Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
  498. args[_key18] = arguments[_key18];
  499. }
  500.  
  501. if (_this12._isGlobalModuleCall(args[1].exports)) cb(args[1].exports);
  502. });
  503. }
  504. }, {
  505. key: 'hookGlobalConstructorAfter',
  506. value: function hookGlobalConstructorAfter() {
  507. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  508.  
  509. Hooker.hookGlobal(function (exports) {
  510. var constructor = exports.default;
  511. exports.default = function () {
  512. for (var _len19 = arguments.length, args = Array(_len19), _key19 = 0; _key19 < _len19; _key19++) {
  513. args[_key19] = arguments[_key19];
  514. }
  515.  
  516. constructor.apply(this, args);
  517. cb(this);
  518. };
  519. exports.default.prototype = constructor.prototype;
  520. });
  521. }
  522. }, {
  523. key: 'hookGlobalInit',
  524. value: function hookGlobalInit() {
  525. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  526.  
  527. Hooker.hookGlobal(function (exports) {
  528. var init = exports.default.prototype.init;
  529. exports.default.prototype.init = function (config) {
  530. cb(config, this);
  531. init.apply(this, [config]);
  532. };
  533. });
  534. }
  535. }, {
  536. key: 'hookGlobalDeal',
  537. value: function hookGlobalDeal() {
  538. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  539.  
  540. Hooker.hookGlobal(function (exports) {
  541. var deal = exports.default.prototype.deal;
  542. exports.default.prototype.deal = function () {
  543. cb(this);
  544. deal.apply(this);
  545. };
  546. });
  547. }
  548. }, {
  549. key: 'hookGlobalResetAfter',
  550. value: function hookGlobalResetAfter() {
  551. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  552.  
  553. Hooker.hookGlobal(function (exports) {
  554. var reset = exports.default.prototype.reset;
  555. exports.default.prototype.reset = function () {
  556. reset.apply(this);
  557. cb(this);
  558. };
  559. });
  560. }
  561. }, {
  562. key: '_extractArgsName',
  563. value: function _extractArgsName(code) {
  564. return code.slice(code.indexOf('(') + 1, code.indexOf(')')).split(/\s*,\s*/);
  565. }
  566. }, {
  567. key: '_extractFunctionBody',
  568. value: function _extractFunctionBody(code) {
  569. return code.slice(code.indexOf('{') + 1, code.lastIndexOf('}'));
  570. }
  571. }, {
  572. key: '_isBaseModuleCall',
  573. value: function _isBaseModuleCall() {
  574. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  575.  
  576. return exports.SingleVideoControl && exports.MultiVideoControl;
  577. }
  578. }, {
  579. key: 'hookBase',
  580. value: function hookBase() {
  581. var _this13 = this;
  582.  
  583. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  584. var mode = arguments[1];
  585.  
  586. if (!this._hookBaseCallbacks) {
  587. this._hookBaseCallbacks = [];
  588. this._hookBaseCodeCallbacks = [];
  589. (mode === 'code' ? this._hookBaseCodeCallbacks : this._hookBaseCallbacks).push(cb);
  590.  
  591. this.hookModuleCall(function () {
  592. for (var _len20 = arguments.length, args = Array(_len20), _key20 = 0; _key20 < _len20; _key20++) {
  593. args[_key20] = arguments[_key20];
  594. }
  595.  
  596. if (_this13._isBaseModuleCall(args[1].exports)) {
  597. if (_this13._hookBaseCodeCallbacks.length > 0) {
  598. var code = args[3].m[args[1].i].toString();
  599. code = _this13._hookBaseCodeCallbacks.reduce(function (c, cb) {
  600. return cb(c);
  601. }, code);
  602. var fn = new (Function.prototype.bind.apply(Function, [null].concat(_toConsumableArray(_this13._extractArgsName(code)), [_this13._extractFunctionBody(code)])))();
  603. fn.apply(args[0], args.slice(1));
  604. }
  605. _this13._hookBaseCallbacks.forEach(function (cb) {
  606. return cb(args[1].exports);
  607. });
  608. }
  609. });
  610. } else {
  611. (mode === 'code' ? this._hookBaseCodeCallbacks : this._hookBaseCallbacks).push(cb);
  612. }
  613. }
  614. }, {
  615. key: 'hookOz',
  616. value: function hookOz() {
  617. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  618.  
  619. if (!this._hookOzCallbacks) {
  620. var self = this;
  621. this._hookOzCallbacks = [cb];
  622. var window = unsafeWindow;
  623. var oz = window.oz; // oz 可能先于脚本执行
  624.  
  625. Object.defineProperty(window, 'oz', {
  626. get: function get() {
  627. return oz;
  628. },
  629. set: function set(value) {
  630. oz = value;
  631. try {
  632. self._hookOzCallbacks.forEach(function (cb) {
  633. return cb(oz);
  634. });
  635. } catch (err) {
  636. Logger.error(err.stack);
  637. }
  638. }
  639. });
  640.  
  641. if (oz) window.oz = oz; // oz 先于脚本执行
  642. } else {
  643. this._hookOzCallbacks.push(cb);
  644. }
  645. }
  646. }, {
  647. key: 'hookDefine',
  648. value: function hookDefine(name) {
  649. var _this14 = this;
  650.  
  651. var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
  652.  
  653. if (!this._hookDefineCallbacksMap) {
  654. this._hookDefineCallbacksMap = new Map([[name, [cb]]]);
  655. this.hookOz(function (oz) {
  656. var self = _this14;
  657. var define = oz.define;
  658. oz.define = function (name, deps, block) {
  659. if (self._hookDefineCallbacksMap.has(name)) {
  660. var code = block.toString();
  661. code = self._hookDefineCallbacksMap.get(name).reduce(function (c, cb) {
  662. return cb(c);
  663. }, code);
  664. block = new (Function.prototype.bind.apply(Function, [null].concat(_toConsumableArray(self._extractArgsName(code)), [self._extractFunctionBody(code)])))();
  665. }
  666. define(name, deps, block);
  667. };
  668. });
  669. } else {
  670. if (this._hookDefineCallbacksMap.has(name)) {
  671. this._hookDefineCallbacksMap.get(name).push(cb);
  672. } else {
  673. this._hookDefineCallbacksMap.set(name, [cb]);
  674. }
  675. }
  676. }
  677. }]);
  678.  
  679. return Hooker;
  680. }();
  681.  
  682. var Patch = function () {
  683. function Patch() {
  684. _classCallCheck(this, Patch);
  685.  
  686. this._installed = false;
  687. }
  688.  
  689. _createClass(Patch, [{
  690. key: 'install',
  691. value: function install() {
  692. if (!this._installed) {
  693. this._installed = true;
  694. this._apply();
  695. }
  696. }
  697. }, {
  698. key: '_apply',
  699. value: function _apply() {}
  700. }]);
  701.  
  702. return Patch;
  703. }();
  704.  
  705. var AdBlockPatch = function (_Patch) {
  706. _inherits(AdBlockPatch, _Patch);
  707.  
  708. function AdBlockPatch() {
  709. _classCallCheck(this, AdBlockPatch);
  710.  
  711. return _possibleConstructorReturn(this, (AdBlockPatch.__proto__ || Object.getPrototypeOf(AdBlockPatch)).call(this));
  712. }
  713.  
  714. _createClass(AdBlockPatch, [{
  715. key: '_apply',
  716. value: function _apply() {
  717. Hooker.hookAdService(function (exports) {
  718. exports.default.prototype.requestAdData = function (arg) {
  719. var _this16 = this;
  720.  
  721. setTimeout(function () {
  722. _this16.fail(arg, { code: '404', message: 'error' });
  723. }, 0);
  724. };
  725. });
  726. }
  727. }]);
  728.  
  729. return AdBlockPatch;
  730. }(Patch);
  731.  
  732. var WatermarksPatch = function (_Patch2) {
  733. _inherits(WatermarksPatch, _Patch2);
  734.  
  735. function WatermarksPatch() {
  736. _classCallCheck(this, WatermarksPatch);
  737.  
  738. return _possibleConstructorReturn(this, (WatermarksPatch.__proto__ || Object.getPrototypeOf(WatermarksPatch)).call(this));
  739. }
  740.  
  741. _createClass(WatermarksPatch, [{
  742. key: '_apply',
  743. value: function _apply() {
  744. Hooker.hookLogo(function (exports) {
  745. exports.default.prototype.reset = function () {};
  746. });
  747. }
  748. }]);
  749.  
  750. return WatermarksPatch;
  751. }(Patch);
  752.  
  753. var VipPatch = function (_Patch3) {
  754. _inherits(VipPatch, _Patch3);
  755.  
  756. function VipPatch() {
  757. _classCallCheck(this, VipPatch);
  758.  
  759. return _possibleConstructorReturn(this, (VipPatch.__proto__ || Object.getPrototypeOf(VipPatch)).call(this));
  760. }
  761.  
  762. _createClass(VipPatch, [{
  763. key: '_apply',
  764. value: function _apply() {
  765. Hooker.hookUpsOnComplete(function (res) {
  766. var data = res.data;
  767. if (data.user) {
  768. data.user.vip = true;
  769. } else {
  770. data.user = { vip: true };
  771. }
  772. });
  773. }
  774. }]);
  775.  
  776. return VipPatch;
  777. }(Patch);
  778.  
  779. var QualitySettingPatch = function (_Patch4) {
  780. _inherits(QualitySettingPatch, _Patch4);
  781.  
  782. function QualitySettingPatch() {
  783. _classCallCheck(this, QualitySettingPatch);
  784.  
  785. return _possibleConstructorReturn(this, (QualitySettingPatch.__proto__ || Object.getPrototypeOf(QualitySettingPatch)).call(this));
  786. }
  787.  
  788. _createClass(QualitySettingPatch, [{
  789. key: '_apply',
  790. value: function _apply() {
  791. this._patchPreferQuality();
  792. this._patchCurrentQuality();
  793. this._addStyle();
  794. }
  795. }, {
  796. key: '_patchPreferQuality',
  797. value: function _patchPreferQuality() {
  798. Hooker.hookSetting(function (exports) {
  799. var html = exports.default.prototype.render();
  800. var autoRe = /<div\s+data-val="auto"[^<>]*>自动<\/div>/;
  801. var sdRe = /<div\s+data-val="320p"[^<>]*>标清<\/div>/;
  802. var autoDiv = autoRe.exec(html)[0];
  803. var fhdDiv = autoDiv.replace('auto', '1080p').replace('自动', '1080p');
  804. html = html.replace(autoRe, fhdDiv).replace(sdRe, '$&' + autoDiv);
  805. exports.default.prototype.render = function () {
  806. return html;
  807. };
  808. });
  809. }
  810. }, {
  811. key: '_patchCurrentQuality',
  812. value: function _patchCurrentQuality() {
  813. Hooker.hookSetting(function (exports) {
  814. var _findRecentAvaliableQuality = exports.default.prototype._findRecentAvaliableQuality;
  815. exports.default.prototype._findRecentAvaliableQuality = function (code, qualitys) {
  816. qualitys.reverse();
  817. return _findRecentAvaliableQuality.apply(this, [code, qualitys]);
  818. };
  819. });
  820.  
  821. Hooker.hookRenderQulaity(function (qualitys) {
  822. qualitys.reverse();
  823. var idx = qualitys.findIndex(function (i) {
  824. return i.code === '1080p';
  825. });
  826. if (idx !== -1) qualitys[idx].name = '1080p';
  827. });
  828. }
  829. }, {
  830. key: '_addStyle',
  831. value: function _addStyle() {
  832. GM_addStyle('\n .personalise-layer {\n width: 315px !important;\n }\n .setting-bar.setting-confirm {\n justify-content: center !important;\n }\n ');
  833. }
  834. }]);
  835.  
  836. return QualitySettingPatch;
  837. }(Patch);
  838.  
  839. var QualityFallbackPatch = function (_Patch5) {
  840. _inherits(QualityFallbackPatch, _Patch5);
  841.  
  842. function QualityFallbackPatch() {
  843. _classCallCheck(this, QualityFallbackPatch);
  844.  
  845. return _possibleConstructorReturn(this, (QualityFallbackPatch.__proto__ || Object.getPrototypeOf(QualityFallbackPatch)).call(this));
  846. }
  847.  
  848. _createClass(QualityFallbackPatch, [{
  849. key: '_apply',
  850. value: function _apply() {
  851. Hooker.hookRenderQulaity(function (qualitys, that) {
  852. return that.data.quality = that.data.preferQuality;
  853. }); // 由优先画质决定当前画质
  854. Hooker.hookSetCurrentQuality(function (that) {
  855. return that._video.global.config.quality = that.data.quality;
  856. }); // 更新config当前画质
  857. }
  858. }]);
  859.  
  860. return QualityFallbackPatch;
  861. }(Patch);
  862.  
  863. var DashboardPatch = function (_Patch6) {
  864. _inherits(DashboardPatch, _Patch6);
  865.  
  866. function DashboardPatch() {
  867. _classCallCheck(this, DashboardPatch);
  868.  
  869. return _possibleConstructorReturn(this, (DashboardPatch.__proto__ || Object.getPrototypeOf(DashboardPatch)).call(this));
  870. }
  871.  
  872. _createClass(DashboardPatch, [{
  873. key: '_apply',
  874. value: function _apply() {
  875. this._prepare();
  876. this._patch();
  877. }
  878. }, {
  879. key: '_prepare',
  880. value: function _prepare() {
  881. this._exposeDashboard();
  882. Hooker.hookPreviewLayerBind(function (that) {
  883. that._el.addEventListener('mouseover', function () {
  884. return that.emit('mouseoverpreview');
  885. });
  886. that._el.addEventListener('mouseleave', function () {
  887. return that.emit('mouseleavepreview');
  888. });
  889. });
  890. }
  891. }, {
  892. key: '_findVarName',
  893. value: function _findVarName(code) {
  894. return (/"dashboard"\s*,\s*(\w+)/.exec(code)[1]
  895. );
  896. }
  897. }, {
  898. key: '_exposeDashboard',
  899. value: function _exposeDashboard() {
  900. var _this22 = this;
  901.  
  902. Hooker.hookBase(function (code) {
  903. var varName = _this22._findVarName(code);
  904. return code.replace(/\.exports\s*=\s*(\w+)/, '$&;$1.__Dashboard=' + varName + ';');
  905. }, 'code');
  906. }
  907. }, {
  908. key: '_patch',
  909. value: function _patch() {
  910. Hooker.hookBase(function (exports) {
  911. var proto = exports.__Dashboard.prototype;
  912.  
  913. proto.bindAutoHide = function () {
  914. var _this23 = this;
  915.  
  916. this._el.addEventListener('mouseover', function () {
  917. return _this23._mouseover = true;
  918. });
  919. this._el.addEventListener('mouseleave', function () {
  920. return _this23._mouseover = false;
  921. });
  922. this.on('mouseoverpreview', function () {
  923. return _this23._mouseoverpreview = true;
  924. });
  925. this.on('mouseleavepreview', function () {
  926. return _this23._mouseoverpreview = false;
  927. });
  928. this._video.on('play', function () {
  929. if (!_this23._mouseover && !_this23._mouseoverpreview) _this23._hideTimeout = setTimeout(_this23.hide.bind(_this23), _this23._args.autoHide);
  930. });
  931. this._video.on('pause', function () {
  932. _this23._hideTimeout && clearTimeout(_this23._hideTimeout);
  933. _this23.isShow() || _this23.show();
  934. });
  935. this._parent.addEventListener('mousemove', function () {
  936. _this23._hideTimeout && clearTimeout(_this23._hideTimeout);
  937. _this23.isShow() || _this23.show();
  938. if (!_this23._isPaused() && !_this23._mouseover && !_this23._mouseoverpreview) _this23._hideTimeout = setTimeout(_this23.hide.bind(_this23), _this23._args.autoHide);
  939. });
  940. this._parent.addEventListener('mouseleave', function () {
  941. _this23._hideTimeout && clearTimeout(_this23._hideTimeout);
  942. if (!_this23._isPaused()) _this23.hide();
  943. });
  944. };
  945.  
  946. proto._isPaused = function () {
  947. return this._video._videoCore.video.paused;
  948. };
  949.  
  950. proto.isShow = function () {
  951. return this._el.style.display !== 'none';
  952. };
  953.  
  954. var show = proto.show;
  955. proto.show = function () {
  956. this.emit('dashboardshow');
  957. this._parent.style.cursor = '';
  958. show.apply(this);
  959. };
  960.  
  961. var hide = proto.hide;
  962. proto.hide = function () {
  963. this.emit('dashboardhide');
  964. this._parent.style.cursor = 'none'; // 隐藏鼠标
  965. hide.apply(this);
  966. };
  967. });
  968. }
  969. }]);
  970.  
  971. return DashboardPatch;
  972. }(Patch);
  973.  
  974. var TopAreaPatch = function (_Patch7) {
  975. _inherits(TopAreaPatch, _Patch7);
  976.  
  977. function TopAreaPatch() {
  978. _classCallCheck(this, TopAreaPatch);
  979.  
  980. return _possibleConstructorReturn(this, (TopAreaPatch.__proto__ || Object.getPrototypeOf(TopAreaPatch)).call(this));
  981. }
  982.  
  983. _createClass(TopAreaPatch, [{
  984. key: '_apply',
  985. value: function _apply() {
  986. Hooker.hookTopAreaAddEvent(function (that) {
  987. that.on('webfullscreen', function (isWebFullscreen) {
  988. isWebFullscreen ? that._showHideTop(true) : that._hideHideTop();
  989. });
  990. that.on('dashboardshow', function () {
  991. var playerState = that._video.global.playerState;
  992. if (playerState.fullscreen || playerState.webfullscreen) {
  993. that._showHideTop(true);
  994. }
  995. });
  996. that.on('dashboardhide', function () {
  997. var playerState = that._video.global.playerState;
  998. if (playerState.fullscreen || playerState.webfullscreen) {
  999. that._hideHideTop();
  1000. }
  1001. });
  1002. });
  1003. Hooker.hookResetPlayerAfter(function (that) {
  1004. // 网页全屏播放上下集重置播放器后显示顶部控件
  1005. if (!that.global.playerState.fullscreen) that._player.control.emit('webfullscreen', that.global.playerState.webfullscreen);
  1006. });
  1007. }
  1008. }]);
  1009.  
  1010. return TopAreaPatch;
  1011. }(Patch);
  1012.  
  1013. var SettingSeriesPatch = function (_Patch8) {
  1014. _inherits(SettingSeriesPatch, _Patch8);
  1015.  
  1016. function SettingSeriesPatch() {
  1017. _classCallCheck(this, SettingSeriesPatch);
  1018.  
  1019. return _possibleConstructorReturn(this, (SettingSeriesPatch.__proto__ || Object.getPrototypeOf(SettingSeriesPatch)).call(this));
  1020. }
  1021.  
  1022. _createClass(SettingSeriesPatch, [{
  1023. key: '_apply',
  1024. value: function _apply() {
  1025. Hooker.hookSettingSeries(function (exports) {
  1026. // 网页全屏显示选集
  1027. var _addEvent = exports.default.prototype._addEvent;
  1028. exports.default.prototype._addEvent = function () {
  1029. var _this26 = this;
  1030.  
  1031. _addEvent.apply(this);
  1032. this.on('webfullscreen', function (isWebFullscreen) {
  1033. if (isWebFullscreen) {
  1034. if (_this26.seriesList.length > 1) _this26._el.style.display = 'inline-block';
  1035. } else {
  1036. _this26._el.style.display = 'none';
  1037. _this26._el.classList.remove('cliced');
  1038. _this26.emit('seriesliseLayer', false);
  1039. }
  1040. });
  1041. };
  1042. });
  1043. }
  1044. }]);
  1045.  
  1046. return SettingSeriesPatch;
  1047. }(Patch);
  1048.  
  1049. var ContinuePlayPatch = function (_Patch9) {
  1050. _inherits(ContinuePlayPatch, _Patch9);
  1051.  
  1052. function ContinuePlayPatch() {
  1053. _classCallCheck(this, ContinuePlayPatch);
  1054.  
  1055. return _possibleConstructorReturn(this, (ContinuePlayPatch.__proto__ || Object.getPrototypeOf(ContinuePlayPatch)).call(this));
  1056. }
  1057.  
  1058. _createClass(ContinuePlayPatch, [{
  1059. key: '_apply',
  1060. value: function _apply() {
  1061. var _this28 = this;
  1062.  
  1063. Hooker.hookInitPlayerEvent(function (that) {
  1064. // 视频播放结束处理
  1065. that._player.control.on('ended', that._onEnd.bind(that));
  1066. that._player.control.on('ended', function () {
  1067. return _this28._onEnd(that);
  1068. });
  1069. });
  1070. }
  1071. }, {
  1072. key: '_onEnd',
  1073. value: function _onEnd(that) {
  1074. var config = that.global.config;
  1075. var playerState = that.global.playerState;
  1076. if (config.continuePlay && config.nextVid && !playerState.fullscreen) {
  1077. if (playerState.webfullscreen) {
  1078. that.playByVid({ vid: that.global.config.nextVid });
  1079. } else {
  1080. that.gotoVideo(that.global.config.nextVid);
  1081. }
  1082. }
  1083. }
  1084. }]);
  1085.  
  1086. return ContinuePlayPatch;
  1087. }(Patch);
  1088.  
  1089. var AntiAdPatch = function (_Patch10) {
  1090. _inherits(AntiAdPatch, _Patch10);
  1091.  
  1092. function AntiAdPatch() {
  1093. _classCallCheck(this, AntiAdPatch);
  1094.  
  1095. return _possibleConstructorReturn(this, (AntiAdPatch.__proto__ || Object.getPrototypeOf(AntiAdPatch)).call(this));
  1096. }
  1097.  
  1098. _createClass(AntiAdPatch, [{
  1099. key: '_apply',
  1100. value: function _apply() {
  1101. Hooker.hookGlobalConstructorAfter(function (that) {
  1102. return that.cycleData.isFront = true;
  1103. });
  1104. Hooker.hookGlobalResetAfter(function (that) {
  1105. return that.cycleData.isFront = true;
  1106. });
  1107. }
  1108. }]);
  1109.  
  1110. return AntiAdPatch;
  1111. }(Patch);
  1112.  
  1113. var WebFullscreen = function () {
  1114. function WebFullscreen(elem) {
  1115. _classCallCheck(this, WebFullscreen);
  1116.  
  1117. this._elem = elem;
  1118. }
  1119.  
  1120. _createClass(WebFullscreen, [{
  1121. key: 'isWebFullscreen',
  1122. value: function isWebFullscreen() {
  1123. return this._elem.classList.contains('webfullscreen');
  1124. }
  1125. }, {
  1126. key: 'enter',
  1127. value: function enter() {
  1128. this._elem.classList.add('webfullscreen');
  1129. document.body.style.overflow = 'hidden';
  1130.  
  1131. var parentNode = this._elem.parentNode;
  1132. while (parentNode.nodeName !== 'BODY') {
  1133. if (parentNode.nodeType === Node.ELEMENT_NODE) {
  1134. parentNode.classList.add('z-top');
  1135. }
  1136. parentNode = parentNode.parentNode;
  1137. }
  1138. }
  1139. }, {
  1140. key: 'exit',
  1141. value: function exit() {
  1142. this._elem.classList.remove('webfullscreen');
  1143. document.body.style.overflow = '';
  1144.  
  1145. var parentNode = this._elem.parentNode;
  1146. while (parentNode.nodeName !== 'BODY') {
  1147. if (parentNode.nodeType === Node.ELEMENT_NODE) {
  1148. parentNode.classList.remove('z-top');
  1149. }
  1150. parentNode = parentNode.parentNode;
  1151. }
  1152. }
  1153. }, {
  1154. key: 'toggle',
  1155. value: function toggle() {
  1156. this.isWebFullscreen() ? this.exit() : this.enter();
  1157. }
  1158. }], [{
  1159. key: 'addStyle',
  1160. value: function addStyle() {
  1161. GM_addStyle('\n .z-top {\n position: relative !important;\n z-index: 23333333 !important;\n }\n .webfullscreen {\n display: block !important;\n position: fixed !important;\n width: 100% !important;\n height: 100% !important;\n top: 0 !important;\n left: 0 !important;\n background: #000 !important;\n z-index: 23333333 !important;\n }\n ');
  1162. }
  1163. }]);
  1164.  
  1165. return WebFullscreen;
  1166. }();
  1167.  
  1168. var PlayerPatch = function (_Patch11) {
  1169. _inherits(PlayerPatch, _Patch11);
  1170.  
  1171. function PlayerPatch() {
  1172. _classCallCheck(this, PlayerPatch);
  1173.  
  1174. return _possibleConstructorReturn(this, (PlayerPatch.__proto__ || Object.getPrototypeOf(PlayerPatch)).call(this));
  1175. }
  1176.  
  1177. _createClass(PlayerPatch, [{
  1178. key: '_apply',
  1179. value: function _apply() {
  1180. this._prepare();
  1181. this._hookPlayer();
  1182. }
  1183. }, {
  1184. key: '_prepare',
  1185. value: function _prepare() {
  1186. this._customTip();
  1187. this._disablePlayAfterSeek();
  1188. this._addPrevInfo();
  1189. this._playAfterPlayerReset();
  1190. new ContinuePlayPatch().install();
  1191. }
  1192. }, {
  1193. key: '_customTip',
  1194. value: function _customTip() {
  1195. Hooker.hookTips(function (exports) {
  1196. var showHintTips = exports.default.prototype.showHintTips;
  1197. exports.default.prototype.showHintTips = function (code, info) {
  1198. if (info.msg) {
  1199. this._hintLayer.setHintShow(info.msg);
  1200. } else {
  1201. showHintTips.apply(this, [code, info]);
  1202. }
  1203. };
  1204. });
  1205. }
  1206. }, {
  1207. key: '_disablePlayAfterSeek',
  1208. value: function _disablePlayAfterSeek() {
  1209. // SingleVideoControl seek 后不自动播放
  1210. Hooker.hookBase(function (exports) {
  1211. var _setCurrentTime = exports.SingleVideoControl.prototype._setCurrentTime;
  1212. exports.SingleVideoControl.prototype._setCurrentTime = function (time) {
  1213. var play = this.video.play;
  1214. this.video.play = function () {};
  1215. _setCurrentTime.apply(this, [time]);
  1216. this.video.play = play;
  1217. };
  1218. });
  1219. }
  1220. }, {
  1221. key: '_addPrevInfo',
  1222. value: function _addPrevInfo() {
  1223. Hooker.hookGlobalDeal(function (that) {
  1224. if (that.ups && that.ups.videoData && that.ups.programList && that.ups.programList.videoList) {
  1225. var list = that.ups.programList.videoList;
  1226. var currVid = that.ups.videoData.id;
  1227. var currIdx = list.findIndex(function (item) {
  1228. return parseInt(item.vid) === currVid;
  1229. });
  1230. if (currIdx > 0) {
  1231. var prevVideo = list[currIdx - 1];
  1232. that.ups.programList.prevVideo = prevVideo;
  1233. prevVideo && (that._config.prevVid = prevVideo.encodevid);
  1234. }
  1235. }
  1236. });
  1237. }
  1238. }, {
  1239. key: '_playAfterPlayerReset',
  1240. value: function _playAfterPlayerReset() {
  1241. Hooker.hookResetPlayerAfter(function (that) {
  1242. if (that.global.playerState.state === 'playerreset') that.play();
  1243. });
  1244. }
  1245. }, {
  1246. key: '_hookPlayer',
  1247. value: function _hookPlayer() {
  1248. Hooker.hookPlayer(this._hookPlayerCallback.bind(this));
  1249. }
  1250. }, {
  1251. key: '_hookPlayerCallback',
  1252. value: function _hookPlayerCallback(exports) {
  1253. var proto = exports.default.prototype;
  1254.  
  1255. var _init = proto._init;
  1256. proto._init = function () {
  1257. _init.apply(this);
  1258. WebFullscreen.addStyle();
  1259. this._webfullscreen = new WebFullscreen(this.container);
  1260. };
  1261.  
  1262. proto._showTip = function (msg) {
  1263. this._emitter.emit('player.showinfo', { type: 'hint', msg: msg });
  1264. };
  1265.  
  1266. proto.play = function () {
  1267. this._player && this._player.control.play();
  1268. this._showTip('播放');
  1269. };
  1270.  
  1271. proto._pause = proto.pause;
  1272. proto.pause = function () {
  1273. this._pause();
  1274. this._showTip('暂停');
  1275. };
  1276.  
  1277. proto.adjustVolume = function (value) {
  1278. var volume = this.global.playerState.volume + value;
  1279. volume = Math.max(0, Math.min(1, volume.toFixed(2)));
  1280. this._player.control.setVolume(volume);
  1281. if (volume === 0) {
  1282. this._emitter.emit('player.showinfo', { type: 'hint', code: 'H0003', volume: volume + '%' });
  1283. }
  1284. };
  1285.  
  1286. proto.toggleMute = function () {
  1287. if (this.global.playerState.muted) this._showTip('取消静音');
  1288. this.setMuted(!this.global.playerState.muted);
  1289. };
  1290.  
  1291. proto.stepSeek = function (stepTime) {
  1292. var duration = this._player.control.getDuration();
  1293. var currentTime = this.global.currentTime;
  1294. var seekTime = Math.max(0, Math.min(duration, currentTime + stepTime));
  1295. this.seek(seekTime);
  1296.  
  1297. var msg = void 0;
  1298. if (Math.abs(stepTime) < 60) {
  1299. msg = stepTime > 0 ? '\u6B65\u8FDB\uFF1A' + stepTime + '\u79D2' : '\u6B65\u9000\uFF1A' + Math.abs(stepTime) + '\u79D2';
  1300. } else {
  1301. msg = stepTime > 0 ? '\u6B65\u8FDB\uFF1A' + stepTime / 60 + '\u5206\u949F' : '\u6B65\u9000\uFF1A' + Math.abs(stepTime) / 60 + '\u5206\u949F';
  1302. }
  1303. this._showTip(msg);
  1304. };
  1305.  
  1306. proto.rangeSeek = function (range) {
  1307. var duration = this._player.control.getDuration();
  1308. var seekTime = Math.max(0, Math.min(duration, duration * range));
  1309. this.seek(seekTime);
  1310. this._showTip('定位:' + (range * 100).toFixed(0) + '%');
  1311. };
  1312.  
  1313. proto.isFullscreen = function () {
  1314. return this.global.playerState.fullscreen;
  1315. };
  1316.  
  1317. proto.toggleFullscreen = function () {
  1318. if (this.isFullscreen()) {
  1319. this.exitFullscreen();
  1320. } else {
  1321. this.fullScreen();
  1322. }
  1323. };
  1324.  
  1325. proto.isWebFullscreen = function () {
  1326. return this._webfullscreen.isWebFullscreen();
  1327. };
  1328.  
  1329. proto.enterWebFullscreen = function () {
  1330. this._webfullscreen.enter();
  1331. this.global.playerState = { webfullscreen: true };
  1332. this._player.control.emit('webfullscreen', true);
  1333. };
  1334.  
  1335. proto.exitWebFullscreen = function () {
  1336. this._webfullscreen.exit();
  1337. this.global.playerState = { webfullscreen: false };
  1338. this._player.control.emit('webfullscreen', false);
  1339. };
  1340.  
  1341. proto.toggleWebFullscreen = function () {
  1342. this.isWebFullscreen() ? this.exitWebFullscreen() : this.enterWebFullscreen();
  1343. };
  1344.  
  1345. proto.adjustPlaybackRate = function (value) {
  1346. var videoCore = this._player.control._videoCore;
  1347. var rate = Math.max(0.2, Math.min(5, videoCore.video.playbackRate + value));
  1348. if (this._player.config.controlType === 'multi') {
  1349. videoCore._videoElments.forEach(function (v) {
  1350. return v.playbackRate = rate;
  1351. });
  1352. } else {
  1353. videoCore.video.playbackRate = rate;
  1354. }
  1355. this._showTip('\u64AD\u653E\u901F\u7387\uFF1A' + rate.toFixed(1).replace(/\.0+$/, ''));
  1356. };
  1357.  
  1358. proto.resetPlaybackRate = function () {
  1359. this._player.control.setRate(1);
  1360. this._showTip('恢复播放速率');
  1361. };
  1362.  
  1363. proto.getFps = function () {
  1364. return 25; // 标清fps为15,标清以上fps为25。
  1365. };
  1366.  
  1367. proto.prevFrame = function () {
  1368. var state = this.global.playerState.state;
  1369. if (state === 'playing') this.pause();
  1370. var duration = this._player.control.getDuration();
  1371. var currentTime = this.global.currentTime;
  1372. var seekTime = Math.max(0, Math.min(duration, currentTime - 1 / this.getFps()));
  1373. this.seek(seekTime);
  1374. this._showTip('上一帧');
  1375. };
  1376.  
  1377. proto.nextFrame = function () {
  1378. var state = this.global.playerState.state;
  1379. if (state === 'playing') this.pause();
  1380. var duration = this._player.control.getDuration();
  1381. var currentTime = this.global.currentTime;
  1382. var seekTime = Math.max(0, Math.min(duration, currentTime + 1 / this.getFps()));
  1383. this.seek(seekTime);
  1384. this._showTip('下一帧');
  1385. };
  1386.  
  1387. proto.playPrev = function () {
  1388. var prevVid = this.global.config.prevVid;
  1389. if (prevVid) {
  1390. if (this.isFullscreen() || this.isWebFullscreen()) {
  1391. this.playByVid({ vid: prevVid });
  1392. } else {
  1393. this.gotoVideo(prevVid);
  1394. }
  1395. this._showTip('播放上一集');
  1396. } else {
  1397. this._showTip('没有上一集哦');
  1398. }
  1399. };
  1400.  
  1401. var playNext = proto.playNext;
  1402. proto.playNext = function (data) {
  1403. if (data) playNext.apply(this, [data]);
  1404. var nextVid = this.global.config.nextVid;
  1405. if (nextVid) {
  1406. if (this.isFullscreen() || this.isWebFullscreen()) {
  1407. this.playByVid({ vid: nextVid });
  1408. } else {
  1409. this.gotoVideo(nextVid);
  1410. }
  1411. this._showTip('播放下一集');
  1412. } else {
  1413. this._showTip('没有下一集哦');
  1414. }
  1415. };
  1416.  
  1417. proto.gotoVideo = function (vid) {
  1418. location.href = '//v.youku.com/v_show/id_' + vid + '.html';
  1419. };
  1420. }
  1421. }]);
  1422.  
  1423. return PlayerPatch;
  1424. }(Patch);
  1425.  
  1426. var playerPatch = new PlayerPatch();
  1427.  
  1428. var KeyShortcutsPatch = function (_Patch12) {
  1429. _inherits(KeyShortcutsPatch, _Patch12);
  1430.  
  1431. function KeyShortcutsPatch() {
  1432. _classCallCheck(this, KeyShortcutsPatch);
  1433.  
  1434. return _possibleConstructorReturn(this, (KeyShortcutsPatch.__proto__ || Object.getPrototypeOf(KeyShortcutsPatch)).call(this));
  1435. }
  1436.  
  1437. _createClass(KeyShortcutsPatch, [{
  1438. key: '_apply',
  1439. value: function _apply() {
  1440. this._prepare();
  1441. this._addListener();
  1442. }
  1443. }, {
  1444. key: '_prepare',
  1445. value: function _prepare() {
  1446. playerPatch.install();
  1447. this._obtainPlayer();
  1448. }
  1449. }, {
  1450. key: '_obtainPlayer',
  1451. value: function _obtainPlayer() {
  1452. var self = this;
  1453. Hooker.hookKeyShortcuts(function (exports) {
  1454. exports.default.prototype.registerEvents = function () {
  1455. self._player = this._player;
  1456. };
  1457. });
  1458. }
  1459. }, {
  1460. key: '_addListener',
  1461. value: function _addListener() {
  1462. document.addEventListener('keydown', this._handler.bind(this));
  1463. }
  1464. }, {
  1465. key: '_handler',
  1466. value: function _handler(event) {
  1467. if (event.target.nodeName !== 'BODY') return;
  1468.  
  1469. switch (event.keyCode) {
  1470. case 32:
  1471. // Spacebar
  1472. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1473. var state = this._player.global.playerState.state;
  1474. if (state === 'paused') {
  1475. this._player.play();
  1476. } else if (state === 'ended') {
  1477. this._player.replay();
  1478. } else {
  1479. this._player.pause();
  1480. }
  1481. } else {
  1482. return;
  1483. }
  1484. break;
  1485. case 39: // → Arrow Right
  1486. case 37:
  1487. {
  1488. // ← Arrow Left
  1489. var stepTime = void 0;
  1490. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1491. stepTime = 39 === event.keyCode ? 5 : -5;
  1492. } else if (event.ctrlKey && !event.shiftKey && !event.altKey) {
  1493. stepTime = 39 === event.keyCode ? 30 : -30;
  1494. } else if (!event.ctrlKey && event.shiftKey && !event.altKey) {
  1495. stepTime = 39 === event.keyCode ? 60 : -60;
  1496. } else if (event.ctrlKey && !event.shiftKey && event.altKey) {
  1497. stepTime = 39 === event.keyCode ? 3e2 : -3e2; // 5分钟
  1498. } else {
  1499. return;
  1500. }
  1501. this._player.stepSeek(stepTime);
  1502. break;
  1503. }
  1504. case 38: // ↑ Arrow Up
  1505. case 40:
  1506. // ↓ Arrow Down
  1507. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1508. this._player.adjustVolume(38 === event.keyCode ? 0.05 : -0.05);
  1509. } else {
  1510. return;
  1511. }
  1512. break;
  1513. case 77:
  1514. // M
  1515. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1516. this._player.toggleMute();
  1517. } else {
  1518. return;
  1519. }
  1520. break;
  1521. case 13:
  1522. // Enter
  1523. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1524. this._player.toggleFullscreen();
  1525. } else if (event.ctrlKey && !event.shiftKey && !event.altKey) {
  1526. this._player.toggleWebFullscreen();
  1527. } else {
  1528. return;
  1529. }
  1530. break;
  1531. case 67: // C
  1532. case 88:
  1533. // X
  1534. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1535. this._player.adjustPlaybackRate(67 === event.keyCode ? 0.1 : -0.1);
  1536. } else {
  1537. return;
  1538. }
  1539. break;
  1540. case 90:
  1541. // Z
  1542. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1543. this._player.resetPlaybackRate();
  1544. } else {
  1545. return;
  1546. }
  1547. break;
  1548. case 68: // D
  1549. case 70:
  1550. // F
  1551. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1552. if (event.keyCode === 68) {
  1553. this._player.prevFrame();
  1554. } else {
  1555. this._player.nextFrame();
  1556. }
  1557. } else {
  1558. return;
  1559. }
  1560. break;
  1561. case 80: // P
  1562. case 78:
  1563. // N
  1564. if (!event.ctrlKey && event.shiftKey && !event.altKey) {
  1565. if (event.keyCode === 78) {
  1566. this._player.playNext();
  1567. } else {
  1568. this._player.playPrev();
  1569. }
  1570. } else {
  1571. return;
  1572. }
  1573. break;
  1574. default:
  1575. if (event.keyCode >= 48 && event.keyCode <= 57) {
  1576. // 0 ~ 9
  1577. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1578. this._player.rangeSeek((event.keyCode - 48) * 0.1);
  1579. } else {
  1580. return;
  1581. }
  1582. } else {
  1583. return;
  1584. }
  1585. }
  1586.  
  1587. event.preventDefault();
  1588. event.stopPropagation();
  1589. }
  1590. }]);
  1591.  
  1592. return KeyShortcutsPatch;
  1593. }(Patch);
  1594.  
  1595. var MouseShortcutsPatch = function (_Patch13) {
  1596. _inherits(MouseShortcutsPatch, _Patch13);
  1597.  
  1598. function MouseShortcutsPatch() {
  1599. _classCallCheck(this, MouseShortcutsPatch);
  1600.  
  1601. return _possibleConstructorReturn(this, (MouseShortcutsPatch.__proto__ || Object.getPrototypeOf(MouseShortcutsPatch)).call(this));
  1602. }
  1603.  
  1604. _createClass(MouseShortcutsPatch, [{
  1605. key: '_apply',
  1606. value: function _apply() {
  1607. this._prepare();
  1608. this._addListener();
  1609. }
  1610. }, {
  1611. key: '_prepare',
  1612. value: function _prepare() {
  1613. playerPatch.install();
  1614. this._addStyle();
  1615. }
  1616. }, {
  1617. key: '_addStyle',
  1618. value: function _addStyle() {
  1619. GM_addStyle('\n .h5-layer-conatiner {\n -webkit-user-select: none !important;\n -moz-user-select: none !important;\n -ms-user-select: none !important;\n user-select: none !important;\n }\n .h5-ext-layer-adsdk {\n display: none !important;\n }\n ');
  1620. }
  1621. }, {
  1622. key: '_addListener',
  1623. value: function _addListener() {
  1624. Hooker.hookInitPlayerEvent(function (that) {
  1625. var timer = void 0;
  1626. var container = that.container.querySelector('.h5-layer-conatiner');
  1627. container.addEventListener('click', function (event) {
  1628. if (event.target !== container) return;
  1629. if (timer) {
  1630. clearTimeout(timer);
  1631. timer = null;
  1632. return;
  1633. }
  1634. timer = setTimeout(function () {
  1635. var state = that.global.playerState.state;
  1636. if (state === 'paused') {
  1637. that.play();
  1638. } else if (state === 'ended') {
  1639. that.replay();
  1640. } else {
  1641. that.pause();
  1642. }
  1643. timer = null;
  1644. }, 200);
  1645. });
  1646. container.addEventListener('dblclick', function (event) {
  1647. if (event.target !== container) return;
  1648. event.ctrlKey ? that.toggleWebFullscreen() : that.toggleFullscreen();
  1649. });
  1650. container.addEventListener('wheel', function (event) {
  1651. if (event.target === container && (that.isFullscreen() || that.isWebFullscreen())) {
  1652. var delta = event.wheelDelta || event.detail || event.deltaY && -event.deltaY;
  1653. that.adjustVolume(delta > 0 ? 0.05 : -0.05);
  1654. }
  1655. });
  1656. });
  1657. }
  1658. }]);
  1659.  
  1660. return MouseShortcutsPatch;
  1661. }(Patch);
  1662.  
  1663. var ShortcutsPatch = function (_Patch14) {
  1664. _inherits(ShortcutsPatch, _Patch14);
  1665.  
  1666. function ShortcutsPatch() {
  1667. _classCallCheck(this, ShortcutsPatch);
  1668.  
  1669. return _possibleConstructorReturn(this, (ShortcutsPatch.__proto__ || Object.getPrototypeOf(ShortcutsPatch)).call(this));
  1670. }
  1671.  
  1672. _createClass(ShortcutsPatch, [{
  1673. key: '_apply',
  1674. value: function _apply() {
  1675. new KeyShortcutsPatch().install();
  1676. Logger.log('添加键盘快捷键');
  1677. new MouseShortcutsPatch().install();
  1678. Logger.log('添加鼠标快捷键');
  1679. }
  1680. }]);
  1681.  
  1682. return ShortcutsPatch;
  1683. }(Patch);
  1684.  
  1685. var H5Patch = function (_Patch15) {
  1686. _inherits(H5Patch, _Patch15);
  1687.  
  1688. function H5Patch() {
  1689. _classCallCheck(this, H5Patch);
  1690.  
  1691. return _possibleConstructorReturn(this, (H5Patch.__proto__ || Object.getPrototypeOf(H5Patch)).call(this));
  1692. }
  1693.  
  1694. _createClass(H5Patch, [{
  1695. key: '_apply',
  1696. value: function _apply() {
  1697. Hooker.hookDefine('page/find/play/player/load', this._forceH5.bind(this));
  1698. }
  1699. }, {
  1700. key: '_forceH5',
  1701. value: function _forceH5(code) {
  1702. return code.replace(/(if\s*\().*?(\)\s*\{)/, '$1true$2').replace('window.sessionStorage', 'null');
  1703. }
  1704. }]);
  1705.  
  1706. return H5Patch;
  1707. }(Patch);
  1708.  
  1709. function enableH5Player() {
  1710. new H5Patch().install();
  1711. Logger.log('启用html5播放器');
  1712. }
  1713.  
  1714. function blockAds() {
  1715. new AdBlockPatch().install();
  1716. new AntiAdPatch().install();
  1717. Logger.log('和谐广告');
  1718. }
  1719.  
  1720. function invalidateWatermarks() {
  1721. new WatermarksPatch().install();
  1722. Logger.log('和谐水印');
  1723. }
  1724.  
  1725. function invalidateQualityLimitation() {
  1726. new VipPatch().install();
  1727. Logger.log('解除会员画质限制');
  1728. }
  1729.  
  1730. function improveQualitySetting() {
  1731. new QualitySettingPatch().install();
  1732. Logger.log('设置里优先画质增加1080P选项并与当前画质对齐');
  1733. }
  1734.  
  1735. function improveQualityFallback() {
  1736. new QualityFallbackPatch().install();
  1737. Logger.log('改善当前画质逻辑');
  1738. }
  1739.  
  1740. function improveAutoHide() {
  1741. new DashboardPatch().install();
  1742. new TopAreaPatch().install();
  1743. new SettingSeriesPatch().install();
  1744. Logger.log('改善控件与光标自动隐藏');
  1745. }
  1746.  
  1747. function improveShortcuts() {
  1748. new ShortcutsPatch().install();
  1749. }
  1750.  
  1751. //=============================================================================
  1752.  
  1753. enableH5Player();
  1754. blockAds();
  1755. invalidateWatermarks();
  1756. invalidateQualityLimitation();
  1757. improveQualitySetting();
  1758. improveQualityFallback();
  1759. improveAutoHide();
  1760. improveShortcuts();
  1761. })();