iqiyi-player-switch

爱奇艺flash播放器与html5播放器随意切换,改善html5播放器播放体验。

目前为 2017-06-23 提交的版本,查看 最新版本

  1. 'use strict';
  2.  
  3. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  4.  
  5. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  6.  
  7. 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; }; }();
  8.  
  9. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10.  
  11. // ==UserScript==
  12. // @name iqiyi-player-switch
  13. // @namespace https://github.com/gooyie/userscript-iqiyi-player-switch
  14. // @homepageURL https://github.com/gooyie/userscript-iqiyi-player-switch
  15. // @supportURL https://github.com/gooyie/userscript-iqiyi-player-switch/issues
  16. // @version 1.9.0
  17. // @description 爱奇艺flash播放器与html5播放器随意切换,改善html5播放器播放体验。
  18. // @author gooyie
  19. // @license MIT License
  20. //
  21. // @include *://*.iqiyi.com/*
  22. // @include *://v.baidu.com/*
  23. // @grant GM_registerMenuCommand
  24. // @grant GM_xmlhttpRequest
  25. // @grant GM_addStyle
  26. // @grant GM_getValue
  27. // @grant GM_setValue
  28. // @grant GM_info
  29. // @grant unsafeWindow
  30. // @connect qiyi.com
  31. // @require https://greasyfork.org/scripts/29319-web-streams-polyfill/code/web-streams-polyfill.js?version=191261
  32. // @require https://greasyfork.org/scripts/29306-fetch-readablestream/code/fetch-readablestream.js?version=191832
  33. // @require https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/3.3.4/adapter.min.js
  34. // @require https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.7.0/js/md5.min.js
  35. // @run-at document-start
  36. // ==/UserScript==
  37.  
  38. (function () {
  39. 'use strict';
  40.  
  41. var PLAYER_TYPE = {
  42. Html5VOD: 'h5_VOD',
  43. FlashVOD: 'flash_VOD'
  44. };
  45. /* eslint-disable no-console */
  46.  
  47. var Logger = function () {
  48. function Logger() {
  49. _classCallCheck(this, Logger);
  50. }
  51.  
  52. _createClass(Logger, null, [{
  53. key: 'log',
  54. value: function log() {
  55. var _console;
  56.  
  57. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  58. args[_key] = arguments[_key];
  59. }
  60.  
  61. (_console = console).log.apply(_console, ['%c' + this.tag + '%c' + args.shift(), 'color: green; font-weight: bolder', 'color: blue'].concat(args));
  62. }
  63. }, {
  64. key: 'info',
  65. value: function info() {
  66. var _console2;
  67.  
  68. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  69. args[_key2] = arguments[_key2];
  70. }
  71.  
  72. (_console2 = console).info.apply(_console2, [this.tag + args.shift()].concat(args));
  73. }
  74. }, {
  75. key: 'debug',
  76. value: function debug() {
  77. var _console3;
  78.  
  79. for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  80. args[_key3] = arguments[_key3];
  81. }
  82.  
  83. (_console3 = console).debug.apply(_console3, [this.tag + args.shift()].concat(args));
  84. }
  85. }, {
  86. key: 'warn',
  87. value: function warn() {
  88. var _console4;
  89.  
  90. for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  91. args[_key4] = arguments[_key4];
  92. }
  93.  
  94. (_console4 = console).warn.apply(_console4, [this.tag + args.shift()].concat(args));
  95. }
  96. }, {
  97. key: 'error',
  98. value: function error() {
  99. var _console5;
  100.  
  101. for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  102. args[_key5] = arguments[_key5];
  103. }
  104.  
  105. (_console5 = console).error.apply(_console5, [this.tag + args.shift()].concat(args));
  106. }
  107. }, {
  108. key: 'tag',
  109. get: function get() {
  110. return '[' + GM_info.script.name + ']';
  111. }
  112. }]);
  113.  
  114. return Logger;
  115. }();
  116. /* eslint-enable no-console */
  117.  
  118.  
  119. var Cookies = function () {
  120. function Cookies() {
  121. _classCallCheck(this, Cookies);
  122. }
  123.  
  124. _createClass(Cookies, null, [{
  125. key: 'get',
  126. value: function get(key) {
  127. var value = void 0;
  128. if (new RegExp('^[^\\x00-\\x20\\x7f\\(\\)<>@,;:\\\\\\"\\[\\]\\?=\\{\\}\\/\\u0080-\\uffff]+$').test(key)) {
  129. // eslint-disable-line no-control-regex
  130. var re = new RegExp('(^| )' + key + '=([^;]*)(;|$)');
  131. var rs = re.exec(document.cookie);
  132. value = rs ? rs[2] : '';
  133. }
  134. return value ? decodeURIComponent(value) : '';
  135. }
  136. }, {
  137. key: 'set',
  138. value: function set(k, v) {
  139. var o = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  140.  
  141. var n = o.expires;
  142. if ('number' == typeof o.expires) {
  143. n = new Date();
  144. n.setTime(n.getTime() + o.expires);
  145. }
  146. var key = k;
  147. var value = encodeURIComponent(v);
  148. var path = o.path ? '; path=' + o.path : '';
  149. var expires = n ? '; expires=' + n.toGMTString() : '';
  150. var domain = o.domain ? '; domain=' + o.domain : '';
  151. document.cookie = key + '=' + value + path + expires + domain;
  152. }
  153. }, {
  154. key: 'remove',
  155. value: function remove(k) {
  156. var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  157.  
  158. o.expires = new Date(0);
  159. this.set(k, '', o);
  160. }
  161. }]);
  162.  
  163. return Cookies;
  164. }();
  165.  
  166. var Detector = function () {
  167. function Detector() {
  168. _classCallCheck(this, Detector);
  169. }
  170.  
  171. _createClass(Detector, null, [{
  172. key: 'isSupportHtml5',
  173. value: function isSupportHtml5() {
  174. var v = document.createElement('video');
  175. return !!(v.canPlayType('audio/mp4; codecs="mp4a.40.2"') && v.canPlayType('video/mp4; codecs="avc1.640029"') && v.canPlayType('video/mp4; codecs="avc1.640029, mp4a.40.2"'));
  176. }
  177. }, {
  178. key: 'isSupportVms',
  179. value: function isSupportVms() {
  180. return !!(window.MediaSource && window.URL && window.WebSocket && window.ReadableStream && (window.RTCSessionDescription || window.webkitRTCSessionDescription) && (window.RTCPeerConnection || window.webkitRTCPeerConnection) && (window.RTCIceCandidate || window.webkitRTCIceCandidate));
  181. }
  182. }, {
  183. key: 'isSupportM3u8',
  184. value: function isSupportM3u8() {
  185. var v = document.createElement('video');
  186. return !!(v.canPlayType('application/x-mpegurl') && v.canPlayType('application/vnd.apple.mpegurl'));
  187. }
  188. }, {
  189. key: 'isChrome',
  190. value: function isChrome() {
  191. return (/chrome/i.test(navigator.userAgent)
  192. );
  193. }
  194. }, {
  195. key: 'isFirefox',
  196. value: function isFirefox() {
  197. return (/firefox/i.test(navigator.userAgent)
  198. );
  199. }
  200. }, {
  201. key: 'isEdge',
  202. value: function isEdge() {
  203. return (/edge/i.test(navigator.userAgent)
  204. );
  205. }
  206. }, {
  207. key: 'isInnerFrame',
  208. value: function isInnerFrame() {
  209. return window.top !== window.self;
  210. }
  211. }, {
  212. key: 'isOutsite',
  213. value: function isOutsite() {
  214. return !/\.iqiyi\.com$/.test(location.host);
  215. }
  216. }, {
  217. key: 'isFullScreen',
  218. value: function isFullScreen() {
  219. return !!(document.fullscreen || document.webkitIsFullScreen || document.mozFullScreen || document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement);
  220. }
  221. }]);
  222.  
  223. return Detector;
  224. }();
  225.  
  226. var Hooker = function () {
  227. function Hooker() {
  228. _classCallCheck(this, Hooker);
  229. }
  230.  
  231. _createClass(Hooker, null, [{
  232. key: 'hookCall',
  233. value: function hookCall() {
  234. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  235.  
  236. var call = Function.prototype.call;
  237. Function.prototype.call = function () {
  238. for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  239. args[_key6] = arguments[_key6];
  240. }
  241.  
  242. var ret = call.apply(this, args);
  243. try {
  244. if (args) cb.apply(undefined, args);
  245. } catch (err) {
  246. Logger.error(err.stack);
  247. }
  248. return ret;
  249. };
  250.  
  251. Function.prototype.call.toString = Function.prototype.call.toLocaleString = function () {
  252. return 'function call() { [native code] }';
  253. };
  254. }
  255. }, {
  256. key: '_isFactoryCall',
  257. value: function _isFactoryCall(args) {
  258. // module.exports, module, module.exports, require
  259. return args.length === 4 && args[1] instanceof Object && args[1].hasOwnProperty('exports');
  260. }
  261. }, {
  262. key: 'hookFactoryCall',
  263. value: function hookFactoryCall() {
  264. var _this = this;
  265.  
  266. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  267.  
  268. this.hookCall(function () {
  269. for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  270. args[_key7] = arguments[_key7];
  271. }
  272.  
  273. if (_this._isFactoryCall(args)) cb.apply(undefined, args);
  274. });
  275. }
  276. }, {
  277. key: '_isJqueryFactoryCall',
  278. value: function _isJqueryFactoryCall(exports) {
  279. return exports.hasOwnProperty('fn') && exports.fn.hasOwnProperty('jquery');
  280. }
  281. }, {
  282. key: 'hookJquery',
  283. value: function hookJquery() {
  284. var _this2 = this;
  285.  
  286. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  287.  
  288. this.hookFactoryCall(function () {
  289. for (var _len8 = arguments.length, args = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
  290. args[_key8] = arguments[_key8];
  291. }
  292.  
  293. if (_this2._isJqueryFactoryCall(args[1].exports)) cb(args[1].exports);
  294. });
  295. }
  296. }, {
  297. key: 'hookJqueryAjax',
  298. value: function hookJqueryAjax() {
  299. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  300.  
  301. this.hookJquery(function (exports) {
  302. var ajax = exports.ajax.bind(exports);
  303.  
  304. exports.ajax = function (url) {
  305. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  306.  
  307. if ((typeof url === 'undefined' ? 'undefined' : _typeof(url)) === 'object') {
  308. var _ref = [url.url, url];
  309. url = _ref[0];
  310. options = _ref[1];
  311. }
  312.  
  313. var isHijacked = cb(url, options);
  314. if (isHijacked) return;
  315.  
  316. return ajax(url, options);
  317. };
  318. });
  319. }
  320. }, {
  321. key: '_isHttpFactoryCall',
  322. value: function _isHttpFactoryCall() {
  323. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  324.  
  325. return exports.hasOwnProperty('jsonp') && exports.hasOwnProperty('ajax');
  326. }
  327. }, {
  328. key: 'hookHttp',
  329. value: function hookHttp() {
  330. var _this3 = this;
  331.  
  332. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  333.  
  334. this.hookFactoryCall(function () {
  335. for (var _len9 = arguments.length, args = Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
  336. args[_key9] = arguments[_key9];
  337. }
  338.  
  339. if (_this3._isHttpFactoryCall(args[1].exports)) cb(args[1].exports);
  340. });
  341. }
  342. }, {
  343. key: 'hookHttpJsonp',
  344. value: function hookHttpJsonp() {
  345. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  346.  
  347. this.hookHttp(function (exports) {
  348. var jsonp = exports.jsonp.bind(exports);
  349.  
  350. exports.jsonp = function (options) {
  351. var isHijacked = cb(options);
  352. if (isHijacked) return;
  353. return jsonp(options);
  354. };
  355. });
  356. }
  357. }, {
  358. key: '_isLogoFactoryCall',
  359. value: function _isLogoFactoryCall() {
  360. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  361.  
  362. return 'function' === typeof exports && exports.prototype.hasOwnProperty('showLogo');
  363. }
  364. }, {
  365. key: 'hookLogo',
  366. value: function hookLogo() {
  367. var _this4 = this;
  368.  
  369. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  370.  
  371. this.hookFactoryCall(function () {
  372. for (var _len10 = arguments.length, args = Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
  373. args[_key10] = arguments[_key10];
  374. }
  375.  
  376. if (_this4._isLogoFactoryCall(args[1].exports)) cb(args[1].exports);
  377. });
  378. }
  379. }, {
  380. key: '_isFullScreenFactoryCall',
  381. value: function _isFullScreenFactoryCall() {
  382. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  383.  
  384. return exports.__proto__ && exports.__proto__.hasOwnProperty('isFullScreen');
  385. }
  386. }, {
  387. key: 'hookFullScreen',
  388. value: function hookFullScreen() {
  389. var _this5 = this;
  390.  
  391. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  392.  
  393. this.hookFactoryCall(function () {
  394. for (var _len11 = arguments.length, args = Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
  395. args[_key11] = arguments[_key11];
  396. }
  397.  
  398. if (_this5._isFullScreenFactoryCall(args[1].exports)) cb(args[1].exports);
  399. });
  400. }
  401. }, {
  402. key: '_isWebFullScreenFactoryCall',
  403. value: function _isWebFullScreenFactoryCall() {
  404. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  405.  
  406. return exports.__proto__ && exports.__proto__.hasOwnProperty('isWebFullScreen');
  407. }
  408. }, {
  409. key: 'hookWebFullScreen',
  410. value: function hookWebFullScreen() {
  411. var _this6 = this;
  412.  
  413. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  414.  
  415. this.hookFactoryCall(function () {
  416. for (var _len12 = arguments.length, args = Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
  417. args[_key12] = arguments[_key12];
  418. }
  419.  
  420. if (_this6._isWebFullScreenFactoryCall(args[1].exports)) cb(args[1].exports);
  421. });
  422. }
  423. }, {
  424. key: 'hookWebFullScreenInit',
  425. value: function hookWebFullScreenInit() {
  426. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  427.  
  428. this.hookWebFullScreen(function (exports) {
  429. var init = exports.__proto__.init;
  430. exports.__proto__.init = function (wrapper, btn) {
  431. cb(this, wrapper, btn);
  432. init.apply(this, [wrapper, btn]);
  433. };
  434. });
  435. }
  436. }, {
  437. key: '_isPluginControlsFactoryCall',
  438. value: function _isPluginControlsFactoryCall() {
  439. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  440.  
  441. return 'function' === typeof exports && exports.prototype.hasOwnProperty('initFullScreen');
  442. }
  443. }, {
  444. key: 'hookPluginControls',
  445. value: function hookPluginControls() {
  446. var _this7 = this;
  447.  
  448. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  449.  
  450. this.hookFactoryCall(function () {
  451. for (var _len13 = arguments.length, args = Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
  452. args[_key13] = arguments[_key13];
  453. }
  454.  
  455. if (_this7._isPluginControlsFactoryCall(args[1].exports)) cb(args[1].exports);
  456. });
  457. }
  458. }, {
  459. key: 'hookPluginControlsInit',
  460. value: function hookPluginControlsInit() {
  461. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  462.  
  463. this.hookPluginControls(function (exports) {
  464. var init = exports.prototype.init;
  465. exports.prototype.init = function () {
  466. cb(this);
  467. init.apply(this);
  468. };
  469. });
  470. }
  471. }, {
  472. key: 'hookInitFullScreen',
  473. value: function hookInitFullScreen() {
  474. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  475.  
  476. this.hookPluginControls(function (exports) {
  477. var initFullScreen = exports.prototype.initFullScreen;
  478. exports.prototype.initFullScreen = function () {
  479. cb(this);
  480. initFullScreen.apply(this);
  481. };
  482. });
  483. }
  484. }, {
  485. key: '_isCoreFactoryCall',
  486. value: function _isCoreFactoryCall() {
  487. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  488.  
  489. return 'function' === typeof exports && exports.prototype.hasOwnProperty('getdefaultvds') && exports.prototype.hasOwnProperty('getMovieInfo');
  490. }
  491. }, {
  492. key: 'hookCore',
  493. value: function hookCore() {
  494. var _this8 = this;
  495.  
  496. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  497.  
  498. this.hookFactoryCall(function () {
  499. for (var _len14 = arguments.length, args = Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
  500. args[_key14] = arguments[_key14];
  501. }
  502.  
  503. if (_this8._isCoreFactoryCall(args[1].exports)) cb(args[1].exports);
  504. });
  505. }
  506. }, {
  507. key: '_isSkinBaseFactoryCall',
  508. value: function _isSkinBaseFactoryCall() {
  509. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  510.  
  511. return 'function' === typeof exports && exports.prototype.hasOwnProperty('_checkPlugin');
  512. }
  513. }, {
  514. key: 'hookSkinBase',
  515. value: function hookSkinBase() {
  516. var _this9 = this;
  517.  
  518. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  519.  
  520. this.hookFactoryCall(function () {
  521. for (var _len15 = arguments.length, args = Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
  522. args[_key15] = arguments[_key15];
  523. }
  524.  
  525. if (_this9._isSkinBaseFactoryCall(args[1].exports)) cb(args[1].exports);
  526. });
  527. }
  528. }, {
  529. key: '_isPluginHotKeysFactoryCall',
  530. value: function _isPluginHotKeysFactoryCall() {
  531. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  532.  
  533. return 'function' === typeof exports && exports.prototype.hasOwnProperty('_keydown');
  534. }
  535. }, {
  536. key: 'hookPluginHotKeys',
  537. value: function hookPluginHotKeys() {
  538. var _this10 = this;
  539.  
  540. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  541.  
  542. this.hookFactoryCall(function () {
  543. for (var _len16 = arguments.length, args = Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
  544. args[_key16] = arguments[_key16];
  545. }
  546.  
  547. if (_this10._isPluginHotKeysFactoryCall(args[1].exports)) cb(args[1].exports);
  548. });
  549. }
  550. }, {
  551. key: '_isFragmentFactoryCall',
  552. value: function _isFragmentFactoryCall() {
  553. var exports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  554.  
  555. return 'function' === typeof exports && exports.prototype.hasOwnProperty('parseData');
  556. }
  557. }, {
  558. key: 'hookFragment',
  559. value: function hookFragment() {
  560. var _this11 = this;
  561.  
  562. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  563.  
  564. this.hookFactoryCall(function () {
  565. for (var _len17 = arguments.length, args = Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
  566. args[_key17] = arguments[_key17];
  567. }
  568.  
  569. if (_this11._isFragmentFactoryCall(args[1].exports)) cb(args[1].exports);
  570. });
  571. }
  572. }, {
  573. key: 'hookParseData',
  574. value: function hookParseData() {
  575. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  576.  
  577. this.hookFragment(function (exports) {
  578. var parseData = exports.prototype.parseData;
  579. exports.prototype.parseData = function () {
  580. for (var _len18 = arguments.length, args = Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
  581. args[_key18] = arguments[_key18];
  582. }
  583.  
  584. parseData.apply(this, args);
  585. cb(this);
  586. };
  587. });
  588. }
  589. }]);
  590.  
  591. return Hooker;
  592. }();
  593.  
  594. var Faker = function () {
  595. function Faker() {
  596. _classCallCheck(this, Faker);
  597. }
  598.  
  599. _createClass(Faker, null, [{
  600. key: 'fakeMacPlatform',
  601. value: function fakeMacPlatform() {
  602. var PLAFORM_MAC = 'mac';
  603. Object.defineProperty(unsafeWindow.navigator, 'platform', { get: function get() {
  604. return PLAFORM_MAC;
  605. } });
  606. }
  607. }, {
  608. key: 'fakeSafari',
  609. value: function fakeSafari() {
  610. var UA_SAFARY = 'safari';
  611. Object.defineProperty(unsafeWindow.navigator, 'userAgent', { get: function get() {
  612. return UA_SAFARY;
  613. } });
  614. }
  615. }, {
  616. key: 'fakeChrome',
  617. value: function fakeChrome() {
  618. var UA_CHROME = 'chrome';
  619. Object.defineProperty(unsafeWindow.navigator, 'userAgent', { get: function get() {
  620. return UA_CHROME;
  621. } });
  622. }
  623. }, {
  624. key: '_calcSign',
  625. value: function _calcSign(authcookie) {
  626. var RESPONSE_KEY = '-0J1d9d^ESd)9jSsja';
  627. return md5(authcookie.substring(5, 39).split('').reverse().join('') + '<1<' + RESPONSE_KEY);
  628. }
  629. }, {
  630. key: 'fakeVipRes',
  631. value: function fakeVipRes(authcookie) {
  632. var json = {
  633. code: 'A00000',
  634. data: {
  635. sign: this._calcSign(authcookie)
  636. }
  637. };
  638. return json;
  639. }
  640. }, {
  641. key: 'fakeAdRes',
  642. value: function fakeAdRes() {
  643. var json = {};
  644. return json;
  645. }
  646. }, {
  647. key: 'fakePassportCookie',
  648. value: function fakePassportCookie() {
  649. Cookies.set('P00001', 'faked_passport', { domain: '.iqiyi.com' });
  650. Logger.log('faked passport cookie');
  651. }
  652. }]);
  653.  
  654. return Faker;
  655. }();
  656.  
  657. var Mocker = function () {
  658. function Mocker() {
  659. _classCallCheck(this, Mocker);
  660. }
  661.  
  662. _createClass(Mocker, null, [{
  663. key: 'mock',
  664. value: function mock() {
  665. this.mockForBestDefintion();
  666. this.mockAd();
  667. this.mockVip();
  668. this.mockLogo();
  669. this.mockCheckPlugin();
  670. }
  671. }, {
  672. key: 'mockToUseVms',
  673. value: function mockToUseVms() {
  674. Faker.fakeChrome();
  675. }
  676. }, {
  677. key: 'mockToUseM3u8',
  678. value: function mockToUseM3u8() {
  679. Faker.fakeMacPlatform();
  680. Faker.fakeSafari();
  681. }
  682. }, {
  683. key: '_isVideoReq',
  684. value: function _isVideoReq(url) {
  685. return (/^https?:\/\/(?:\d+.?){4}\/videos\/v.*$/.test(url)
  686. );
  687. }
  688. }, {
  689. key: 'mockForBestDefintion',
  690. value: function mockForBestDefintion() {
  691. var _this12 = this;
  692.  
  693. // apply shims
  694. if (Detector.isFirefox()) {
  695. var fetch = unsafeWindow.fetch.bind(unsafeWindow);
  696.  
  697. unsafeWindow.fetch = function (url, opts) {
  698. if (_this12._isVideoReq(url)) {
  699. Logger.log('fetching stream ' + url);
  700. return fetchStream(url, opts); // xhr with moz-chunked-arraybuffer
  701. } else {
  702. return fetch(url, opts);
  703. }
  704. };
  705. } else if (Detector.isEdge()) {
  706. // export to the global window object
  707. unsafeWindow.RTCIceCandidate = window.RTCIceCandidate;
  708. unsafeWindow.RTCPeerConnection = window.RTCPeerConnection;
  709. unsafeWindow.RTCSessionDescription = window.RTCSessionDescription;
  710. }
  711. // auto fall-back
  712. if (Detector.isSupportVms()) {
  713. if (!Detector.isChrome()) this.mockToUseVms(); // vms, 1080p or higher
  714. } else if (Detector.isSupportM3u8()) {
  715. this.mockToUseM3u8(); // tmts m3u8
  716. } else {
  717. // by default, tmts mp4 ...
  718. }
  719. }
  720. }, {
  721. key: '_isAdReq',
  722. value: function _isAdReq(url) {
  723. var AD_URL = 'http://t7z.cupid.iqiyi.com/show2';
  724. return url.indexOf(AD_URL) === 0;
  725. }
  726. }, {
  727. key: 'mockAd',
  728. value: function mockAd() {
  729. var _this13 = this;
  730.  
  731. Hooker.hookJqueryAjax(function (url, options) {
  732. if (_this13._isAdReq(url)) {
  733. var res = Faker.fakeAdRes();
  734. (options.complete || options.success)({ responseJSON: res }, 'success');
  735. Logger.log('mocked ad request ' + url);
  736. return true;
  737. }
  738. });
  739. }
  740. }, {
  741. key: '_isCheckVipReq',
  742. value: function _isCheckVipReq(url) {
  743. var CHECK_VIP_URL = 'https://cmonitor.iqiyi.com/apis/user/check_vip.action';
  744. return url === CHECK_VIP_URL;
  745. }
  746. }, {
  747. key: '_isLogin',
  748. value: function _isLogin() {
  749. return !!Cookies.get('P00001');
  750. }
  751. }, {
  752. key: 'mockVip',
  753. value: function mockVip() {
  754. var _this14 = this;
  755.  
  756. if (!this._isLogin()) Faker.fakePassportCookie();
  757.  
  758. Hooker.hookHttpJsonp(function (options) {
  759. var url = options.url;
  760.  
  761. if (_this14._isCheckVipReq(url)) {
  762. var res = Faker.fakeVipRes(options.params.authcookie);
  763. options.success(res);
  764. Logger.log('mocked check vip request ' + url);
  765. return true;
  766. }
  767. });
  768. }
  769. }, {
  770. key: 'mockLogo',
  771. value: function mockLogo() {
  772. Hooker.hookLogo(function (exports) {
  773. return exports.prototype.showLogo = function () {};
  774. });
  775. }
  776. }, {
  777. key: 'mockCheckPlugin',
  778. value: function mockCheckPlugin() {
  779. Hooker.hookSkinBase(function (exports) {
  780. exports.prototype._checkPlugin = function () {};
  781. });
  782. }
  783. }]);
  784.  
  785. return Mocker;
  786. }();
  787.  
  788. var Patcher = function () {
  789. function Patcher() {
  790. _classCallCheck(this, Patcher);
  791. }
  792.  
  793. _createClass(Patcher, null, [{
  794. key: '_patchWebFullScreen',
  795. value: function _patchWebFullScreen() {
  796. Hooker.hookWebFullScreenInit(function (that, wrapper, btn) {
  797. btn.on('toggle', that.toggle.bind(that));
  798. });
  799. }
  800. }, {
  801. key: '_patchInitFullScreen',
  802. value: function _patchInitFullScreen() {
  803. this._patchWebFullScreen();
  804.  
  805. Hooker.hookInitFullScreen(function (that) {
  806. that.core.on('togglefullscreen', function () {
  807. that._fullscreenBtn.fire('click', { data: null });
  808. });
  809.  
  810. that.core.on('togglewebfullscreen', function () {
  811. that._webfullscreenBtn.fire('toggle', { data: null });
  812. });
  813. });
  814. }
  815. }, {
  816. key: '_patchPluginControls',
  817. value: function _patchPluginControls() {
  818. Hooker.hookPluginControlsInit(function (that) {
  819. that.core.on('showtip', function (event) {
  820. that.setcontroltip.apply(that, [{ str: event.data, x: that._process.offset().left, y: 3, cut: true, timeout: true }]);
  821. if (that.$plugin.hasClass('process_hidden')) {
  822. that._controltips.css('top', '-25px');
  823. } else if (that.$plugin.hasClass('bottom-hide')) {
  824. that._controltips.css('top', '-38px');
  825. }
  826. });
  827. });
  828. }
  829. }, {
  830. key: '_obtainFlvInfo',
  831. value: function _obtainFlvInfo() {
  832. var _this15 = this;
  833.  
  834. Hooker.hookParseData(function (that) {
  835. return _this15._flvInfo = that.flvInfo;
  836. });
  837. }
  838. }, {
  839. key: '_patchCore',
  840. value: function _patchCore() {
  841. var self = this;
  842.  
  843. this._patchPluginControls();
  844. this._patchInitFullScreen();
  845. this._obtainFlvInfo();
  846.  
  847. Hooker.hookCore(function (exports) {
  848. exports.prototype._showTip = function (msg) {
  849. this.fire({ type: 'showtip', data: msg });
  850. };
  851.  
  852. exports.prototype.getFPS = function () {
  853. if (self._flvInfo) {
  854. return self._flvInfo.videoConfigTag.sps.frame_rate.fps;
  855. } else {
  856. return 25; // f4v极速以上,动画23.976、电影24、电视剧25。
  857. }
  858. };
  859.  
  860. exports.prototype.previousFrame = function () {
  861. var video = this.video();
  862. var seekTime = Math.max(0, Math.min(this.getDuration(), video.currentTime - 1 / this.getFPS()));
  863. video.currentTime = seekTime;
  864. this._showTip('上一帧');
  865. };
  866.  
  867. exports.prototype.nextFrame = function () {
  868. var video = this.video();
  869. var seekTime = Math.max(0, Math.min(this.getDuration(), video.currentTime + 1 / this.getFPS()));
  870. video.currentTime = seekTime;
  871. this._showTip('下一帧');
  872. };
  873.  
  874. exports.prototype.stepSeek = function (stepTime) {
  875. var seekTime = Math.max(0, Math.min(this.getDuration(), this.getCurrenttime() + stepTime));
  876. var msg = void 0;
  877.  
  878. if (Math.abs(stepTime) < 60) {
  879. msg = stepTime > 0 ? '\u6B65\u8FDB\uFF1A' + stepTime + '\u79D2' : '\u6B65\u9000\uFF1A' + Math.abs(stepTime) + '\u79D2';
  880. } else {
  881. msg = stepTime > 0 ? '\u6B65\u8FDB\uFF1A' + stepTime / 60 + '\u5206\u949F' : '\u6B65\u9000\uFF1A' + Math.abs(stepTime) / 60 + '\u5206\u949F';
  882. }
  883. this._showTip(msg);
  884.  
  885. this.seek(seekTime, true);
  886. };
  887.  
  888. exports.prototype.rangeSeek = function (range) {
  889. var duration = this.getDuration();
  890. var seekTime = Math.max(0, Math.min(duration, duration * range));
  891. this.seek(seekTime, true);
  892. this._showTip('定位:' + (range * 100).toFixed(0) + '%');
  893. };
  894.  
  895. exports.prototype.toggleMute = function () {
  896. if (this.getMuted()) {
  897. this.setMuted(false);
  898. this._showTip('取消静音');
  899. } else {
  900. this.setMuted(true);
  901. this._showTip('静音');
  902. }
  903. };
  904.  
  905. exports.prototype.adjustVolume = function (value) {
  906. var volume = this.getVolume() + value;
  907. volume = Math.max(0, Math.min(1, volume.toFixed(2)));
  908. this.setVolume(volume);
  909. this.fire({ type: 'keyvolumechange' });
  910. };
  911.  
  912. exports.prototype.adjustPlaybackRate = function (value) {
  913. var video = this.video();
  914. var playbackRate = Math.max(0.2, Math.min(5, video.playbackRate + value));
  915. video.playbackRate = playbackRate;
  916. this._showTip('\u64AD\u653E\u901F\u7387\uFF1A' + playbackRate.toFixed(1).replace(/\.0+$/, ''));
  917. };
  918.  
  919. exports.prototype.resetPlaybackRate = function () {
  920. var video = this.video();
  921. video.playbackRate = 1;
  922. this._showTip('恢复播放速率');
  923. };
  924.  
  925. exports.prototype.hasPreVideo = function () {
  926. return this._getVideoIndexInList(this._movieinfo.tvid) > 0 || this._getVideoIndexInList(this._movieinfo.oldTvid) > 0;
  927. };
  928.  
  929. exports.prototype.playNext = function () {
  930. if (this.hasNextVideo()) {
  931. this._showTip('播放下一集');
  932. this.switchNextVideo();
  933. } else {
  934. this._showTip('没有下一集哦');
  935. }
  936. };
  937.  
  938. exports.prototype.playPre = function () {
  939. if (this.hasPreVideo()) {
  940. this._showTip('播放上一集');
  941. this.switchPreVideo();
  942. } else {
  943. this._showTip('没有上一集哦');
  944. }
  945. };
  946. });
  947. }
  948. }, {
  949. key: '_patchKeyShortcuts',
  950. value: function _patchKeyShortcuts() {
  951. Hooker.hookPluginHotKeys(function (exports) {
  952. exports.prototype.init = function () {
  953. document.addEventListener('keydown', this._keydown.bind(this));
  954. };
  955.  
  956. exports.prototype._isValidTarget = function (target) {
  957. return target.nodeName === 'BODY' || target.nodeName == 'VIDEO' || target.classList.contains('pw-video'); // 全局
  958. // return target.nodeName === 'VIDEO' || target.classList.contains('pw-video'); // 非全局
  959. };
  960.  
  961. exports.prototype._keydown = function (event) {
  962. if (!this._isValidTarget(event.target)) return;
  963.  
  964. switch (event.keyCode) {
  965. case 32:
  966. // Spacebar
  967. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  968. if (this.core.isPaused()) {
  969. this.core.play(true);
  970. this.core._showTip('播放');
  971. } else {
  972. this.core.pause(true);
  973. this.core._showTip('暂停');
  974. }
  975. } else {
  976. return;
  977. }
  978. break;
  979. case 39: // → Arrow Right
  980. case 37:
  981. {
  982. // ← Arrow Left
  983. var stepTime = void 0;
  984. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  985. stepTime = 39 === event.keyCode ? 5 : -5;
  986. } else if (event.ctrlKey && !event.shiftKey && !event.altKey) {
  987. stepTime = 39 === event.keyCode ? 30 : -30;
  988. } else if (!event.ctrlKey && event.shiftKey && !event.altKey) {
  989. stepTime = 39 === event.keyCode ? 60 : -60;
  990. } else if (event.ctrlKey && !event.shiftKey && event.altKey) {
  991. stepTime = 39 === event.keyCode ? 3e2 : -3e2; // 5分钟
  992. } else {
  993. return;
  994. }
  995.  
  996. this.core.stepSeek(stepTime);
  997. break;
  998. }
  999. case 38: // ↑ Arrow Up
  1000. case 40:
  1001. // ↓ Arrow Down
  1002. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1003. this.core.adjustVolume(38 === event.keyCode ? 0.05 : -0.05);
  1004. } else {
  1005. return;
  1006. }
  1007. break;
  1008. case 77:
  1009. // M
  1010. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1011. this.core.toggleMute();
  1012. } else {
  1013. return;
  1014. }
  1015. break;
  1016. case 13:
  1017. // Enter
  1018. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1019. this.core.fire({ type: 'togglefullscreen' });
  1020. } else if (event.ctrlKey && !event.shiftKey && !event.altKey) {
  1021. this.core.fire({ type: 'togglewebfullscreen' });
  1022. } else {
  1023. return;
  1024. }
  1025. break;
  1026. case 67: // C
  1027. case 88:
  1028. // X
  1029. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1030. this.core.adjustPlaybackRate(67 === event.keyCode ? 0.1 : -0.1);
  1031. } else {
  1032. return;
  1033. }
  1034. break;
  1035. case 90:
  1036. // Z
  1037. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1038. this.core.resetPlaybackRate();
  1039. } else {
  1040. return;
  1041. }
  1042. break;
  1043. case 68: // D
  1044. case 70:
  1045. // F
  1046. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1047. this.core.pause(true);
  1048. if (event.keyCode === 68) {
  1049. this.core.previousFrame();
  1050. } else {
  1051. this.core.nextFrame();
  1052. }
  1053. } else {
  1054. return;
  1055. }
  1056. break;
  1057. case 80: // P
  1058. case 78:
  1059. // N
  1060. if (!event.ctrlKey && event.shiftKey && !event.altKey) {
  1061. if (event.keyCode === 78) {
  1062. this.core.playNext();
  1063. } else {
  1064. this.core.playPre();
  1065. }
  1066. } else {
  1067. return;
  1068. }
  1069. break;
  1070. default:
  1071. if (event.keyCode >= 48 && event.keyCode <= 57) {
  1072. // 0 ~ 9
  1073. if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
  1074. this.core.rangeSeek((event.keyCode - 48) * 0.1);
  1075. } else {
  1076. return;
  1077. }
  1078. } else {
  1079. return;
  1080. }
  1081. }
  1082.  
  1083. event.preventDefault();
  1084. event.stopPropagation();
  1085. };
  1086.  
  1087. Logger.log('添加键盘快捷键');
  1088. });
  1089. }
  1090. }, {
  1091. key: '_patchMouseShortcuts',
  1092. value: function _patchMouseShortcuts() {
  1093. Hooker.hookPluginControlsInit(function (that) {
  1094. document.addEventListener('wheel', function (event) {
  1095. if (!Detector.isFullScreen()) return;
  1096.  
  1097. var delta = event.wheelDelta || event.detail || event.deltaY && -event.deltaY;
  1098. that.core.adjustVolume(delta > 0 ? 0.05 : -0.05);
  1099. });
  1100.  
  1101. Logger.log('添加鼠标快捷键');
  1102. });
  1103. }
  1104. }, {
  1105. key: 'patchShortcuts',
  1106. value: function patchShortcuts() {
  1107. this._patchCore();
  1108.  
  1109. this._patchKeyShortcuts();
  1110. this._patchMouseShortcuts();
  1111. }
  1112. }]);
  1113.  
  1114. return Patcher;
  1115. }();
  1116.  
  1117. var Switcher = function () {
  1118. function Switcher() {
  1119. _classCallCheck(this, Switcher);
  1120. }
  1121.  
  1122. _createClass(Switcher, null, [{
  1123. key: 'switchTo',
  1124. value: function switchTo(toType) {
  1125. Logger.log('switching to ' + toType + ' ...');
  1126.  
  1127. GM_setValue('player_forcedType', toType);
  1128. document.location.reload();
  1129. }
  1130. }]);
  1131.  
  1132. return Switcher;
  1133. }();
  1134.  
  1135. var Finder = function () {
  1136. function Finder() {
  1137. _classCallCheck(this, Finder);
  1138. }
  1139.  
  1140. _createClass(Finder, null, [{
  1141. key: 'findVid',
  1142. value: function findVid(text) {
  1143. var result = /vid=([\da-z]+)/.exec(text);
  1144. return result ? result[1] : null;
  1145. }
  1146. }, {
  1147. key: 'findTvid',
  1148. value: function findTvid(text) {
  1149. var result = /tvId=(\d+)/.exec(text);
  1150. return result ? result[1] : null;
  1151. }
  1152. }, {
  1153. key: 'findEmbedNodes',
  1154. value: function findEmbedNodes() {
  1155. var nodes = document.querySelectorAll('object, embed');
  1156. return nodes.length > 0 ? nodes : null;
  1157. }
  1158. }]);
  1159.  
  1160. return Finder;
  1161. }();
  1162.  
  1163. function getVideoUrl(tvid, vid) {
  1164. return new Promise(function (resolve, reject) {
  1165. GM_xmlhttpRequest({
  1166. url: 'http://cache.video.qiyi.com/jp/vi/' + tvid + '/' + vid + '/?callback=callback',
  1167. method: 'GET',
  1168. timeout: 8e3,
  1169. onload: function onload(details) {
  1170. try {
  1171. var json = JSON.parse(/callback\s*\(\s*(\{.*\})\s*\)/.exec(details.responseText)[1]);
  1172. resolve(json.vu);
  1173. } catch (err) {
  1174. reject(err);
  1175. }
  1176. },
  1177. onerror: reject,
  1178. onabort: reject,
  1179. ontimeout: reject
  1180. });
  1181. });
  1182. }
  1183.  
  1184. function embedSrc(targetNode, _ref2) {
  1185. var tvid = _ref2.tvid,
  1186. vid = _ref2.vid;
  1187.  
  1188. targetNode.innerHTML = '<div class="' + GM_info.script.name + ' info">\u6B63\u5728\u83B7\u53D6\u89C6\u9891\u6E90...</div>';
  1189.  
  1190. getVideoUrl(tvid, vid).then(function (url) {
  1191. targetNode.innerHTML = '<iframe id="innerFrame" src="' + url + '" frameborder="0" allowfullscreen="true" width="100%" height="100%"></iframe>';
  1192. }).catch(function (err) {
  1193. targetNode.innerHTML = '<div class="' + GM_info.script.name + ' error"><p>\u83B7\u53D6\u89C6\u9891\u6E90\u51FA\u9519\uFF01</p><p>' + err.message + '</p></div>';
  1194. });
  1195. }
  1196.  
  1197. function replaceFlash() {
  1198. var observer = new MutationObserver(function (records, self) {
  1199. var _iteratorNormalCompletion = true;
  1200. var _didIteratorError = false;
  1201. var _iteratorError = undefined;
  1202.  
  1203. try {
  1204. for (var _iterator = records[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  1205. var record = _step.value;
  1206.  
  1207. if (record.type !== 'childList' || !record.addedNodes) continue;
  1208.  
  1209. var _iteratorNormalCompletion2 = true;
  1210. var _didIteratorError2 = false;
  1211. var _iteratorError2 = undefined;
  1212.  
  1213. try {
  1214. for (var _iterator2 = record.addedNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  1215. var node = _step2.value;
  1216.  
  1217. if (node.nodeName !== 'OBJECT' && node.nodeName !== 'EMBED') continue;
  1218.  
  1219. var text = node.outerHTML;
  1220. var vid = Finder.findVid(text);
  1221. var tvid = Finder.findTvid(text);
  1222.  
  1223. if (tvid && vid) {
  1224. Logger.log('finded player', node);
  1225. embedSrc(node.parentNode, { tvid: tvid, vid: vid });
  1226. self.disconnect();
  1227. Logger.log('stoped observation');
  1228. }
  1229. }
  1230. } catch (err) {
  1231. _didIteratorError2 = true;
  1232. _iteratorError2 = err;
  1233. } finally {
  1234. try {
  1235. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  1236. _iterator2.return();
  1237. }
  1238. } finally {
  1239. if (_didIteratorError2) {
  1240. throw _iteratorError2;
  1241. }
  1242. }
  1243. }
  1244. }
  1245. } catch (err) {
  1246. _didIteratorError = true;
  1247. _iteratorError = err;
  1248. } finally {
  1249. try {
  1250. if (!_iteratorNormalCompletion && _iterator.return) {
  1251. _iterator.return();
  1252. }
  1253. } finally {
  1254. if (_didIteratorError) {
  1255. throw _iteratorError;
  1256. }
  1257. }
  1258. }
  1259. });
  1260.  
  1261. observer.observe(document.body || document.documentElement, { subtree: true, childList: true });
  1262. Logger.log('started observation');
  1263. }
  1264.  
  1265. function adapteIframe() {
  1266. var style = '\n body[class|="qypage"] {\n overflow: hidden !important;\n background: #000 !important;\n visibility: hidden;\n }\n\n .mod-func {\n display: none !important;\n }\n\n .' + GM_info.script.name + '.info {\n width: 20em;\n height: 5em;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n margin: auto;\n text-align: center;\n line-height: 5em;\n font-size: 1em;\n color: #ccc;\n }\n\n .' + GM_info.script.name + '.error {\n height: 3em;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n margin: auto;\n text-align: center;\n font-size: 1em;\n color: #c00;\n }\n ';
  1267.  
  1268. GM_addStyle(style);
  1269.  
  1270. Hooker.hookWebFullScreen(function (exports) {
  1271. var init = exports.__proto__.init;
  1272. exports.__proto__.init = function (wrapper, btn) {
  1273. init.apply(this, [wrapper, btn]);
  1274. this.enter();
  1275.  
  1276. btn[0].style.display = 'none';
  1277. document.body.style.visibility = 'visible';
  1278. };
  1279.  
  1280. exports.__proto__.exit = function () {};
  1281. });
  1282.  
  1283. Hooker.hookCore(function (exports) {
  1284. exports.prototype.hasNextVideo = function () {
  1285. return null;
  1286. };
  1287. });
  1288. }
  1289.  
  1290. function forceHtml5() {
  1291. Logger.log('setting player_forcedType cookie as ' + PLAYER_TYPE.Html5VOD);
  1292. Cookies.set('player_forcedType', PLAYER_TYPE.Html5VOD, { domain: '.iqiyi.com' });
  1293. }
  1294.  
  1295. function forceFlash() {
  1296. Logger.log('setting player_forcedType cookie as ' + PLAYER_TYPE.FlashVOD);
  1297. Cookies.set('player_forcedType', PLAYER_TYPE.FlashVOD, { domain: '.iqiyi.com' });
  1298. }
  1299.  
  1300. function clean() {
  1301. Cookies.remove('player_forcedType', { domain: '.iqiyi.com' });
  1302. if (Cookies.get('P00001') === 'faked_passport') Cookies.remove('P00001', { domain: '.iqiyi.com' });
  1303. Logger.log('removed cookies.');
  1304. }
  1305.  
  1306. function registerMenu() {
  1307. var MENU_NAME = {
  1308. HTML5: 'HTML5播放器',
  1309. FLASH: 'Flash播放器'
  1310. };
  1311.  
  1312. var currType = GM_getValue('player_forcedType', PLAYER_TYPE.Html5VOD); // 默认为Html5播放器,免去切换。
  1313.  
  1314. var _ref3 = currType === PLAYER_TYPE.Html5VOD ? [PLAYER_TYPE.FlashVOD, MENU_NAME.FLASH] : [PLAYER_TYPE.Html5VOD, MENU_NAME.HTML5],
  1315. _ref4 = _slicedToArray(_ref3, 2),
  1316. toType = _ref4[0],
  1317. name = _ref4[1];
  1318.  
  1319. GM_registerMenuCommand(name, function () {
  1320. return Switcher.switchTo(toType);
  1321. }, null);
  1322. Logger.log('registered menu.');
  1323. }
  1324.  
  1325. //=============================================================================
  1326.  
  1327. registerMenu();
  1328.  
  1329. var currType = GM_getValue('player_forcedType', PLAYER_TYPE.Html5VOD);
  1330. if (currType === PLAYER_TYPE.Html5VOD) {
  1331. if (!Detector.isSupportHtml5()) {
  1332. alert('╮(╯▽╰)╭ 你的浏览器播放不了html5视频~~~~');
  1333. return;
  1334. }
  1335.  
  1336. forceHtml5();
  1337. Mocker.mock();
  1338. Patcher.patchShortcuts();
  1339.  
  1340. if (Detector.isInnerFrame()) adapteIframe();
  1341. if (Detector.isOutsite()) replaceFlash();
  1342. } else {
  1343. forceFlash();
  1344. }
  1345.  
  1346. window.addEventListener('unload', function () {
  1347. return clean();
  1348. });
  1349. })();