HTML5 Video Player Enhance

To enhance the functionality of HTML5 Video Player (h5player) supporting all websites using shortcut keys similar to PotPlayer.

当前为 2021-06-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HTML5 Video Player Enhance
  3. // @version 2.9.4.1
  4. // @description To enhance the functionality of HTML5 Video Player (h5player) supporting all websites using shortcut keys similar to PotPlayer.
  5. // @author CY Fung
  6. // @match http://*/*
  7. // @match https://*/*
  8. // @run-at document-start
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/js-sha256/0.9.0/sha256.min.js
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/mathjs/9.3.2/math.js
  11. // @namespace https://greasyfork.org/users/371179
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant unsafeWindow
  15. // ==/UserScript==
  16.  
  17.  
  18. /**
  19. * Remarks
  20. * This script support modern browser only with ES6+.
  21. * fullscreen and pointerLock buggy in shadowRoot
  22. * Space Pause not success
  23. * shift F key issue
  24. **/
  25. (function $$($$uWin) {
  26. 'use strict';
  27.  
  28. if (!document || !document.documentElement) return window.requestAnimationFrame($$);
  29.  
  30. const $qmt=($$uWin.queueMicrotask?$$uWin.queueMicrotask:function (callback) {
  31. Promise.resolve()
  32. .then(callback)
  33. .catch(e => setTimeout(() => { throw e; })); // report exceptions
  34. }).bind($$uWin)
  35.  
  36. const $bz={boosted:false}
  37. //document.nmm=[]
  38.  
  39. !(function(window) {
  40.  
  41.  
  42. const $$setTimeout = window.setTimeout
  43. const $$clearTimeout = window.clearTimeout
  44. const $$requestAnimationFrame = window.requestAnimationFrame;
  45. const $$cancelAnimationFrame = window.cancelAnimationFrame;
  46.  
  47. const $$bind = Function.prototype.bind
  48. Function.prototype.bind=function(){
  49. const bf=$$bind.apply(this,arguments)
  50. bf.__bind_func__=[...arguments]
  51. return bf
  52. }
  53.  
  54. window.setTimeout = function() {
  55. let f = arguments[0]
  56. let d = arguments[1] || 0;
  57. let res;
  58. //if($bz.boosted) document.nmm.push(d)
  59.  
  60. if ($bz.boosted && typeof f == 'function' && (arguments.length == 2 || arguments.length == 1)) {
  61. // f : function arguments.length = 1 or 2
  62. // setTimeout(f,d)
  63. if(d>40){
  64. if(!f.__timeout__g__){
  65. f.__timeout__g__= function(){
  66. $qmt(()=>f.apply(this,arguments))
  67. }
  68. }
  69. res = $$setTimeout.call(window, f.__timeout__g__, d)
  70. if (res > 0) res = res << 1;
  71. return res;
  72. }else{
  73. //1000/40=25
  74. res = $$requestAnimationFrame.call(window, f)
  75. if (res > 0) {
  76. res = res << 1;
  77. res |= 1;
  78. }
  79. }
  80. return res;
  81. }
  82. res = $$setTimeout.apply(this, arguments)
  83. if (res > 0) res = res << 1;
  84. return res;
  85. }
  86.  
  87. window.clearTimeout = function() {
  88. let cid = arguments[0]
  89. if (cid > 0) {
  90. let res;
  91. if (cid & 1) {
  92. cid = cid >> 1;
  93. res = $$cancelAnimationFrame.call(window, cid);
  94. } else {
  95. arguments[0] = arguments[0] >> 1;
  96. res = $$clearTimeout.apply(this, arguments);
  97. }
  98. return res;
  99. } else {
  100. return $$clearTimeout.apply(this, arguments);
  101. }
  102. }
  103.  
  104. })(window.unsafeWindow || window);
  105.  
  106.  
  107. const $$vPlay = HTMLVideoElement.prototype.play
  108. const $$vPause = HTMLVideoElement.prototype.pause
  109. HTMLVideoElement.prototype.play=function(){
  110.  
  111. return new Promise((resolve, reject)=>{
  112. $qmt(()=>{
  113.  
  114. if(this.__play_cid__>0) window.cancelAnimationFrame(this.__play_cid__);
  115.  
  116. this.__play_cid__=window.requestAnimationFrame(()=>{
  117.  
  118. if(this.__play_cid__>0){
  119. this.__play_cid__=0;
  120. if(this.paused){
  121.  
  122. $$vPlay.call(this).then(resolve).catch(e=>{
  123.  
  124. if(e instanceof DOMException)return;
  125. throw e;
  126.  
  127. })
  128.  
  129. }
  130. }
  131.  
  132. })
  133.  
  134. })
  135.  
  136. })
  137.  
  138. }
  139.  
  140.  
  141. HTMLVideoElement.prototype.pause=function(){
  142.  
  143.  
  144. $qmt(()=>{
  145.  
  146.  
  147. if(this.__play_cid__>0) this.__play_cid__=window.cancelAnimationFrame(this.__play_cid__);
  148.  
  149. this.__play_cid__=window.requestAnimationFrame(()=>{
  150. if(this.__play_cid__>0){
  151. this.__play_cid__=0;
  152.  
  153.  
  154. if(!this.paused){
  155. $$vPause.call(this)
  156.  
  157.  
  158.  
  159. }
  160.  
  161. }
  162.  
  163.  
  164. })
  165. })
  166.  
  167.  
  168. }
  169.  
  170.  
  171.  
  172. let _debug_h5p_logging_ = false;
  173.  
  174. try {
  175. _debug_h5p_logging_ = +window.localStorage.getItem('_h5_player_sLogging_') > 0
  176. } catch (e) {}
  177.  
  178.  
  179.  
  180. const SHIFT = 1;
  181. const CTRL = 2;
  182. const ALT = 4;
  183. const TERMINATE = 0x842;
  184. const _sVersion_ = 1817;
  185. const str_postMsgData = '__postMsgData__'
  186. const DOM_ACTIVE_FOUND = 1;
  187. const DOM_ACTIVE_SRC_LOADED = 2;
  188. const DOM_ACTIVE_ONCE_PLAYED = 4;
  189. const DOM_ACTIVE_MOUSE_CLICK = 8;
  190. const DOM_ACTIVE_MOUSE_IN = 16;
  191. const DOM_ACTIVE_DELAYED_PAUSED = 32;
  192. const DOM_ACTIVE_INVALID_PARENT = 2048;
  193.  
  194. var console = {};
  195.  
  196. console.log = function() {
  197. window.console.log(...['[h5p]', ...arguments])
  198. }
  199. console.error = function() {
  200. window.console.error(...['[h5p]', ...arguments])
  201. }
  202.  
  203. function makeNoRoot(shadowRoot) {
  204. const doc = shadowRoot.ownerDocument || document;
  205. const htmlInShadowRoot = doc.createElement('noroot'); // pseudo element
  206. const childNodes = [...shadowRoot.childNodes]
  207. shadowRoot.insertBefore(htmlInShadowRoot, shadowRoot.firstChild)
  208. for (const childNode of childNodes) htmlInShadowRoot.appendChild(childNode);
  209. return shadowRoot.querySelector('noroot');
  210. }
  211.  
  212. let _endlessloop = null;
  213. const isIframe = (window.top !== window.self && window.top && window.self);
  214. const shadowRoots = [];
  215.  
  216. const getRoot = (elm) => elm.getRootNode instanceof Function ? elm.getRootNode() : (elm.ownerDocument || null);
  217.  
  218. const isShadowRoot = (elm) => (elm && ('host' in elm)) ? elm.nodeType == 11 && !!elm.host && elm.host.nodeType == 1 : null; //instanceof ShadowRoot
  219.  
  220.  
  221. const domAppender = (d) => d.querySelector('head') || d.querySelector('html') || d.querySelector('noroot') || null;
  222.  
  223. const playerConfs = {}
  224.  
  225. const hanlderResizeVideo = (entries) => {
  226. const detected_changes = {};
  227. for (let entry of entries) {
  228. const player = entry.target.nodeName == "VIDEO" ? entry.target : entry.target.querySelector("VIDEO[_h5ppid]");
  229. if (!player) continue;
  230. const vpid = player.getAttribute('_h5ppid');
  231. if (!vpid) continue;
  232. if (vpid in detected_changes) continue;
  233. detected_changes[vpid] = true;
  234. const wPlayer = $hs.getPlayerBlockElement(player, true)
  235. if (!wPlayer) continue;
  236. const layoutBox = wPlayer.parentNode
  237. if (!layoutBox) continue;
  238. const tipsDom = layoutBox.querySelector('[_potTips_]');
  239. if (!tipsDom) continue;
  240.  
  241. $hs.fixNonBoxingVideoTipsPosition(tipsDom, player);
  242. window.requestAnimationFrame(() => $hs.fixNonBoxingVideoTipsPosition(tipsDom, player))
  243.  
  244. }
  245. };
  246.  
  247. const $mb = {
  248.  
  249.  
  250. nightly_isSupportQueueMicrotask: function() {
  251.  
  252. if ('_isSupportQueueMicrotask' in $mb) return $mb._isSupportQueueMicrotask;
  253.  
  254. $mb._isSupportQueueMicrotask = false;
  255. $mb.queueMicrotask = window.queueMicrotask;
  256. if (typeof $mb.queueMicrotask == 'function') {
  257. $mb._isSupportQueueMicrotask = true;
  258. }
  259.  
  260. return $mb._isSupportQueueMicrotask;
  261.  
  262. },
  263.  
  264. stable_isSupportAdvancedEventListener: function() {
  265.  
  266. if ('_isSupportAdvancedEventListener' in $mb) return $mb._isSupportAdvancedEventListener
  267. let prop = 0;
  268. document.createAttribute('z').addEventListener('', null, {
  269. get passive() {
  270. prop++;
  271. },
  272. get once() {
  273. prop++;
  274. }
  275. });
  276. return ($mb._isSupportAdvancedEventListener = (prop == 2));
  277. }
  278.  
  279. }
  280.  
  281.  
  282. const $ws = {
  283. requestAnimationFrame,
  284. cancelAnimationFrame,
  285. MutationObserver,
  286. setInterval,
  287. clearInterval
  288. }
  289. //throw Error if your browser is too outdated. (eg ES6 script, no such window object)
  290.  
  291. Element.prototype.__matches__ = (Element.prototype.matches || Element.prototype.matchesSelector ||
  292. Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector ||
  293. Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector ||
  294. Element.prototype.matches()); // throw Error if not supported
  295.  
  296.  
  297. Element.prototype.__requestPointerLock__ = (Element.prototype.requestPointerLock ||
  298. Element.prototype.mozRequestPointerLock || Element.prototype.webkitRequestPointerLock || function() {});
  299.  
  300. // Ask the browser to release the pointer
  301. Document.prototype.__exitPointerLock__ = (Document.prototype.exitPointerLock ||
  302. Document.prototype.mozExitPointerLock || Document.prototype.webkitExitPointerLock || function() {});
  303.  
  304. // built-in hash - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
  305. async function digestMessage(message) {
  306. return window.sha256(message)
  307. }
  308.  
  309. const dround = (x) => ~~(x + .5);
  310.  
  311. const jsonStringify_replacer = function(key, val) {
  312. if (val && (val instanceof Element || val instanceof Document)) return val.toString();
  313. return val; // return as is
  314. };
  315.  
  316. const jsonParse = function() {
  317. try {
  318. return JSON.parse.apply(this, arguments)
  319. } catch (e) {}
  320. return null;
  321. }
  322. const jsonStringify = function(obj) {
  323. try {
  324. return JSON.stringify.call(this, obj, jsonStringify_replacer)
  325. } catch (e) {}
  326. return null;
  327. }
  328.  
  329. function _postMsg() {
  330. //async is needed. or error handling for postMessage
  331. const [win, tag, ...data] = arguments;
  332. if (typeof tag == 'string') {
  333. let postMsgObj = {
  334. tag,
  335. passing: true,
  336. winOrder: _postMsg.a
  337. }
  338. try {
  339. let k = 'msg-' + (+new Date)
  340. win.document[str_postMsgData] = win.document[str_postMsgData] || {}
  341. win.document[str_postMsgData][k] = data; //direct
  342. postMsgObj.str = k;
  343. postMsgObj.stype = 1;
  344. } catch (e) {}
  345. if (!postMsgObj.stype) {
  346. postMsgObj.str = jsonStringify({
  347. d: data
  348. })
  349. if (postMsgObj.str && postMsgObj.str.length) postMsgObj.stype = 2;
  350. }
  351. if (!postMsgObj.stype) {
  352. postMsgObj.str = "" + data;
  353. postMsgObj.stype = 0;
  354. }
  355. win.postMessage(postMsgObj, '*');
  356. }
  357.  
  358. }
  359.  
  360. function postMsg() {
  361. let win = window;
  362. let a = 0;
  363. while (win = win.parent) {
  364. _postMsg.a = ++a;
  365. _postMsg(win, ...arguments)
  366. if (win == top) break;
  367. }
  368. }
  369.  
  370.  
  371. function crossBrowserTransition(type) {
  372. if (crossBrowserTransition['_result_' + type]) return crossBrowserTransition['_result_' + type]
  373. let el = document.createElement("fakeelement");
  374.  
  375. const capital = (x) => x[0].toUpperCase() + x.substr(1);
  376. const capitalType = capital(type);
  377.  
  378. const transitions = {
  379. [type]: `${type}end`,
  380. [`O${capitalType}`]: `o${capitalType}End`,
  381. [`Moz${capitalType}`]: `${type}end`,
  382. [`Webkit${capitalType}`]: `webkit${capitalType}End`,
  383. [`MS${capitalType}`]: `MS${capitalType}End`
  384. }
  385.  
  386. for (let styleProp in transitions) {
  387. if (el.style[styleProp] !== undefined) {
  388. return (crossBrowserTransition['_result_' + type] = transitions[styleProp]);
  389. }
  390. }
  391. }
  392.  
  393. function isInOperation(elm) {
  394. let elmInFocus = elm || document.activeElement;
  395. if (!elmInFocus) return false;
  396. let res1 = elmInFocus.__matches__(
  397. 'a[href],link[href],button,input:not([type="hidden"]),select,textarea,iframe,frame,menuitem,[draggable],[contenteditable]'
  398. );
  399. return res1;
  400. }
  401.  
  402. const fn_toString = (f, n = 50) => {
  403. let s = (f + "");
  404. if (s.length > 2 * n + 5) {
  405. s = s.substr(0, n) + ' ... ' + s.substr(-n);
  406. }
  407. return s
  408. };
  409.  
  410. function consoleLog() {
  411. if (!_debug_h5p_logging_) return;
  412. if (isIframe) postMsg('consoleLog', ...arguments);
  413. else console.log.apply(console, arguments);
  414. }
  415.  
  416. function consoleLogF() {
  417. if (isIframe) postMsg('consoleLog', ...arguments);
  418. else console.log.apply(console, arguments);
  419. }
  420.  
  421. class AFLooperArray extends Array {
  422. constructor() {
  423. super();
  424. this.activeLoopsCount = 0;
  425. this.cid = 0;
  426. this.loopingFrame = this.loopingFrame.bind(this);
  427. }
  428.  
  429. loopingFrame() {
  430. if (!this.cid) return; //cancelled
  431. for (const opt of this) {
  432. if (opt.isFunctionLooping) opt.qn(opt.fn);
  433. }
  434. }
  435.  
  436. get isArrayLooping() {
  437. return this.cid > 0;
  438. }
  439.  
  440. loopStart() {
  441. this.cid = $ws.setInterval(this.loopingFrame, 300);
  442. }
  443. loopStop() {
  444. if (this.cid) $ws.clearInterval(this.cid);
  445. this.cid = 0;
  446. }
  447. appendLoop(fn) {
  448. if (typeof fn != 'function' || !this) return;
  449. const opt = new AFLooperFunc(fn, this);
  450. super.push(opt);
  451. return opt;
  452. }
  453. }
  454.  
  455. class AFLooperFunc {
  456. constructor(fn, bind) {
  457. this._looping = false;
  458. this.fn = fn.bind(this);
  459. if ($mb.nightly_isSupportQueueMicrotask()) this.qn = $mb.queueMicrotask;
  460. else this.qn = this.fn; //qn(fn) = qn() = fn()
  461. this.bind = bind;
  462. }
  463. get isFunctionLooping() {
  464. return this._looping;
  465. }
  466. loopingStart() {
  467. if (this._looping === false) {
  468. this._looping = true;
  469. if (++this.bind.activeLoopsCount == 1) this.bind.loopStart();
  470. }
  471. }
  472. loopingStop() {
  473. if (this._looping === true) {
  474. this._looping = false;
  475. if (--this.bind.activeLoopsCount == 0) this.bind.loopStop();
  476. }
  477. }
  478. }
  479.  
  480. function decimalEqual(a, b) {
  481. return Math.round(a * 100000000) == Math.round(b * 100000000)
  482. }
  483.  
  484. function nonZeroNum(a) {
  485. return a > 0 || a < 0;
  486. }
  487.  
  488. class PlayerConf {
  489.  
  490. get scaleFactor() {
  491. return this.mFactor * this.vFactor;
  492. }
  493.  
  494. cssTransform() {
  495.  
  496. const playerConf = this;
  497. const player = playerConf.domElement;
  498. if (!player) return;
  499. const videoScale = playerConf.scaleFactor;
  500.  
  501. let {
  502. x,
  503. y
  504. } = playerConf.translate;
  505.  
  506. let [_x, _y] = ((playerConf.rotate % 180) == 90) ? [y, x] : [x, y];
  507.  
  508.  
  509. if ((playerConf.rotate % 360) == 270) _x = -_x;
  510. if ((playerConf.rotate % 360) == 90) _y = -_y;
  511.  
  512. var s = [
  513. playerConf.rotate > 0 ? 'rotate(' + playerConf.rotate + 'deg)' : '',
  514. !decimalEqual(videoScale, 1.0) ? 'scale(' + videoScale + ')' : '',
  515. (nonZeroNum(_x) || nonZeroNum(_y)) ? `translate(${_x}px, ${_y}px)` : '',
  516. ];
  517.  
  518. player.style.transform = s.join(' ').trim()
  519.  
  520. }
  521.  
  522. constructor() {
  523.  
  524. this.translate = {
  525. x: 0,
  526. y: 0
  527. };
  528. this.rotate = 0;
  529. this.mFactor = 1.0;
  530. this.vFactor = 1.0;
  531. this.fps = 30;
  532. this.filter_key = {};
  533. this.filter_view_units = {
  534. 'hue-rotate': 'deg',
  535. 'blur': 'px'
  536. };
  537. this.filterReset();
  538.  
  539. }
  540.  
  541. setFilter(prop, f) {
  542.  
  543. let oldValue = this.filter_key[prop];
  544. if (typeof oldValue != 'number') return;
  545. let newValue = f(oldValue)
  546. if (oldValue != newValue) {
  547.  
  548. newValue = +newValue.toFixed(6); //javascript bug
  549.  
  550. }
  551.  
  552. this.filter_key[prop] = newValue
  553. this.filterSetup();
  554.  
  555. return newValue;
  556.  
  557.  
  558.  
  559. }
  560.  
  561. filterSetup(options) {
  562.  
  563. let ums = GM_getValue("unsharpen_mask")
  564. if (!ums) ums = ""
  565.  
  566. let view = []
  567. let playerElm = $hs.player();
  568. if (!playerElm) return;
  569. for (let view_key in this.filter_key) {
  570. let filter_value = +((+this.filter_key[view_key] || 0).toFixed(3))
  571. let addTo = true;
  572. switch (view_key) {
  573. case 'brightness':
  574. /* fall through */
  575. case 'contrast':
  576. /* fall through */
  577. case 'saturate':
  578. if (decimalEqual(filter_value, 1.0)) addTo = false;
  579. break;
  580. case 'hue-rotate':
  581. /* fall through */
  582. case 'blur':
  583. if (decimalEqual(filter_value, 0.0)) addTo = false;
  584. break;
  585. }
  586. let view_unit = this.filter_view_units[view_key] || ''
  587. if (addTo) view.push(`${view_key}(${filter_value}${view_unit})`)
  588. this.filter_key[view_key] = Number(+this.filter_key[view_key] || 0)
  589. }
  590. if (ums) view.push(`url("#_h5p_${ums}")`);
  591. if (options && options.grey) view.push('url("#grey1")');
  592. playerElm.style.filter = view.join(' ').trim(); //performance in firefox is bad
  593. }
  594.  
  595. filterReset() {
  596. this.filter_key['brightness'] = 1.0
  597. this.filter_key['contrast'] = 1.0
  598. this.filter_key['saturate'] = 1.0
  599. this.filter_key['hue-rotate'] = 0.0
  600. this.filter_key['blur'] = 0.0
  601. this.filterSetup()
  602. }
  603.  
  604. }
  605.  
  606. const Store = {
  607. prefix: '_h5_player',
  608. save: function(k, v) {
  609. if (!Store.available()) return false;
  610. if (typeof v != 'string') return false;
  611. Store.LS.setItem(Store.prefix + k, v)
  612. let sk = fn_toString(k + "", 30);
  613. let sv = fn_toString(v + "", 30);
  614. consoleLog(`localStorage Saved "${sk}" = "${sv}"`)
  615. return true;
  616.  
  617. },
  618. read: function(k) {
  619. if (!Store.available()) return false;
  620. let v = Store.LS.getItem(Store.prefix + k)
  621. let sk = fn_toString(k + "", 30);
  622. let sv = fn_toString(v + "", 30);
  623. consoleLog(`localStorage Read "${sk}" = "${sv}"`);
  624. return v;
  625.  
  626. },
  627. remove: function(k) {
  628.  
  629. if (!Store.available()) return false;
  630. Store.LS.removeItem(Store.prefix + k)
  631. let sk = fn_toString(k + "", 30);
  632. consoleLog(`localStorage Removed "${sk}"`)
  633. return true;
  634. },
  635. clearInvalid: function(sVersion) {
  636. if (!Store.available()) return false;
  637.  
  638. //let sVersion=1814;
  639. if (+Store.read('_sVersion_') < sVersion) {
  640. Store._keys()
  641. .filter(s => s.indexOf(Store.prefix) === 0)
  642. .forEach(key => window.localStorage.removeItem(key))
  643. Store.save('_sVersion_', sVersion + '')
  644. return 2;
  645. }
  646. return 1;
  647.  
  648. },
  649. available: function() {
  650. if (Store.LS) return true;
  651. if (!window) return false;
  652. const localStorage = window.localStorage;
  653. if (!localStorage) return false;
  654. if (typeof localStorage != 'object') return false;
  655. if (!('getItem' in localStorage)) return false;
  656. if (!('setItem' in localStorage)) return false;
  657. Store.LS = localStorage;
  658. return true;
  659.  
  660. },
  661. _keys: function() {
  662. return Object.keys(localStorage);
  663. },
  664. _setItem: function(key, value) {
  665. return localStorage.setItem(key, value)
  666. },
  667. _getItem: function(key) {
  668. return localStorage.getItem(key)
  669. },
  670. _removeItem: function(key) {
  671. return localStorage.removeItem(key)
  672. }
  673.  
  674. }
  675.  
  676. const domTool = {
  677. nopx: (x) => +x.replace('px', ''),
  678. cssWH: function(m, r) {
  679. if (!r) r = getComputedStyle(m, null);
  680. let c = (x) => +x.replace('px', '');
  681. return {
  682. w: m.offsetWidth || c(r.width),
  683. h: m.offsetHeight || c(r.height)
  684. }
  685. },
  686. _isActionBox_1: function(vEl, pEl) {
  687.  
  688. const vElCSS = domTool.cssWH(vEl);
  689. let vElCSSw = vElCSS.w;
  690. let vElCSSh = vElCSS.h;
  691.  
  692. let vElx = vEl;
  693. const res = [];
  694. //let mLevel = 0;
  695. if (vEl && pEl && vEl != pEl && pEl.contains(vEl)) {
  696. while (vElx && vElx != pEl) {
  697. vElx = vElx.parentNode;
  698. let vElx_css = null;
  699. if (isShadowRoot(vElx)) {} else {
  700. vElx_css = getComputedStyle(vElx, null);
  701. let vElx_wp = domTool.nopx(vElx_css.paddingLeft) + domTool.nopx(vElx_css.paddingRight)
  702. vElCSSw += vElx_wp
  703. let vElx_hp = domTool.nopx(vElx_css.paddingTop) + domTool.nopx(vElx_css.paddingBottom)
  704. vElCSSh += vElx_hp
  705. }
  706. res.push({
  707. //level: ++mLevel,
  708. padW: vElCSSw,
  709. padH: vElCSSh,
  710. elm: vElx,
  711. css: vElx_css
  712. })
  713.  
  714. }
  715. }
  716.  
  717. // in the array, each item is the parent of video player
  718. //res.vEl_cssWH = vElCSS
  719.  
  720. return res;
  721.  
  722. },
  723. _isActionBox: function(vEl, walkRes, pEl_idx) {
  724.  
  725. function absDiff(w1, w2, h1, h2) {
  726. const w = (w1 - w2),
  727. h = h1 - h2;
  728. return [(w > 0 ? w : -w), (h > 0 ? h : -h)]
  729. }
  730.  
  731. function midPoint(rect) {
  732. return {
  733. x: (rect.left + rect.right) / 2,
  734. y: (rect.top + rect.bottom) / 2
  735. }
  736. }
  737.  
  738. const parentCount = walkRes.length;
  739. if (pEl_idx >= 0 && pEl_idx < parentCount) {} else {
  740. return;
  741. }
  742. const pElr = walkRes[pEl_idx]
  743. if (!pElr.css) {
  744. //shadowRoot
  745. return true;
  746. }
  747.  
  748. const pEl = pElr.elm;
  749.  
  750. //prevent activeElement==body
  751. const pElCSS = domTool.cssWH(pEl, pElr.css);
  752.  
  753. //check prediction of parent dimension
  754. const d1v = absDiff(pElCSS.w, pElr.padW, pElCSS.h, pElr.padH)
  755.  
  756. const d1x = d1v[0] < 10
  757. const d1y = d1v[1] < 10;
  758.  
  759. if (d1x && d1y) return true; //both edge along the container - fit size
  760. if (!d1x && !d1y) return false; //no edge along the container - body contain the video element, fixed width&height
  761.  
  762. //case: youtube video fullscreen
  763.  
  764. //check centre point
  765.  
  766. const pEl_rect = pEl.getBoundingClientRect()
  767. const vEl_rect = vEl.getBoundingClientRect()
  768.  
  769. const pEl_center = midPoint(pEl_rect)
  770. const vEl_center = midPoint(vEl_rect)
  771.  
  772. const d2v = absDiff(pEl_center.x, vEl_center.x, pEl_center.y, vEl_center.y);
  773.  
  774. const d2x = d2v[0] < 10;
  775. const d2y = d2v[1] < 10;
  776.  
  777. return (d2x && d2y);
  778.  
  779. },
  780. getRect: function(element) {
  781. let rect = element.getBoundingClientRect();
  782. let scroll = domTool.getScroll();
  783. return {
  784. pageX: rect.left + scroll.left,
  785. pageY: rect.top + scroll.top,
  786. screenX: rect.left,
  787. screenY: rect.top
  788. };
  789. },
  790. getScroll: function() {
  791. return {
  792. left: document.documentElement.scrollLeft || document.body.scrollLeft,
  793. top: document.documentElement.scrollTop || document.body.scrollTop
  794. };
  795. },
  796. getClient: function() {
  797. return {
  798. width: document.compatMode == 'CSS1Compat' ? document.documentElement.clientWidth : document.body.clientWidth,
  799. height: document.compatMode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight
  800. };
  801. },
  802. addStyle: //GM_addStyle,
  803. function(css, head) {
  804. if (!head) {
  805. let _doc = document.documentElement;
  806. head = domAppender(_doc);
  807. }
  808. let doc = head.ownerDocument;
  809. let style = doc.createElement('style');
  810. style.type = 'text/css';
  811. style.textContent = css;
  812. head.appendChild(style);
  813. //console.log(document.head,style,'add style')
  814. return style;
  815. },
  816. eachParentNode: function(dom, fn) {
  817. let parent = dom.parentNode
  818. while (parent) {
  819. let isEnd = fn(parent, dom)
  820. parent = parent.parentNode
  821. if (isEnd) {
  822. break
  823. }
  824. }
  825. },
  826.  
  827. hideDom: function hideDom(selector) {
  828. let dom = document.querySelector(selector)
  829. if (dom) {
  830. $ws.requestAnimationFrame(function() {
  831. dom.style.opacity = 0;
  832. dom.style.transform = 'translate(-9999px)';
  833. dom = null;
  834. })
  835. }
  836. }
  837. };
  838.  
  839. const handle = {
  840.  
  841.  
  842. afPlaybackRecording: async function() {
  843. const opts = this;
  844.  
  845. let qTime = +new Date;
  846. if (qTime >= opts.pTime) {
  847. opts.pTime = qTime + opts.timeDelta; //prediction of next Interval
  848. opts.savePlaybackProgress()
  849. }
  850.  
  851. },
  852. savePlaybackProgress: function() {
  853.  
  854. //this refer to endless's opts
  855. let player = this.player;
  856.  
  857. let _uid = this.player_uid; //_h5p_uid_encrypted
  858. if (!_uid) return;
  859.  
  860. let shallSave = true;
  861. let currentTimeToSave = ~~player.currentTime;
  862.  
  863. if (this._lastSave == currentTimeToSave) shallSave = false;
  864.  
  865. if (shallSave) {
  866.  
  867. this._lastSave = currentTimeToSave
  868.  
  869. //console.log('aasas',this.player_uid, shallSave, '_play_progress_'+_uid, currentTimeToSave)
  870.  
  871. Store.save('_play_progress_' + _uid, jsonStringify({
  872. 't': currentTimeToSave
  873. }))
  874.  
  875. }
  876. //console.log('playback logged')
  877.  
  878. },
  879. playingWithRecording: function() {
  880. let player = this.player;
  881. if (!player.paused && !this.isFunctionLooping) {
  882. let player = this.player;
  883. let _uid = player.getAttribute('_h5p_uid_encrypted') || ''
  884. if (_uid) {
  885. this.player_uid = _uid;
  886. this.pTime = 0;
  887. this.loopingStart();
  888. }
  889. }
  890. }
  891.  
  892. };
  893.  
  894. class Momentary extends Map {
  895. act(uniqueId, fn_start, fn_end, delay) {
  896. if (!uniqueId) return;
  897. uniqueId = uniqueId + "";
  898. const last_cid = this.get(uniqueId);
  899. if (last_cid > 0) clearTimeout(last_cid);
  900. fn_start();
  901. const new_cid = setTimeout(fn_end, delay)
  902. this.set(uniqueId, new_cid)
  903. }
  904. }
  905.  
  906. const momentary = new Momentary();
  907.  
  908. const $hs = {
  909.  
  910. /* 提示文本的字號 */
  911. fontSize: 16,
  912. enable: true,
  913. playerInstance: null,
  914. playbackRate: 1,
  915. /* 快進快退步長 */
  916. skipStep: 5,
  917.  
  918. /* 獲取當前播放器的實例 */
  919. player: function() {
  920. let res = $hs.playerInstance || null;
  921. if (res && res.parentNode == null) {
  922. $hs.playerInstance = null;
  923. res = null;
  924. }
  925.  
  926. if (res == null) {
  927. for (let k in playerConfs) {
  928. let playerConf = playerConfs[k];
  929. if (playerConf && playerConf.domElement && playerConf.domElement.parentNode) return playerConf.domElement;
  930. }
  931. }
  932. return res;
  933. },
  934.  
  935. pictureInPicture: function(videoElm) {
  936. if (document.pictureInPictureElement) {
  937. document.exitPictureInPicture();
  938. } else if ('requestPictureInPicture' in videoElm) {
  939. videoElm.requestPictureInPicture()
  940. } else {
  941. $hs.tips('PIP is not supported.');
  942. }
  943. },
  944.  
  945. getPlayerConf: function(video) {
  946.  
  947. if (!video) return null;
  948. let vpid = video.getAttribute('_h5ppid') || null;
  949. if (!vpid) return null;
  950. return playerConfs[vpid] || null;
  951.  
  952. },
  953.  
  954. handlerVideoPlaying: function(evt) {
  955. const videoElm = evt.target || this || null;
  956.  
  957. if (!videoElm || videoElm.nodeName != "VIDEO") return;
  958.  
  959. const vpid = videoElm.getAttribute('_h5ppid')
  960.  
  961. if (!vpid) return;
  962. if ($hs.cid_playHook > 0) clearTimeout($hs.cid_playHook);
  963. $hs.cid_playHook = setTimeout(function() {
  964. let onlyPlayed = null;
  965. for (var k in playerConfs) {
  966. if (k == vpid) {
  967. if (playerConfs[k].domElement.paused === false) onlyPlayed = true;
  968. } else if (playerConfs[k].domElement.paused === false) {
  969. onlyPlayed = false;
  970. break;
  971. }
  972. }
  973. if (onlyPlayed === true) {
  974. $hs.focusHookVDoc = getRoot(videoElm)
  975. $hs.focusHookVId = vpid
  976. }
  977. $bv.boostVideoPerformanceActivate();
  978. }, 100)
  979.  
  980. const playerConf = $hs.getPlayerConf(videoElm)
  981.  
  982. $hs._actionBoxObtain(videoElm);
  983. if (playerConf) {
  984. if (playerConf.timeout_pause > 0) playerConf.timeout_pause = clearTimeout(playerConf.timeout_pause);
  985. playerConf.lastPauseAt = 0
  986. playerConf.domActive |= DOM_ACTIVE_ONCE_PLAYED;
  987. playerConf.domActive &= ~DOM_ACTIVE_DELAYED_PAUSED;
  988. }
  989.  
  990. $hs.swtichPlayerInstance();
  991.  
  992.  
  993.  
  994. $hs.onVideoTriggering();
  995.  
  996. if (!$hs.enable) return $hs.tips(false);
  997.  
  998. if (videoElm._isThisPausedBefore_) consoleLog('resumed')
  999. let _pausedbefore_ = videoElm._isThisPausedBefore_
  1000.  
  1001. if (videoElm.playpause_cid) {
  1002. clearTimeout(videoElm.playpause_cid);
  1003. videoElm.playpause_cid = 0;
  1004. }
  1005. let _last_paused = videoElm._last_paused
  1006. videoElm._last_paused = videoElm.paused
  1007. if (_last_paused === !videoElm.paused) {
  1008. videoElm.playpause_cid = setTimeout(() => {
  1009. if (videoElm.paused === !_last_paused && !videoElm.paused && _pausedbefore_) {
  1010. $hs.tips('Playback resumed', undefined, 2500)
  1011. }
  1012. }, 90)
  1013. }
  1014.  
  1015. /* 播放的時候進行相關同步操作 */
  1016.  
  1017. if (!videoElm._record_continuous) {
  1018.  
  1019. /* 同步之前設定的播放速度 */
  1020. $hs.setPlaybackRate()
  1021.  
  1022. if (!_endlessloop) _endlessloop = new AFLooperArray();
  1023.  
  1024. videoElm._record_continuous = _endlessloop.appendLoop(handle.afPlaybackRecording);
  1025. videoElm._record_continuous._lastSave = -999;
  1026.  
  1027. videoElm._record_continuous.timeDelta = 2000;
  1028. videoElm._record_continuous.player = videoElm
  1029. videoElm._record_continuous.savePlaybackProgress = handle.savePlaybackProgress;
  1030. videoElm._record_continuous.playingWithRecording = handle.playingWithRecording;
  1031. }
  1032.  
  1033. videoElm._record_continuous.playingWithRecording(videoElm); //try to start recording
  1034.  
  1035. videoElm._isThisPausedBefore_ = false;
  1036.  
  1037. },
  1038. handlerVideoPause: function(evt) {
  1039.  
  1040. const videoElm = evt.target || this || null;
  1041.  
  1042. if (!videoElm || videoElm.nodeName != "VIDEO") return;
  1043.  
  1044. const vpid = videoElm.getAttribute('_h5ppid')
  1045.  
  1046. if (!vpid) return;
  1047. if ($hs.cid_playHook > 0) clearTimeout($hs.cid_playHook);
  1048. $hs.cid_playHook = setTimeout(function() {
  1049. let allPaused = true;
  1050. for (var k in playerConfs) {
  1051. if (playerConfs[k].domElement.paused === false) {
  1052. allPaused = false;
  1053. break;
  1054. }
  1055. }
  1056. if (allPaused) {
  1057. $hs.focusHookVDoc = getRoot(videoElm)
  1058. $hs.focusHookVId = vpid
  1059. }
  1060. $bv.boostVideoPerformanceDeactivate();
  1061. }, 100)
  1062.  
  1063.  
  1064.  
  1065. const playerConf = $hs.getPlayerConf(videoElm)
  1066. if (playerConf) {
  1067. playerConf.lastPauseAt = +new Date;
  1068. playerConf.timeout_pause = setTimeout(() => {
  1069. if (playerConf.lastPauseAt > 0) playerConf.domActive |= DOM_ACTIVE_DELAYED_PAUSED;
  1070. }, 600)
  1071. }
  1072.  
  1073. if (!$hs.enable) return $hs.tips(false);
  1074. consoleLog('pause')
  1075. videoElm._isThisPausedBefore_ = true;
  1076.  
  1077. let _last_paused = videoElm._last_paused
  1078. videoElm._last_paused = videoElm.paused
  1079. if (videoElm.playpause_cid) {
  1080. clearTimeout(videoElm.playpause_cid);
  1081. videoElm.playpause_cid = 0;
  1082. }
  1083. if (_last_paused === !videoElm.paused) {
  1084. videoElm.playpause_cid = setTimeout(() => {
  1085. if (videoElm.paused === !_last_paused && videoElm.paused) {
  1086. $hs._tips(videoElm, 'Playback paused', undefined, 2500)
  1087. }
  1088. }, 90)
  1089. }
  1090.  
  1091.  
  1092. if (videoElm._record_continuous && videoElm._record_continuous.isFunctionLooping) {
  1093. setTimeout(function() {
  1094. if (videoElm.paused === true && !videoElm._record_continuous.isFunctionLooping)
  1095. videoElm._record_continuous.savePlaybackProgress(); //savePlaybackProgress once before stopping //handle.savePlaybackProgress;
  1096. }, 380)
  1097. videoElm._record_continuous.loopingStop();
  1098. }
  1099.  
  1100.  
  1101. },
  1102. handlerVideoVolumeChange: function(evt) {
  1103.  
  1104. const videoElm = evt.target || this || null;
  1105.  
  1106. if (videoElm.volume >= 0) {} else {
  1107. return;
  1108. }
  1109. let cVol = videoElm.volume;
  1110. let cMuted = videoElm.muted;
  1111.  
  1112. if (cVol === videoElm._volume_p && cMuted === videoElm._muted_p) {
  1113. // nothing changed
  1114. } else if (cVol === videoElm._volume_p && cMuted !== videoElm._muted_p) {
  1115. // muted changed
  1116. } else { // cVol != pVol
  1117.  
  1118. // only volume changed
  1119.  
  1120. let shallShowTips = videoElm._volume >= 0; //prevent initialization
  1121.  
  1122. if (!cVol) {
  1123. videoElm.muted = true;
  1124. } else if (cMuted) {
  1125. videoElm.muted = false;
  1126. videoElm._volume = cVol;
  1127. } else if (!cMuted) {
  1128. videoElm._volume = cVol;
  1129. }
  1130. consoleLog('volume changed')
  1131.  
  1132. if (shallShowTips)
  1133. $hs._tips(videoElm, 'Volume: ' + dround(videoElm.volume * 100) + '%', undefined, 3000)
  1134.  
  1135. }
  1136.  
  1137. videoElm._volume_p = cVol
  1138. videoElm._muted_p = cMuted
  1139.  
  1140. },
  1141. handlerVideoLoadedMetaData: function(evt) {
  1142. const videoElm = evt.target || this || null;
  1143.  
  1144. if (!videoElm || videoElm.nodeName != "VIDEO") return;
  1145.  
  1146. consoleLog('video size', videoElm.videoWidth + ' x ' + videoElm.videoHeight);
  1147.  
  1148. let vpid = videoElm.getAttribute('_h5ppid') || null;
  1149. if (!vpid || !videoElm.currentSrc) return;
  1150.  
  1151. if ($hs.varSrcList[vpid] != videoElm.currentSrc) {
  1152. $hs.varSrcList[vpid] = videoElm.currentSrc;
  1153. $hs.videoSrcFound(videoElm);
  1154. $hs._actionBoxObtain(videoElm);
  1155. }
  1156. if (!videoElm._onceVideoLoaded) {
  1157. videoElm._onceVideoLoaded = true;
  1158. playerConfs[vpid].domActive |= DOM_ACTIVE_SRC_LOADED;
  1159. }
  1160.  
  1161. },
  1162. handlerElementMouseEnter: function(evt) {
  1163. if ($hs.intVideoInitCount > 0) {} else {
  1164. return;
  1165. }
  1166. const actionBoxRelation = $hs.getActionBoxRelationFromDOM(evt.target);
  1167. if (!actionBoxRelation) return;
  1168. const actionBox = actionBoxRelation.actionBox
  1169. if (!actionBox) return;
  1170. const vpid = actionBox.getAttribute('_h5p_actionbox_');
  1171. const videoElm = actionBoxRelation.player;
  1172. if (!videoElm) return;
  1173.  
  1174. $hs._actionBoxObtain(videoElm);
  1175.  
  1176. const playerConf = $hs.getPlayerConf(videoElm)
  1177. if (playerConf) {
  1178. momentary.act("actionBoxMouseEnter",
  1179. () => {
  1180. playerConf.domActive |= DOM_ACTIVE_MOUSE_IN;
  1181. },
  1182. () => {
  1183. playerConf.domActive &= ~DOM_ACTIVE_MOUSE_IN;
  1184. },
  1185. 300)
  1186. }
  1187.  
  1188. },
  1189. handlerElementMouseDown: function(evt) {
  1190.  
  1191. function notAtVideo() {
  1192. if ($hs.focusHookVDoc) $hs.focusHookVDoc = null
  1193. if ($hs.focusHookVId) $hs.focusHookVId = ''
  1194. }
  1195.  
  1196. if ($hs.intVideoInitCount > 0) {} else {
  1197. return notAtVideo();
  1198. }
  1199.  
  1200. const actionBoxRelation = $hs.getActionBoxRelationFromDOM(evt.target);
  1201. if (!actionBoxRelation) return notAtVideo();
  1202. const actionBox = actionBoxRelation.actionBox
  1203. if (!actionBox) return notAtVideo();
  1204. const vpid = actionBox.getAttribute('_h5p_actionbox_');
  1205. const videoElm = actionBoxRelation.player;
  1206. if (!videoElm) return notAtVideo();
  1207.  
  1208. if (vpid) {
  1209. $hs.focusHookVDoc = getRoot(videoElm)
  1210. $hs.focusHookVId = vpid
  1211. }
  1212.  
  1213.  
  1214.  
  1215. $hs._actionBoxObtain(videoElm);
  1216.  
  1217. const playerConf = $hs.getPlayerConf(videoElm)
  1218. if (playerConf) {
  1219. momentary.act("actionBoxClicking",
  1220. () => {
  1221. playerConf.domActive |= DOM_ACTIVE_MOUSE_CLICK;
  1222. },
  1223. () => {
  1224. playerConf.domActive &= ~DOM_ACTIVE_MOUSE_CLICK;
  1225. },
  1226. 300)
  1227. }
  1228. $hs.swtichPlayerInstance();
  1229.  
  1230. },
  1231. handlerElementWheelTuneVolume: function(evt) { //shift + wheel
  1232.  
  1233. if ($hs.intVideoInitCount > 0) {} else {
  1234. return;
  1235. }
  1236.  
  1237. const actionBoxRelation = $hs.getActionBoxRelationFromDOM(evt.target);
  1238. if (!actionBoxRelation) return;
  1239. const actionBox = actionBoxRelation.actionBox
  1240. if (!actionBox) return;
  1241. const vpid = actionBox.getAttribute('_h5p_actionbox_');
  1242. const videoElm = actionBoxRelation.player;
  1243. if (!videoElm) return;
  1244.  
  1245. $hs._actionBoxObtain(videoElm);
  1246.  
  1247. if (!evt.shiftKey) return;
  1248. if (evt.deltaY) {
  1249. let player = $hs.player();
  1250. if (!player || player != videoElm) return;
  1251.  
  1252. if (evt.deltaY > 0) {
  1253.  
  1254. if ((player.muted && player.volume === 0) && player._volume > 0) {
  1255.  
  1256. player.muted = false;
  1257. player.volume = player._volume;
  1258. } else if (player.muted && (player.volume > 0 || !player._volume)) {
  1259. player.muted = false;
  1260. }
  1261. $hs.tuneVolume(-0.05)
  1262.  
  1263. evt.stopPropagation()
  1264. evt.preventDefault()
  1265. return false
  1266.  
  1267. } else if (evt.deltaY < 0) {
  1268.  
  1269. if ((player.muted && player.volume === 0) && player._volume > 0) {
  1270. player.muted = false;
  1271. player.volume = player._volume;
  1272. } else if (player.muted && (player.volume > 0 || !player._volume)) {
  1273. player.muted = false;
  1274. }
  1275. $hs.tuneVolume(+0.05)
  1276.  
  1277. evt.stopPropagation()
  1278. evt.preventDefault()
  1279. return false
  1280.  
  1281. }
  1282. }
  1283. },
  1284. debug01: function(evt, videoActive) {
  1285.  
  1286. if (!$hs.eventHooks) {
  1287. document.__h5p_eventhooks = ($hs.eventHooks = {
  1288. _debug_: []
  1289. });
  1290. }
  1291. $hs.eventHooks._debug_.push([videoActive, evt.type]);
  1292. // console.log('h5p eventhooks = document.__h5p_eventhooks')
  1293. },
  1294.  
  1295. swtichPlayerInstance: function() {
  1296.  
  1297. let newPlayerInstance = null;
  1298. const ONLY_PLAYING_NONE = 0x4A00;
  1299. const ONLY_PLAYING_MORE_THAN_ONE = 0x5A00;
  1300. let onlyPlayingInstance = ONLY_PLAYING_NONE;
  1301. for (let k in playerConfs) {
  1302. let playerConf = playerConfs[k] || {};
  1303. let {
  1304. domElement,
  1305. domActive
  1306. } = playerConf;
  1307. if (domElement) {
  1308. if (domActive & DOM_ACTIVE_INVALID_PARENT) continue;
  1309. if (!domElement.parentNode) {
  1310. playerConf.domActive |= DOM_ACTIVE_INVALID_PARENT;
  1311. continue;
  1312. }
  1313. if (domActive & DOM_ACTIVE_MOUSE_CLICK) {
  1314. newPlayerInstance = domElement
  1315. break;
  1316. }
  1317. if (domActive & DOM_ACTIVE_ONCE_PLAYED && (domActive & DOM_ACTIVE_DELAYED_PAUSED) == 0) {
  1318. if (onlyPlayingInstance == ONLY_PLAYING_NONE) onlyPlayingInstance = domElement;
  1319. else onlyPlayingInstance = ONLY_PLAYING_MORE_THAN_ONE;
  1320. }
  1321. }
  1322. }
  1323. if (newPlayerInstance == null && onlyPlayingInstance.nodeType == 1) {
  1324. newPlayerInstance = onlyPlayingInstance;
  1325. }
  1326.  
  1327. $hs.playerInstance = newPlayerInstance
  1328.  
  1329.  
  1330. },
  1331. handlerElementDblClick: function(evt) {
  1332.  
  1333. if ($hs.intVideoInitCount > 0) {} else {
  1334. return;
  1335. }
  1336.  
  1337. if (document.readyState != "complete") return;
  1338.  
  1339. const actionBoxRelation = $hs.getActionBoxRelationFromDOM(evt.target);
  1340. if (!actionBoxRelation) return;
  1341. const actionBox = actionBoxRelation.actionBox
  1342. if (!actionBox) return;
  1343. const vpid = actionBox.getAttribute('_h5p_actionbox_');
  1344. const videoElm = actionBoxRelation.player;
  1345. if (!videoElm) return;
  1346.  
  1347. $hs._actionBoxObtain(videoElm);
  1348.  
  1349. const playerConf = $hs.getPlayerConf(videoElm)
  1350. if (playerConf) {
  1351. momentary.act("actionBoxClicking",
  1352. () => {
  1353. playerConf.domActive |= DOM_ACTIVE_MOUSE_CLICK;
  1354. },
  1355. () => {
  1356. playerConf.domActive &= ~DOM_ACTIVE_MOUSE_CLICK;
  1357. },
  1358. 600)
  1359. }
  1360. $hs.swtichPlayerInstance()
  1361.  
  1362. $hs.onVideoTriggering()
  1363.  
  1364. $hs.callFullScreenBtn();
  1365.  
  1366. evt.stopPropagation()
  1367. evt.preventDefault()
  1368. return false
  1369.  
  1370. },
  1371. handlerDocFocusOut: function(e) {
  1372. let doc = this;
  1373. $hs.focusFxLock = true;
  1374. $ws.requestAnimationFrame(function() {
  1375. $hs.focusFxLock = false;
  1376. if (!$hs.enable) $hs.tips(false);
  1377. else
  1378. if (!doc.hasFocus() && $hs.player() && !$hs.isLostFocus) {
  1379. $hs.isLostFocus = true;
  1380. consoleLog('doc.focusout')
  1381. //$hs.tips('focus is lost', -1);
  1382. }
  1383. });
  1384. },
  1385. handlerDocFocusIn: function(e) {
  1386. let doc = this;
  1387. if ($hs.focusFxLock) return;
  1388. $ws.requestAnimationFrame(function() {
  1389.  
  1390. if ($hs.focusFxLock) return;
  1391. if (!$hs.enable) $hs.tips(false);
  1392. else
  1393. if (doc.hasFocus() && $hs.player() && $hs.isLostFocus) {
  1394. $hs.isLostFocus = false;
  1395. consoleLog('doc.focusin')
  1396. $hs.tips(false);
  1397.  
  1398. }
  1399. });
  1400. },
  1401.  
  1402. handlerWinMessage: async function(e) {
  1403. let tag, ed;
  1404. if (typeof e.data == 'object' && typeof e.data.tag == 'string') {
  1405. tag = e.data.tag;
  1406. ed = e.data
  1407. } else {
  1408. return;
  1409. }
  1410. let msg = null,
  1411. success = 0;
  1412. let msg_str, msg_stype,p
  1413. switch (tag) {
  1414. case 'consoleLog':
  1415. msg_str = ed.str;
  1416. msg_stype = ed.stype;
  1417. if (msg_stype === 1) {
  1418. msg = (document[str_postMsgData] || {})[msg_str] || [];
  1419. success = 1;
  1420. } else if (msg_stype === 2) {
  1421. msg = jsonParse(msg_str);
  1422. if (msg && msg.d) {
  1423. success = 2;
  1424. msg = msg.d;
  1425. }
  1426. } else {
  1427. msg = msg_str
  1428. }
  1429. p = (ed.passing && ed.winOrder) ? [' | from win-' + ed.winOrder] : [];
  1430. if (success) {
  1431. console.log(...msg, ...p)
  1432. //document[ed.data]=null; // also delete the information
  1433. } else {
  1434. console.log('msg--', msg, ...p, ed);
  1435. }
  1436. break;
  1437.  
  1438. }
  1439. },
  1440.  
  1441. isInActiveMode: function(activeElm, player) {
  1442.  
  1443. console.log('check active mode', activeElm, player)
  1444. if (activeElm == player) {
  1445. return true;
  1446. }
  1447.  
  1448. for (let vpid in $hs.actionBoxRelations) {
  1449. const actionBox = $hs.actionBoxRelations[vpid].actionBox
  1450. if (actionBox && actionBox.parentNode) {
  1451. if (activeElm == actionBox || actionBox.contains(activeElm)) {
  1452. return true;
  1453. }
  1454. }
  1455. }
  1456.  
  1457. let _checkingPass = false;
  1458.  
  1459. if (!player) return;
  1460. let layoutBox = $hs.getPlayerBlockElement(player).parentNode;
  1461. if (layoutBox && layoutBox.parentNode && layoutBox.contains(activeElm)) {
  1462. let rpid = player.getAttribute('_h5ppid') || "NULL";
  1463. let actionBox = layoutBox.parentNode.querySelector(`[_h5p_actionbox_="${rpid}"]`); //the box can be layoutBox
  1464. if (actionBox && actionBox.contains(activeElm)) _checkingPass = true;
  1465. }
  1466.  
  1467. return _checkingPass
  1468. },
  1469.  
  1470.  
  1471. toolCheckFullScreen: function(doc) {
  1472. if (typeof doc.fullScreen == 'boolean') return doc.fullScreen;
  1473. if (typeof doc.webkitIsFullScreen == 'boolean') return doc.webkitIsFullScreen;
  1474. if (typeof doc.mozFullScreen == 'boolean') return doc.mozFullScreen;
  1475. return null;
  1476. },
  1477.  
  1478. toolFormatCT: function(u) {
  1479.  
  1480. let w = Math.round(u, 0)
  1481. let a = w % 60
  1482. w = (w - a) / 60
  1483. let b = w % 60
  1484. w = (w - b) / 60
  1485. let str = ("0" + b).substr(-2) + ":" + ("0" + a).substr(-2);
  1486. if (w) str = w + ":" + str
  1487.  
  1488. return str
  1489.  
  1490. },
  1491.  
  1492. makeFocus: function(player, evt) {
  1493. setTimeout(function() {
  1494. let rpid = player.getAttribute('_h5ppid');
  1495. let actionBox = getRoot(player).querySelector(`[_h5p_actionbox_="${rpid}"]`);
  1496.  
  1497. //console.log('p',rpid, player,actionBox,document.activeElement)
  1498. if (actionBox && actionBox != document.activeElement && !actionBox.contains(document.activeElement)) {
  1499. consoleLog('make focus on', actionBox)
  1500. actionBox.focus();
  1501.  
  1502. }
  1503.  
  1504. }, 300)
  1505. },
  1506.  
  1507. loopOutwards: function(startPoint, maxStep) {
  1508.  
  1509.  
  1510. let c = 0,
  1511. p = startPoint,
  1512. q = null;
  1513. while (p && (++c <= maxStep)) {
  1514. if (p.querySelectorAll('video').length !== 1) {
  1515. return q;
  1516. break;
  1517. }
  1518. q = p;
  1519. p = p.parentNode;
  1520. }
  1521.  
  1522. return p || q || null;
  1523.  
  1524. },
  1525.  
  1526. getActionBlockElement: function(player, layoutBox) {
  1527.  
  1528. //player, $hs.getPlayerBlockElement(player).parentNode;
  1529. //player, player.parentNode .... player.parentNode.parentNode.parentNode
  1530.  
  1531. //layoutBox: a container element containing video and with innerHeight>=player.innerHeight [skipped wrapping]
  1532. //layoutBox parentSize > layoutBox Size
  1533.  
  1534. //actionBox: a container with video and controls
  1535. //can be outside layoutbox (bilibili)
  1536. //assume maximum 3 layers
  1537.  
  1538.  
  1539. let outerLayout = $hs.loopOutwards(layoutBox, 3); //i.e. layoutBox.parent.parent.parent
  1540.  
  1541. const allFullScreenBtns = $hs.queryFullscreenBtnsIndependant(outerLayout)
  1542. let actionBox = null;
  1543.  
  1544. // console.log('fa0a', allFullScreenBtns.length, layoutBox)
  1545. if (allFullScreenBtns.length > 0) {
  1546. // console.log('faa', allFullScreenBtns.length)
  1547.  
  1548. for (const possibleFullScreenBtn of allFullScreenBtns) possibleFullScreenBtn.setAttribute('__h5p_fsb__', '');
  1549. let pElm = player.parentNode;
  1550. let fullscreenBtns = null;
  1551. while (pElm && pElm.parentNode) {
  1552. fullscreenBtns = pElm.querySelectorAll('[__h5p_fsb__]');
  1553. if (fullscreenBtns.length > 0) {
  1554. break;
  1555. }
  1556. pElm = pElm.parentNode;
  1557. }
  1558. for (const possibleFullScreenBtn of allFullScreenBtns) possibleFullScreenBtn.removeAttribute('__h5p_fsb__');
  1559. if (fullscreenBtns && fullscreenBtns.length > 0) {
  1560. actionBox = pElm;
  1561. fullscreenBtns = $hs.exclusiveElements(fullscreenBtns);
  1562. return {
  1563. actionBox,
  1564. fullscreenBtns
  1565. };
  1566. }
  1567. }
  1568.  
  1569. let walkRes = domTool._isActionBox_1(player, layoutBox);
  1570. //walkRes.elm = player... player.parentNode.parentNode (i.e. wPlayer)
  1571. let parentCount = walkRes.length;
  1572.  
  1573. if (parentCount - 1 >= 0 && domTool._isActionBox(player, walkRes, parentCount - 1)) {
  1574. actionBox = walkRes[parentCount - 1].elm;
  1575. } else if (parentCount - 2 >= 0 && domTool._isActionBox(player, walkRes, parentCount - 2)) {
  1576. actionBox = walkRes[parentCount - 2].elm;
  1577. } else {
  1578. actionBox = player;
  1579. }
  1580.  
  1581. return {
  1582. actionBox,
  1583. fullscreenBtns: []
  1584. };
  1585.  
  1586.  
  1587.  
  1588.  
  1589. },
  1590.  
  1591. actionBoxRelations: {},
  1592.  
  1593. actionBoxRelationClearNodes: function(param) {
  1594.  
  1595. if (!param) return;
  1596. let refNode = null;
  1597. let domNodes = null;
  1598.  
  1599. if (param.nodeType > 0) {
  1600. refNode = param;
  1601. const rootNode = getRoot(refNode);
  1602. domNodes = rootNode ? rootNode.querySelectorAll(`[_h5p_mo_="${vpid}"]`) : [];
  1603. if (refNode) refNode.removeAttribute('_h5p_mo_');
  1604. } else {
  1605. const actionBoxRelation = param;
  1606. domNodes = actionBoxRelation.domNodes;
  1607. }
  1608.  
  1609. if (domNodes) {
  1610. for (const domNode of domNodes) domNode.removeAttribute('_h5p_mo_')
  1611. domNodes.length = 0;
  1612. }
  1613.  
  1614.  
  1615. },
  1616.  
  1617. actionBoxMutationCallback: function(mutations, observer) {
  1618. for (const mutation of mutations) {
  1619. let pElm = mutation.target;
  1620. let vpid = null;
  1621. if (pElm && pElm.nodeType > 0 && (vpid = pElm.getAttribute('_h5p_mo_'))) {
  1622. const actionBoxRelation = $hs.actionBoxRelations[vpid]
  1623. if (actionBoxRelation) {
  1624. actionBoxRelation.mutationCount++;
  1625. } else {
  1626. $hs.actionBoxRelationClearNodes(pElm);
  1627. }
  1628. }
  1629. }
  1630. },
  1631.  
  1632.  
  1633. getActionBoxRelationFromDOM: function(elm) {
  1634.  
  1635. //assume action boxes are mutually exclusive
  1636.  
  1637. for (let vpid in $hs.actionBoxRelations) {
  1638. const actionBoxRelation = $hs.actionBoxRelations[vpid];
  1639. const actionBox = actionBoxRelation.actionBox
  1640. //console.log('ab', actionBox)
  1641. if (actionBox && actionBox.parentNode) {
  1642. if (elm == actionBox || actionBox.contains(elm)) {
  1643. return actionBoxRelation;
  1644. }
  1645. }
  1646. }
  1647.  
  1648.  
  1649. return null;
  1650.  
  1651. },
  1652.  
  1653.  
  1654.  
  1655. _actionBoxObtain: function(player) {
  1656.  
  1657. if (!player) return null;
  1658. let vpid = player.getAttribute('_h5ppid');
  1659. if (!vpid) return null;
  1660. if (!player.parentNode) return null;
  1661.  
  1662. let actionBoxRelation = $hs.actionBoxRelations[vpid],
  1663. layoutBox = null,
  1664. actionBox = null,
  1665. boxSearchResult = null,
  1666. fullscreenBtns = null,
  1667. wPlayer = null;
  1668.  
  1669. function a() {
  1670. wPlayer = $hs.getPlayerBlockElement(player);
  1671. layoutBox = wPlayer.parentNode;
  1672. boxSearchResult = $hs.getActionBlockElement(player, layoutBox);
  1673. console.log('box search', boxSearchResult)
  1674. actionBox = boxSearchResult.actionBox
  1675. fullscreenBtns = boxSearchResult.fullscreenBtns
  1676. }
  1677.  
  1678. function b(domNodes) {
  1679. $hs.actionBoxRelations[vpid] = {
  1680. player: player,
  1681. wPlayer: wPlayer,
  1682. layoutBox: layoutBox,
  1683. actionBox: actionBox,
  1684. mutationCount: 0,
  1685. domNodes: domNodes,
  1686. fullscreenBtns: fullscreenBtns
  1687. }
  1688. for (const domNode of domNodes) {
  1689. domNode.setAttribute('_h5p_mo_', vpid);
  1690. $hs.actionBoxMutationObserver.observe(domNode, {
  1691. childList: true
  1692. });
  1693. }
  1694. }
  1695.  
  1696. if (actionBoxRelation) {
  1697. if (actionBoxRelation.actionBox && actionBoxRelation.actionBox.parentNode && actionBoxRelation.layoutBox && actionBoxRelation.layoutBox.parentNode) {
  1698. if (actionBoxRelation.mutationCount === 0) return actionBoxRelation.actionBox
  1699. a();
  1700. if (actionBox == actionBoxRelation.actionBox && layoutBox == actionBoxRelation.layoutBox && wPlayer == actionBoxRelation.wPlayer) {
  1701. actionBoxRelation.mutationCount = 0;
  1702. actionBoxRelation.fullscreenBtns = fullscreenBtns;
  1703. return actionBox
  1704. }
  1705. }
  1706. $hs.actionBoxRelationClearNodes(actionBoxRelation);
  1707. for (var k in actionBoxRelation) delete actionBoxRelation[k]
  1708. actionBoxRelation = null;
  1709. delete $hs.actionBoxRelations[vpid]
  1710. }
  1711.  
  1712. if (boxSearchResult == null) a();
  1713. if (actionBox) {
  1714. actionBox.setAttribute('_h5p_actionbox_', vpid);
  1715. if (!$hs.actionBoxMutationObserver) $hs.actionBoxMutationObserver = new MutationObserver($hs.actionBoxMutationCallback);
  1716. const domNodes = [];
  1717. let pElm = player;
  1718. let containing = 0;
  1719. while (pElm) {
  1720. domNodes.push(pElm);
  1721. if (pElm === actionBox) containing |= 1;
  1722. if (pElm === layoutBox) containing |= 2;
  1723. if (containing === 3) {
  1724. b(domNodes);
  1725. return actionBox
  1726. }
  1727. pElm = pElm.parentNode;
  1728. }
  1729. }
  1730.  
  1731. return null;
  1732.  
  1733.  
  1734. // if (!actionBox.hasAttribute('tabindex')) actionBox.setAttribute('tabindex', '-1');
  1735.  
  1736.  
  1737.  
  1738.  
  1739. },
  1740.  
  1741. videoSrcFound: function(player) {
  1742.  
  1743. // src loaded
  1744.  
  1745. if (!player) return;
  1746. let vpid = player.getAttribute('_h5ppid') || null;
  1747. if (!vpid || !player.currentSrc) return;
  1748.  
  1749. player._isThisPausedBefore_ = false;
  1750.  
  1751. player.removeAttribute('_h5p_uid_encrypted');
  1752.  
  1753. if (player._record_continuous) player._record_continuous._lastSave = -999; //first time must save
  1754.  
  1755. let uid_A = location.pathname.replace(/[^\d+]/g, '') + '.' + location.search.replace(/[^\d+]/g, '');
  1756. let _uid = location.hostname.replace('www.', '').toLowerCase() + '!' + location.pathname.toLowerCase() + 'A' + uid_A + 'W' + player.videoWidth + 'H' + player.videoHeight + 'L' + (player.duration << 0);
  1757.  
  1758. digestMessage(_uid).then(function(_uid_encrypted) {
  1759.  
  1760. let d = +new Date;
  1761.  
  1762. let recordedTime = null;
  1763.  
  1764. ;
  1765. (function() {
  1766. //read the last record only;
  1767.  
  1768. let k1 = '_h5_player_play_progress_';
  1769. let k1n = '_play_progress_';
  1770. let k2 = _uid_encrypted;
  1771. let k3 = k1 + k2;
  1772. let k3n = k1n + k2;
  1773. let m2 = Store._keys().filter(key => key.substr(0, k3.length) == k3); //all progress records for this video
  1774. let m2v = m2.map(keyName => +(keyName.split('+')[1] || '0'))
  1775. let m2vMax = Math.max(0, ...m2v)
  1776. if (!m2vMax) recordedTime = null;
  1777. else {
  1778. let _json_recordedTime = null;
  1779. _json_recordedTime = Store.read(k3n + '+' + m2vMax);
  1780. if (!_json_recordedTime) _json_recordedTime = {};
  1781. else _json_recordedTime = jsonParse(_json_recordedTime);
  1782. if (typeof _json_recordedTime == 'object') recordedTime = _json_recordedTime;
  1783. else recordedTime = null;
  1784. recordedTime = typeof recordedTime == 'object' ? recordedTime.t : recordedTime;
  1785. if (typeof recordedTime == 'number' && (+recordedTime >= 0 || +recordedTime <= 0)) {
  1786.  
  1787. } else if (typeof recordedTime == 'string' && recordedTime.length > 0 && (+recordedTime >= 0 || +recordedTime <= 0)) {
  1788. recordedTime = +recordedTime
  1789. } else {
  1790. recordedTime = null
  1791. }
  1792. }
  1793. if (recordedTime !== null) {
  1794. player._h5player_lastrecord_ = recordedTime;
  1795. } else {
  1796. player._h5player_lastrecord_ = null;
  1797. }
  1798. if (player._h5player_lastrecord_ > 5) {
  1799. consoleLog('last record playing', player._h5player_lastrecord_);
  1800. setTimeout(function() {
  1801. $hs._tips(player, `Press Shift-R to restore Last Playback: ${$hs.toolFormatCT(player._h5player_lastrecord_)}`, 5000, 4000)
  1802. }, 1000)
  1803. }
  1804.  
  1805. })();
  1806. // delay the recording by 5.4s => prevent ads or mis operation
  1807. setTimeout(function() {
  1808.  
  1809. let k1 = '_h5_player_play_progress_';
  1810. let k1n = '_play_progress_';
  1811. let k2 = _uid_encrypted;
  1812. let k3 = k1 + k2;
  1813. let k3n = k1n + k2;
  1814.  
  1815. //re-read all the localStorage keys
  1816. let m1 = Store._keys().filter(key => key.substr(0, k1.length) == k1); //all progress records in this site
  1817. let p = m1.length + 1;
  1818.  
  1819. for (const key of m1) { //all progress records for this video
  1820. if (key.substr(0, k3.length) == k3) {
  1821. Store._removeItem(key); //remove previous record for the current video
  1822. p--;
  1823. }
  1824. }
  1825.  
  1826. if (recordedTime !== null) {
  1827. Store.save(k3n + '+' + d, jsonStringify({
  1828. 't': recordedTime
  1829. })) //prevent loss of last record
  1830. }
  1831.  
  1832. const _record_max_ = 48;
  1833. const _record_keep_ = 26;
  1834.  
  1835. if (p > _record_max_) {
  1836. //exisiting 48 records for one site;
  1837. //keep only 26 records
  1838.  
  1839. const comparator = (a, b) => (a.t < b.t ? -1 : a.t > b.t ? 1 : 0);
  1840.  
  1841. m1
  1842. .map(keyName => ({
  1843. keyName,
  1844. t: +(keyName.split('+')[1] || '0')
  1845. }))
  1846. .sort(comparator)
  1847. .slice(0, -_record_keep_)
  1848. .forEach((item) => localStorage.removeItem(item.keyName));
  1849.  
  1850. consoleLog(`stored progress: reduced to ${_record_keep_}`)
  1851. }
  1852.  
  1853. player.setAttribute('_h5p_uid_encrypted', _uid_encrypted + '+' + d);
  1854.  
  1855. //try to start recording
  1856. if (player._record_continuous) player._record_continuous.playingWithRecording();
  1857.  
  1858. }, 5400);
  1859.  
  1860. })
  1861.  
  1862. },
  1863. bindDocEvents: function(rootNode) {
  1864. if (!rootNode._onceBindedDocEvents) {
  1865.  
  1866. rootNode._onceBindedDocEvents = true;
  1867. rootNode.addEventListener('keydown', $hs.handlerRootKeyDownEvent, true)
  1868. document._debug_rootNode_ = rootNode;
  1869.  
  1870. rootNode.addEventListener('mouseenter', $hs.handlerElementMouseEnter, true)
  1871. rootNode.addEventListener('mousedown', $hs.handlerElementMouseDown, true)
  1872. rootNode.addEventListener('dblclick', $hs.handlerElementDblClick, true)
  1873. rootNode.addEventListener('wheel', $hs.handlerElementWheelTuneVolume, {
  1874. passive: false
  1875. });
  1876.  
  1877. // wheel - bubble events to keep it simple (i.e. it must be passive:false & capture:false)
  1878.  
  1879.  
  1880. rootNode.addEventListener('focus', $hs.handlerElementFocus, true)
  1881. rootNode.addEventListener('fullscreenchange', $hs.handlerFullscreenChanged, true)
  1882.  
  1883. }
  1884. },
  1885. fireGlobalInit: function() {
  1886. if ($hs.intVideoInitCount != 1) return;
  1887. if (!$hs.varSrcList) $hs.varSrcList = {};
  1888. $hs.isLostFocus = null;
  1889. try {
  1890. //iframe may not be able to control top window
  1891. //error; just ignore with async
  1892. let topDoc = window.top && window.top.document ? window.top.document : null;
  1893. if (topDoc) {
  1894. topDoc.addEventListener('focusout', $hs.handlerDocFocusOut, true)
  1895. topDoc.addEventListener('focusin', $hs.handlerDocFocusIn, true)
  1896. }
  1897.  
  1898. } catch (e) {}
  1899. Store.clearInvalid(_sVersion_)
  1900. },
  1901. onVideoTriggering: function() {
  1902.  
  1903.  
  1904. // initialize a single video player - h5Player.playerInstance
  1905.  
  1906. /**
  1907. * 初始化播放器實例
  1908. */
  1909. let player = $hs.playerInstance
  1910. if (!player) return
  1911.  
  1912. let vpid = player.getAttribute('_h5ppid');
  1913.  
  1914. if (!vpid) return;
  1915.  
  1916. let firstTime = !!$hs.initTips()
  1917. if (firstTime) {
  1918. // first time to trigger this player
  1919. if (!player.hasAttribute('playsinline')) player.setAttribute('playsinline', 'playsinline');
  1920. if (!player.hasAttribute('x-webkit-airplay')) player.setAttribute('x-webkit-airplay', 'deny');
  1921. if (!player.hasAttribute('preload')) player.setAttribute('preload', 'auto');
  1922. //player.style['image-rendering'] = 'crisp-edges';
  1923. $hs.playbackRate = $hs.getPlaybackRate()
  1924. }
  1925.  
  1926. },
  1927. getPlaybackRate: function() {
  1928. let playbackRate = Store.read('_playback_rate_') || $hs.playbackRate
  1929. return Number(Number(playbackRate).toFixed(1))
  1930. },
  1931. getPlayerBlockElement: function(player, useCache) {
  1932.  
  1933. let layoutBox = null,
  1934. wPlayer = null
  1935.  
  1936. if (!player || !player.offsetHeight || !player.offsetWidth || !player.parentNode) {
  1937. return null;
  1938. }
  1939.  
  1940.  
  1941. if (useCache === true) {
  1942. let vpid = player.getAttribute('_h5ppid');
  1943. let actionBoxRelation = $hs.actionBoxRelations[vpid]
  1944. if (actionBoxRelation && actionBoxRelation.mutationCount === 0) {
  1945. return actionBoxRelation.wPlayer
  1946. }
  1947. }
  1948.  
  1949.  
  1950. //without checkActiveBox, just a DOM for you to append tipsDom
  1951.  
  1952. function oWH(elm) {
  1953. return [elm.offsetWidth, elm.offsetHeight].join(',');
  1954. }
  1955.  
  1956. function search_nodes() {
  1957.  
  1958. wPlayer = player; // NOT NULL
  1959. layoutBox = wPlayer.parentNode; // NOT NULL
  1960.  
  1961. while (layoutBox.parentNode && layoutBox.nodeType == 1 && layoutBox.offsetHeight == 0) {
  1962. wPlayer = layoutBox; // NOT NULL
  1963. layoutBox = layoutBox.parentNode; // NOT NULL
  1964. }
  1965. //container must be with offsetHeight
  1966.  
  1967. while (layoutBox.parentNode && layoutBox.nodeType == 1 && layoutBox.offsetHeight < player.offsetHeight) {
  1968. wPlayer = layoutBox; // NOT NULL
  1969. layoutBox = layoutBox.parentNode; // NOT NULL
  1970. }
  1971. //container must have height >= player height
  1972.  
  1973. const layoutOWH = oWH(layoutBox)
  1974. //const playerOWH=oWH(player)
  1975.  
  1976. //skip all inner wraps
  1977. while (layoutBox.parentNode && layoutBox.nodeType == 1 && oWH(layoutBox.parentNode) == layoutOWH) {
  1978. wPlayer = layoutBox; // NOT NULL
  1979. layoutBox = layoutBox.parentNode; // NOT NULL
  1980. }
  1981.  
  1982. // oWH of layoutBox.parentNode != oWH of layoutBox and layoutBox.offsetHeight >= player.offsetHeight
  1983.  
  1984. }
  1985.  
  1986. search_nodes();
  1987.  
  1988. if (layoutBox.nodeType == 11) {
  1989. makeNoRoot(layoutBox);
  1990. search_nodes();
  1991. }
  1992.  
  1993.  
  1994.  
  1995. //condition:
  1996. //!layoutBox.parentNode || layoutBox.nodeType != 1 || layoutBox.offsetHeight > player.offsetHeight
  1997.  
  1998. // layoutBox is a node contains <video> and offsetHeight>=video.offsetHeight
  1999. // wPlayer is a HTML Element (nodeType==1)
  2000. // you can insert the DOM element into the layoutBox
  2001.  
  2002. if (layoutBox && wPlayer && layoutBox.nodeType === 1 && wPlayer.parentNode == layoutBox && layoutBox.parentNode) return wPlayer;
  2003. throw 'unknown error';
  2004.  
  2005. },
  2006. getCommonContainer: function(elm1, elm2) {
  2007.  
  2008. let box1 = elm1;
  2009. let box2 = elm2;
  2010.  
  2011. while (box1 && box2) {
  2012. if (box1.contains(box2) || box2.contains(box1)) {
  2013. break;
  2014. }
  2015. box1 = box1.parentNode;
  2016. box2 = box2.parentNode;
  2017. }
  2018.  
  2019. let layoutBox = null;
  2020.  
  2021. box1 = (box1 && box1.contains(elm2)) ? box1 : null;
  2022. box2 = (box2 && box2.contains(elm1)) ? box2 : null;
  2023.  
  2024. if (box1 && box2) layoutBox = box1.contains(box2) ? box2 : box1;
  2025. else layoutBox = box1 || box2 || null;
  2026.  
  2027. return layoutBox
  2028.  
  2029. },
  2030. change_layoutBox: function(tipsDom) {
  2031. let player = $hs.player()
  2032. if (!player) return;
  2033. let wPlayer = $hs.getPlayerBlockElement(player, true);
  2034. let layoutBox = wPlayer.parentNode;
  2035.  
  2036. if ((layoutBox && layoutBox.nodeType == 1) && (!tipsDom.parentNode || tipsDom.parentNode !== layoutBox)) {
  2037.  
  2038. consoleLog('changed_layoutBox')
  2039. layoutBox.insertBefore(tipsDom, wPlayer);
  2040.  
  2041. }
  2042. },
  2043.  
  2044. _hasEventListener:function(elm, p){
  2045.  
  2046. if(elm && elm._listeners){
  2047.  
  2048. const cache = elm._listeners[p]
  2049. return cache&&cache.funcCount>0
  2050.  
  2051. }
  2052. return false;
  2053.  
  2054. },
  2055.  
  2056. queryFullscreenBtnsIndependant: function(parentNode) {
  2057.  
  2058. let btns = [];
  2059.  
  2060. function elmCallback(elm) {
  2061.  
  2062. let hasClickListeners = null,
  2063. childElementCount = null,
  2064. isVisible = null,
  2065. btnElm = elm;
  2066. var pElm = elm;
  2067. while (pElm && pElm.nodeType === 1 && pElm != parentNode && pElm.querySelector('video') === null) {
  2068.  
  2069. let funcTest= typeof pElm.onclick == 'function' || $hs._hasEventListener(pElm,'click');
  2070. funcTest= funcTest || typeof pElm.onmousedown == 'function' || $hs._hasEventListener(pElm,'mousedown');
  2071. funcTest= funcTest || typeof pElm.onmouseup == 'function' || $hs._hasEventListener(pElm,'mouseup');
  2072.  
  2073. if (funcTest) {
  2074. hasClickListeners = true
  2075. btnElm = pElm;
  2076. break;
  2077. }
  2078.  
  2079. pElm = pElm.parentNode;
  2080. }
  2081. if (btns.indexOf(btnElm) >= 0) return; //btn>a.fullscreen-1>b.fullscreen-2>c.fullscreen-3
  2082.  
  2083. if ('_listeners' in elm) {
  2084.  
  2085. //hasClickListeners = elm._listeners && elm._listeners.click && elm._listeners.click.funcCount > 0
  2086.  
  2087. }
  2088.  
  2089. if ('childElementCount' in elm) {
  2090.  
  2091. childElementCount = elm.childElementCount;
  2092.  
  2093. }
  2094. if ('offsetParent' in elm) {
  2095. isVisible = !!elm.offsetParent; //works with parent/self display none; not work with visiblity hidden / opacity0
  2096.  
  2097. }
  2098.  
  2099. if (hasClickListeners) {
  2100. let btn = {
  2101. elm,
  2102. btnElm,
  2103. isVisible,
  2104. hasClickListeners,
  2105. childElementCount,
  2106. isContained: null
  2107. };
  2108.  
  2109. //console.log('btnElm', btnElm)
  2110.  
  2111. btns.push(btnElm)
  2112.  
  2113. }
  2114. }
  2115.  
  2116.  
  2117. for (const elm of parentNode.querySelectorAll('[class*="full"][class*="screen"]')) {
  2118. let className = (elm.getAttribute('class') || "");
  2119. if (/\b(fullscreen|full-screen)\b/i.test(className.replace(/([A-Z][a-z]+)/g, '-$1-').replace(/[\_\-]+/g, '-'))) {
  2120. elmCallback(elm)
  2121. }
  2122. }
  2123.  
  2124.  
  2125. for (const elm of parentNode.querySelectorAll('[id*="full"][id*="screen"]')) {
  2126. let idName = (elm.getAttribute('id') || "");
  2127. if (/\b(fullscreen|full-screen)\b/i.test(idName.replace(/([A-Z][a-z]+)/g, '-$1-').replace(/[\_\-]+/g, '-'))) {
  2128. elmCallback(elm)
  2129. }
  2130. }
  2131.  
  2132. for (const elm of parentNode.querySelectorAll('[name*="full"][name*="screen"]')) {
  2133. let nName = (elm.getAttribute('name') || "");
  2134. if (/\b(fullscreen|full-screen)\b/i.test(nName.replace(/([A-Z][a-z]+)/g, '-$1-').replace(/[\_\-]+/g, '-'))) {
  2135. elmCallback(elm)
  2136. }
  2137. }
  2138.  
  2139.  
  2140. return btns;
  2141.  
  2142. },
  2143. exclusiveElements: function(elms) {
  2144.  
  2145. //not containing others
  2146. let res = [];
  2147.  
  2148. for (const roleElm of elms) {
  2149.  
  2150. let isContained = false;
  2151. for (const testElm of elms) {
  2152. if (testElm != roleElm && roleElm.contains(testElm)) {
  2153. isContained = true;
  2154. break;
  2155. }
  2156. }
  2157. if (!isContained) res.push(roleElm)
  2158. }
  2159. return res;
  2160.  
  2161. },
  2162. callFullScreenBtn: function() {
  2163. console.log('callFullScreenBtn')
  2164.  
  2165.  
  2166.  
  2167. let player = $hs.player()
  2168. if (!player || !player.ownerDocument || !('exitFullscreen' in player.ownerDocument)) return;
  2169.  
  2170. let btnElement = null;
  2171.  
  2172. let vpid = player.getAttribute('_h5ppid') || null;
  2173.  
  2174. if (!vpid) return;
  2175.  
  2176.  
  2177. const chFull = $hs.toolCheckFullScreen(player.ownerDocument);
  2178.  
  2179.  
  2180.  
  2181. let actionBoxRelation = $hs.actionBoxRelations[vpid];
  2182.  
  2183. if (chFull === true) {
  2184. player.ownerDocument.exitFullscreen();
  2185. return;
  2186. } else if (chFull === false) {
  2187. if (actionBoxRelation && actionBoxRelation.actionBox) {
  2188. let actionBox = actionBoxRelation.actionBox;
  2189. let btnElements = actionBoxRelation.fullscreenBtns;
  2190.  
  2191. if (btnElements && btnElements.length > 0) {
  2192.  
  2193.  
  2194. let btnElement_idx = btnElements._only_idx;
  2195.  
  2196. if (btnElement_idx >= 0) {
  2197.  
  2198. } else if (btnElements.length === 1) {
  2199. btnElement_idx = 0;
  2200. } else if (btnElements.length > 1) {
  2201. //web-fullscreen-on/off ; fullscreen-on/off ....
  2202.  
  2203. const strList = btnElements.map(elm => [elm.className || 'null', elm.id || 'null', elm.name || 'null'].join('-').replace(/([A-Z][a-z]+)/g, '-$1-').replace(/[\_\-]+/g, '-'))
  2204.  
  2205. const filterOutScores = new Array(strList.length).fill(0);
  2206. const filterInScores = new Array(strList.length).fill(0);
  2207. const filterScores = new Array(strList.length).fill(0);
  2208. for (const [j, str] of strList.entries()) {
  2209. if (/\b(fullscreen|full-screen)\b/i.test(str)) filterInScores[j] += 1
  2210. if (/\b(web-fullscreen|web-full-screen)\b/i.test(str)) filterOutScores[j] += 1
  2211. if (/\b(fullscreen-on|full-screen-on)\b/i.test(str)) filterInScores[j] += 1
  2212. if (/\b(fullscreen-off|full-screen-off)\b/i.test(str)) filterOutScores[j] += 1
  2213. if (/\b(on-fullscreen|on-full-screen)\b/i.test(str)) filterInScores[j] += 1
  2214. if (/\b(off-fullscreen|off-full-screen)\b/i.test(str)) filterOutScores[j] += 1
  2215. }
  2216.  
  2217. let maxScore = -1e7;
  2218. for (const [j, str] of strList.entries()) {
  2219. filterScores[j] = filterInScores[j] * 3 - filterOutScores[j] * 2
  2220. if (filterScores[j] > maxScore) maxScore = filterScores[j];
  2221. }
  2222. btnElement_idx = filterScores.indexOf(maxScore)
  2223. if (btnElement_idx < 0) btnElement_idx = 0; //unknown
  2224. }
  2225.  
  2226. btnElements._only_idx = btnElement_idx
  2227.  
  2228. btnElement = btnElements[btnElement_idx];
  2229.  
  2230. //consoleLog('original fullscreen')
  2231. window.requestAnimationFrame(() => btnElement.click());
  2232. return;
  2233.  
  2234. }
  2235.  
  2236.  
  2237. }
  2238.  
  2239. }
  2240.  
  2241. let gPlayer = getRoot(player).querySelector(`[_h5p_fsElm_="${vpid}"]`); //it is set in fullscreenchange
  2242.  
  2243. if (gPlayer) {
  2244.  
  2245. } else if (actionBoxRelation && actionBoxRelation.actionBox) {
  2246. gPlayer = actionBoxRelation.actionBox;
  2247. } else if (actionBoxRelation && actionBoxRelation.layoutBox) {
  2248. gPlayer = actionBoxRelation.layoutBox;
  2249. } else {
  2250. gPlayer = player;
  2251. }
  2252.  
  2253. consoleLog('DOM fullscreen', gPlayer)
  2254. try {
  2255. gPlayer.requestFullscreen() //known bugs : TypeError: fullscreen error
  2256. } catch (e) {
  2257. consoleLogF('fullscreen error', e)
  2258. }
  2259.  
  2260.  
  2261. },
  2262. /* 設置播放速度 */
  2263. setPlaybackRate: function(num, flagTips) {
  2264. let player = $hs.player()
  2265. let curPlaybackRate
  2266. if (num) {
  2267. num = +num
  2268. if (num > 0) { // also checking the type of variable
  2269. curPlaybackRate = num < 0.1 ? 0.1 : +(num.toFixed(1))
  2270. } else {
  2271. console.error('h5player: 播放速度轉換出錯')
  2272. return false
  2273. }
  2274. } else {
  2275. curPlaybackRate = $hs.getPlaybackRate()
  2276. }
  2277. /* 記錄播放速度的信息 */
  2278.  
  2279. let changed = curPlaybackRate !== player.playbackRate;
  2280.  
  2281. if (curPlaybackRate !== player.playbackRate) {
  2282.  
  2283. Store.save('_playback_rate_', curPlaybackRate + '')
  2284. $hs.playbackRate = curPlaybackRate
  2285. player.playbackRate = curPlaybackRate
  2286. /* 本身處於1被播放速度的時候不再提示 */
  2287. //if (!num && curPlaybackRate === 1) return;
  2288.  
  2289. }
  2290.  
  2291. flagTips = (flagTips < 0) ? false : (flagTips > 0) ? true : changed;
  2292. if (flagTips) $hs.tips('Playback speed: ' + player.playbackRate + 'x')
  2293. },
  2294. tuneCurrentTime: function(amount, flagTips) {
  2295. let _amount = +(+amount).toFixed(1);
  2296. let player = $hs.player();
  2297. if (_amount >= 0 || _amount < 0) {} else {
  2298. return;
  2299. }
  2300.  
  2301. let newCurrentTime = player.currentTime + _amount;
  2302. if (newCurrentTime < 0) newCurrentTime = 0;
  2303. if (newCurrentTime > player.duration) newCurrentTime = player.duration;
  2304.  
  2305. let changed = newCurrentTime != player.currentTime && newCurrentTime >= 0 && newCurrentTime <= player.duration;
  2306.  
  2307. if (changed) {
  2308. //player.currentTime = newCurrentTime;
  2309. player.pause();
  2310. let t_ch = (Math.random() / 5 + .75);
  2311. player.currentTime = newCurrentTime * t_ch + player.currentTime * (1.0 - t_ch);
  2312. setTimeout(() => {
  2313. player.play();
  2314. player.currentTime = newCurrentTime;
  2315. }, 33);
  2316. flagTips = (flagTips < 0) ? false : (flagTips > 0) ? true : changed;
  2317. $hs.tips(false);
  2318. if (flagTips) {
  2319. if (_amount > 0) $hs.tips(_amount + ' Sec. Forward', undefined, 3000);
  2320. else $hs.tips(-_amount + ' Sec. Backward', undefined, 3000)
  2321. }
  2322. }
  2323.  
  2324. },
  2325. tuneVolume: function(amount) {
  2326. let _amount = +(+amount).toFixed(2);
  2327.  
  2328. let player = $hs.player()
  2329.  
  2330. let newVol = player.volume + _amount;
  2331. if (newVol < 0) newVol = 0;
  2332. if (newVol > 1) newVol = 1;
  2333. let chVol = player.volume !== newVol && newVol >= 0 && newVol <= 1;
  2334.  
  2335. if (chVol) {
  2336.  
  2337. if (_amount > 0 && player.volume < 1) {
  2338. player.volume = newVol // positive
  2339. } else if (_amount < 0 && player.volume > 0) {
  2340. player.volume = newVol // negative
  2341. }
  2342. $hs.tips(false);
  2343. $hs.tips('Volume: ' + dround(player.volume * 100) + '%', undefined)
  2344. }
  2345. },
  2346. switchPlayStatus: function() {
  2347. let player = $hs.player()
  2348. if (player.paused) {
  2349. player.play()
  2350. if (player._isThisPausedBefore_) {
  2351. $hs.tips(false);
  2352. $hs.tips('Playback resumed', undefined, 2500)
  2353. }
  2354. } else {
  2355. player.pause()
  2356. $hs.tips(false);
  2357. $hs.tips('Playback paused', undefined, 2500)
  2358. }
  2359. },
  2360. tipsClassName: 'html_player_enhance_tips',
  2361. _tips: function(player, str, duration, order) {
  2362.  
  2363.  
  2364. if (!player.getAttribute('_h5player_tips')) $hs.initTips();
  2365.  
  2366. let tipsSelector = '#' + (player.getAttribute('_h5player_tips') || $hs.tipsClassName) //if this attribute still doesnt exist, set it to the base cls name
  2367. let tipsDom = getRoot(player).querySelector(tipsSelector)
  2368. if (!tipsDom) {
  2369. consoleLog('init h5player tips dom error...')
  2370. return false
  2371. }
  2372. $hs.change_layoutBox(tipsDom);
  2373.  
  2374.  
  2375.  
  2376. if (str === false) {
  2377. tipsDom.textContent = '';
  2378. tipsDom.setAttribute('_potTips_', '0')
  2379. } else {
  2380. order = order || 1000
  2381. tipsDom.tipsOrder = tipsDom.tipsOrder || 0;
  2382.  
  2383. let shallDisplay = true
  2384. if (order < tipsDom.tipsOrder && getComputedStyle(tipsDom).opacity > 0) shallDisplay = false
  2385.  
  2386. if (shallDisplay) {
  2387. tipsDom._playerElement = player;
  2388. tipsDom._playerVPID = player.getAttribute('_h5ppid');
  2389. tipsDom._playerBlockElm = $hs.getPlayerBlockElement(player, true)
  2390.  
  2391. if (duration === undefined) duration = 2000
  2392. tipsDom.textContent = str
  2393. tipsDom.setAttribute('_potTips_', '2')
  2394.  
  2395. if (duration > 0) {
  2396. $ws.requestAnimationFrame(() => tipsDom.setAttribute('_potTips_', '1'))
  2397. } else {
  2398. order = -1;
  2399. }
  2400.  
  2401. tipsDom.tipsOrder = order
  2402.  
  2403. }
  2404.  
  2405. }
  2406.  
  2407.  
  2408. if (window.ResizeObserver) {
  2409. //observe not fire twice for the same element.
  2410. if (!$hs.observer_resizeVideos) $hs.observer_resizeVideos = new ResizeObserver(hanlderResizeVideo)
  2411. $hs.observer_resizeVideos.observe(tipsDom._playerBlockElm.parentNode)
  2412. $hs.observer_resizeVideos.observe(tipsDom._playerBlockElm)
  2413. $hs.observer_resizeVideos.observe(player)
  2414. }
  2415. //ensure function called
  2416. window.requestAnimationFrame(() => $hs.fixNonBoxingVideoTipsPosition(tipsDom, player))
  2417.  
  2418. },
  2419. tips: function(str, duration, order) {
  2420. let player = $hs.player()
  2421. if (!player) {
  2422. consoleLog('h5Player Tips:', str)
  2423. return true
  2424. }
  2425.  
  2426. return $hs._tips(player, str, duration, order)
  2427.  
  2428. },
  2429. listOfTipsDom: [],
  2430. getPotTips: function(arr) {
  2431. const res = [];
  2432. for (const tipsDom of $hs.listOfTipsDom) {
  2433. if (tipsDom && tipsDom.nodeType > 0 && tipsDom.parentNode && tipsDom.ownerDocument) {
  2434. if (tipsDom._playerBlockElm && tipsDom._playerBlockElm.parentNode) {
  2435. const potTipsAttr = tipsDom.getAttribute('_potTips_')
  2436. if (arr.indexOf(potTipsAttr) >= 0) res.push(tipsDom)
  2437. }
  2438. }
  2439. }
  2440. return res;
  2441. },
  2442. initTips: function() {
  2443. /* 設置提示DOM的樣式 */
  2444. let player = $hs.player()
  2445. let shadowRoot = getRoot(player);
  2446. let doc = player.ownerDocument;
  2447. //console.log((document.documentElement.qq=player),shadowRoot,'xax')
  2448. let parentNode = player.parentNode
  2449. let tcn = player.getAttribute('_h5player_tips') || ($hs.tipsClassName + '_' + (+new Date));
  2450. player.setAttribute('_h5player_tips', tcn)
  2451. if (shadowRoot.querySelector('#' + tcn)) return false;
  2452.  
  2453. if (!shadowRoot._onceAddedCSS) {
  2454. shadowRoot._onceAddedCSS = true;
  2455.  
  2456. let cssStyle = `
  2457. [_potTips_="1"]{
  2458. animation: 2s linear 0s normal forwards 1 delayHide;
  2459. }
  2460. [_potTips_="0"]{
  2461. opacity:0; transform:translate(-9999px);
  2462. }
  2463. [_potTips_="2"]{
  2464. opacity:.95; transform: translate(0,0);
  2465. }
  2466.  
  2467. @keyframes delayHide{
  2468. 0%, 99% { opacity:0.95; transform: translate(0,0); }
  2469. 100% { opacity:0; transform:translate(-9999px); }
  2470. }
  2471. ` + `
  2472. [_potTips_]{
  2473. font-weight: bold !important;
  2474. position: absolute !important;
  2475. z-index: 999 !important;
  2476. font-size: ${$hs.fontSize || 16}px !important;
  2477. padding: 0px !important;
  2478. border:none !important;
  2479. background: rgba(0,0,0,0) !important;
  2480. color:#738CE6 !important;
  2481. text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
  2482. top: 50%;
  2483. left: 50%;
  2484. max-width:500px;max-height:50px;
  2485. border-radius:3px;
  2486. font-family: 'microsoft yahei', Verdana, Geneva, sans-serif;
  2487. pointer-events: none;
  2488. }
  2489. body div[_potTips_]{
  2490. -webkit-user-select: none !important;
  2491. -moz-user-select: none !important;
  2492. -ms-user-select: none !important;
  2493. user-select: none !important;
  2494. -webkit-touch-callout: none !important;
  2495. -webkit-user-select: none !important;
  2496. -khtml-user-drag: none !important;
  2497. -khtml-user-select: none !important;
  2498. -moz-user-select: none !important;
  2499. -moz-user-select: -moz-none !important;
  2500. -ms-user-select: none !important;
  2501. user-select: none !important;
  2502. }
  2503. `.replace(/\r\n/g, '');
  2504.  
  2505.  
  2506. let cssContainer = domAppender(shadowRoot);
  2507.  
  2508.  
  2509. if (!cssContainer) {
  2510. cssContainer = makeNoRoot(shadowRoot)
  2511. }
  2512.  
  2513. domTool.addStyle(cssStyle, cssContainer);
  2514.  
  2515. }
  2516.  
  2517. let tipsDom = doc.createElement('div')
  2518.  
  2519. tipsDom.addEventListener(crossBrowserTransition('animation'), function(e) {
  2520. if (this.getAttribute('_potTips_') == '1') {
  2521. this.setAttribute('_potTips_', '0')
  2522. }
  2523. })
  2524.  
  2525. tipsDom.id = tcn;
  2526. tipsDom.setAttribute('_potTips_', '0');
  2527. $hs.listOfTipsDom.push(tipsDom);
  2528. $hs.change_layoutBox(tipsDom);
  2529.  
  2530. return true;
  2531. },
  2532.  
  2533. responsiveSizing: function(container, elm) {
  2534.  
  2535. let gcssP = getComputedStyle(container);
  2536.  
  2537. let gcssE = getComputedStyle(elm);
  2538.  
  2539. //console.log(gcssE.left,gcssP.width)
  2540. let elmBound = {
  2541. left: parseFloat(gcssE.left) / parseFloat(gcssP.width),
  2542. width: parseFloat(gcssE.width) / parseFloat(gcssP.width),
  2543. top: parseFloat(gcssE.top) / parseFloat(gcssP.height),
  2544. height: parseFloat(gcssE.height) / parseFloat(gcssP.height)
  2545. };
  2546.  
  2547. let elm00 = [elmBound.left, elmBound.top];
  2548. let elm01 = [elmBound.left + elmBound.width, elmBound.top];
  2549. let elm10 = [elmBound.left, elmBound.top + elmBound.height];
  2550. let elm11 = [elmBound.left + elmBound.width, elmBound.top + elmBound.height];
  2551.  
  2552. return {
  2553. elm00,
  2554. elm01,
  2555. elm10,
  2556. elm11,
  2557. plw: elmBound.width,
  2558. plh: elmBound.height
  2559. };
  2560.  
  2561. },
  2562.  
  2563. fixNonBoxingVideoTipsPosition: function(tipsDom, player) {
  2564.  
  2565. if (!tipsDom || !player) return;
  2566.  
  2567. let ct = $hs.getCommonContainer(tipsDom, player)
  2568.  
  2569. if (!ct) return;
  2570.  
  2571. //relative
  2572.  
  2573. let elm00 = $hs.responsiveSizing(ct, player).elm00;
  2574.  
  2575. if (isNaN(elm00[0]) || isNaN(elm00[1])) {
  2576.  
  2577. [tipsDom.style.left, tipsDom.style.top] = [player.style.left, player.style.top];
  2578. //eg auto
  2579. } else {
  2580.  
  2581. let rlm00 = elm00.map(t => (t * 100).toFixed(2) + '%');
  2582. [tipsDom.style.left, tipsDom.style.top] = rlm00;
  2583.  
  2584. }
  2585.  
  2586. // absolute
  2587.  
  2588. let _offset = {
  2589. left: 10,
  2590. top: 15
  2591. };
  2592.  
  2593. let customOffset = {
  2594. left: _offset.left,
  2595. top: _offset.top
  2596. };
  2597. let p = tipsDom.getBoundingClientRect();
  2598. let q = player.getBoundingClientRect();
  2599. let currentPos = [p.left, p.top];
  2600.  
  2601. let targetPos = [q.left + player.offsetWidth * 0 + customOffset.left, q.top + player.offsetHeight * 0 + customOffset.top];
  2602.  
  2603. let mL = +tipsDom.style.marginLeft.replace('px', '') || 0;
  2604. if (isNaN(mL)) mL = 0;
  2605. let mT = +tipsDom.style.marginTop.replace('px', '') || 0;
  2606. if (isNaN(mT)) mT = 0;
  2607.  
  2608. let z1 = -(currentPos[0] - targetPos[0]);
  2609. let z2 = -(currentPos[1] - targetPos[1]);
  2610.  
  2611. if (z1 || z2) {
  2612.  
  2613. let y1 = z1 + mL;
  2614. let y2 = z2 + mT;
  2615.  
  2616. tipsDom.style.marginLeft = y1 + 'px';
  2617. tipsDom.style.marginTop = y2 + 'px';
  2618.  
  2619. }
  2620. },
  2621.  
  2622. playerTrigger: function(player, event) {
  2623. if (!player || !event) return
  2624. const pCode = event.code;
  2625. let keyAsm = (event.shiftKey ? SHIFT : 0) | ((event.ctrlKey || event.metaKey) ? CTRL : 0) | (event.altKey ? ALT : 0);
  2626.  
  2627.  
  2628. let vpid = player.getAttribute('_h5ppid') || null;
  2629. if (!vpid) return;
  2630. let playerConf = playerConfs[vpid]
  2631. if (!playerConf) return;
  2632.  
  2633. //shift + key
  2634. if (keyAsm == SHIFT) {
  2635. // 網頁FULLSCREEN
  2636. if (pCode === 'Enter') {
  2637. $hs.callFullScreenBtn()
  2638. return TERMINATE
  2639. } else if (pCode == 'KeyF') {
  2640. //change unsharpen filter
  2641.  
  2642. let resList = ["unsharpen3_05", "unsharpen3_10", "unsharpen5_05", "unsharpen5_10", "unsharpen9_05", "unsharpen9_10"]
  2643. let res = (prompt("Enter the unsharpen mask\n(" + resList.map(x => '"' + x + '"').join(', ') + ")", "unsharpen9_05") || "").toLowerCase();
  2644. if (resList.indexOf(res) < 0) res = ""
  2645. GM_setValue("unsharpen_mask", res)
  2646. for (const el of document.querySelectorAll('video[_h5p_uid_encrypted]')) {
  2647. if (el.style.filter == "" || el.style.filter) {
  2648. let filterStr1 = el.style.filter.replace(/\s*url\(\"#_h5p_unsharpen[\d\_]+\"\)/, '');
  2649. let filterStr2 = (res.length > 0 ? ' url("#_h5p_' + res + '")' : '')
  2650. el.style.filter = filterStr1 + filterStr2;
  2651. }
  2652. }
  2653. return TERMINATE
  2654.  
  2655. }
  2656. // 進入或退出畫中畫模式
  2657. else if (pCode == 'KeyP') {
  2658. $hs.pictureInPicture(player)
  2659.  
  2660. return TERMINATE
  2661. } else if (pCode == 'KeyR') {
  2662. if (player._h5player_lastrecord_ !== null && (player._h5player_lastrecord_ >= 0 || player._h5player_lastrecord_ <= 0)) {
  2663. $hs.setPlayProgress(player, player._h5player_lastrecord_)
  2664.  
  2665. return TERMINATE
  2666. }
  2667.  
  2668. } else if (pCode == 'KeyO') {
  2669. let _debug_h5p_logging_ch = false;
  2670. try {
  2671. Store._setItem('_h5_player_sLogging_', 1 - Store._getItem('_h5_player_sLogging_'))
  2672. _debug_h5p_logging_ = +Store._getItem('_h5_player_sLogging_') > 0;
  2673. _debug_h5p_logging_ch = true;
  2674. } catch (e) {
  2675.  
  2676. }
  2677. consoleLogF('_debug_h5p_logging_', !!_debug_h5p_logging_, 'changed', _debug_h5p_logging_ch)
  2678.  
  2679. if (_debug_h5p_logging_ch) {
  2680.  
  2681. return TERMINATE
  2682. }
  2683. } else if (pCode == 'KeyT') {
  2684. if (/^blob/i.test(player.currentSrc)) {
  2685. alert(`The current video is ${player.currentSrc}\nSorry, it cannot be opened in PotPlayer.`);
  2686. } else {
  2687. let confirm_res = confirm(`The current video is ${player.currentSrc}\nDo you want to open it in PotPlayer?`);
  2688. if (confirm_res) window.open('potplayer://' + player.currentSrc, '_blank');
  2689. }
  2690. return TERMINATE
  2691. }
  2692.  
  2693.  
  2694.  
  2695. let videoScale = playerConf.vFactor;
  2696.  
  2697. function tipsForVideoScaling() {
  2698.  
  2699. playerConf.vFactor = +videoScale.toFixed(1);
  2700.  
  2701. playerConf.cssTransform();
  2702. let tipsMsg = `視頻縮放率:${ +(videoScale * 100).toFixed(2) }%`
  2703. if (playerConf.translate.x) {
  2704. tipsMsg += `,水平位移:${playerConf.translate.x}px`
  2705. }
  2706. if (playerConf.translate.y) {
  2707. tipsMsg += `,垂直位移:${playerConf.translate.y}px`
  2708. }
  2709. $hs.tips(false);
  2710. $hs.tips(tipsMsg)
  2711.  
  2712.  
  2713. }
  2714.  
  2715. // 視頻畫面縮放相關事件
  2716.  
  2717. switch (pCode) {
  2718. // shift+X:視頻縮小 -0.1
  2719. case 'KeyX':
  2720. videoScale -= 0.1
  2721. if (videoScale < 0.1) videoScale = 0.1;
  2722. tipsForVideoScaling();
  2723. return TERMINATE
  2724. break
  2725. // shift+C:視頻放大 +0.1
  2726. case 'KeyC':
  2727. videoScale += 0.1
  2728. if (videoScale > 16) videoScale = 16;
  2729. tipsForVideoScaling();
  2730. return TERMINATE
  2731. break
  2732. // shift+Z:視頻恢復正常大小
  2733. case 'KeyZ':
  2734. videoScale = 1.0
  2735. playerConf.translate.x = 0;
  2736. playerConf.translate.y = 0;
  2737. tipsForVideoScaling();
  2738. return TERMINATE
  2739. break
  2740. case 'ArrowRight':
  2741. playerConf.translate.x += 10
  2742. tipsForVideoScaling();
  2743. return TERMINATE
  2744. break
  2745. case 'ArrowLeft':
  2746. playerConf.translate.x -= 10
  2747. tipsForVideoScaling();
  2748. return TERMINATE
  2749. break
  2750. case 'ArrowUp':
  2751. playerConf.translate.y -= 10
  2752. tipsForVideoScaling();
  2753. return TERMINATE
  2754. break
  2755. case 'ArrowDown':
  2756. playerConf.translate.y += 10
  2757. tipsForVideoScaling();
  2758. return TERMINATE
  2759. break
  2760.  
  2761. }
  2762.  
  2763. }
  2764. // 防止其它無關組合鍵衝突
  2765. if (!keyAsm) {
  2766. let kControl = null
  2767. let newPBR, oldPBR, nv, numKey;
  2768. switch (pCode) {
  2769. // 方向鍵右→:快進3秒
  2770. case 'ArrowRight':
  2771. $hs.tuneCurrentTime($hs.skipStep);
  2772. return TERMINATE;
  2773. break;
  2774. // 方向鍵左←:後退3秒
  2775. case 'ArrowLeft':
  2776. $hs.tuneCurrentTime(-$hs.skipStep);
  2777. return TERMINATE;
  2778. break;
  2779. // 方向鍵上↑:音量升高 1%
  2780. case 'ArrowUp':
  2781. if ((player.muted && player.volume === 0) && player._volume > 0) {
  2782.  
  2783. player.muted = false;
  2784. player.volume = player._volume;
  2785. } else if (player.muted && (player.volume > 0 || !player._volume)) {
  2786. player.muted = false;
  2787. }
  2788. $hs.tuneVolume(0.01);
  2789. return TERMINATE;
  2790. break;
  2791. // 方向鍵下↓:音量降低 1%
  2792. case 'ArrowDown':
  2793.  
  2794. if ((player.muted && player.volume === 0) && player._volume > 0) {
  2795.  
  2796. player.muted = false;
  2797. player.volume = player._volume;
  2798. } else if (player.muted && (player.volume > 0 || !player._volume)) {
  2799. player.muted = false;
  2800. }
  2801. $hs.tuneVolume(-0.01);
  2802. return TERMINATE;
  2803. break;
  2804. // 空格鍵:暫停/播放
  2805. case 'Space':
  2806. $hs.switchPlayStatus();
  2807. return TERMINATE;
  2808. break;
  2809. // 按鍵X:減速播放 -0.1
  2810. case 'KeyX':
  2811. if (player.playbackRate > 0) {
  2812. $hs.tips(false);
  2813. $hs.setPlaybackRate(player.playbackRate - 0.1);
  2814. return TERMINATE
  2815. }
  2816. break;
  2817. // 按鍵C:加速播放 +0.1
  2818. case 'KeyC':
  2819. if (player.playbackRate < 16) {
  2820. $hs.tips(false);
  2821. $hs.setPlaybackRate(player.playbackRate + 0.1);
  2822. return TERMINATE
  2823. }
  2824.  
  2825. break;
  2826. // 按鍵Z:正常速度播放
  2827. case 'KeyZ':
  2828. $hs.tips(false);
  2829. oldPBR = player.playbackRate;
  2830. if (oldPBR != 1.0) {
  2831. player._playbackRate_z = oldPBR;
  2832. newPBR = 1.0;
  2833. } else if (player._playbackRate_z != 1.0) {
  2834. newPBR = player._playbackRate_z || 1.0;
  2835. player._playbackRate_z = 1.0;
  2836. } else {
  2837. newPBR = 1.0
  2838. player._playbackRate_z = 1.0;
  2839. }
  2840. $hs.setPlaybackRate(newPBR, 1)
  2841. return TERMINATE
  2842. break;
  2843. // 按鍵F:下一幀
  2844. case 'KeyF':
  2845. if (window.location.hostname === 'www.netflix.com') return /* netflix 的F鍵是FULLSCREEN的意思 */
  2846. $hs.tips(false);
  2847. if (!player.paused) player.pause()
  2848. player.currentTime += +(1 / playerConf.fps)
  2849. $hs.tips('Jump to: Next frame')
  2850. return TERMINATE
  2851. break;
  2852. // 按鍵D:上一幀
  2853. case 'KeyD':
  2854. $hs.tips(false);
  2855. if (!player.paused) player.pause()
  2856. player.currentTime -= +(1 / playerConf.fps)
  2857. $hs.tips('Jump to: Previous frame')
  2858. return TERMINATE
  2859. break;
  2860. // 按鍵E:亮度增加%
  2861. case 'KeyE':
  2862. $hs.tips(false);
  2863. nv = playerConf.setFilter('brightness', (v) => v + 0.1);
  2864. $hs.tips('Brightness: ' + dround(nv * 100) + '%')
  2865. return TERMINATE
  2866. break;
  2867. // 按鍵W:亮度減少%
  2868. case 'KeyW':
  2869. $hs.tips(false);
  2870. nv = playerConf.setFilter('brightness', (v) => v > 0.1 ? v - 0.1 : 0);
  2871. $hs.tips('Brightness: ' + dround(nv * 100) + '%')
  2872. return TERMINATE
  2873. break;
  2874. // 按鍵T:對比度增加%
  2875. case 'KeyT':
  2876. $hs.tips(false);
  2877. nv = playerConf.setFilter('contrast', (v) => v + 0.1);
  2878. $hs.tips('Contrast: ' + dround(nv * 100) + '%')
  2879. return TERMINATE
  2880. break;
  2881. // 按鍵R:對比度減少%
  2882. case 'KeyR':
  2883. $hs.tips(false);
  2884. nv = playerConf.setFilter('contrast', (v) => v > 0.1 ? v - 0.1 : 0);
  2885. $hs.tips('Contrast: ' + dround(nv * 100) + '%')
  2886. return TERMINATE
  2887. break;
  2888. // 按鍵U:飽和度增加%
  2889. case 'KeyU':
  2890. $hs.tips(false);
  2891. nv = playerConf.setFilter('saturate', (v) => v + 0.1);
  2892. $hs.tips('Saturate: ' + dround(nv * 100) + '%')
  2893. return TERMINATE
  2894. break;
  2895. // 按鍵Y:飽和度減少%
  2896. case 'KeyY':
  2897. $hs.tips(false);
  2898. nv = playerConf.setFilter('saturate', (v) => v > 0.1 ? v - 0.1 : 0);
  2899. $hs.tips('Saturate: ' + dround(nv * 100) + '%')
  2900. return TERMINATE
  2901. break;
  2902. // 按鍵O:色相增加 1 度
  2903. case 'KeyO':
  2904. $hs.tips(false);
  2905. nv = playerConf.setFilter('hue-rotate', (v) => v + 1);
  2906. $hs.tips('Hue: ' + nv + ' deg')
  2907. return TERMINATE
  2908. break;
  2909. // 按鍵I:色相減少 1 度
  2910. case 'KeyI':
  2911. $hs.tips(false);
  2912. nv = playerConf.setFilter('hue-rotate', (v) => v - 1);
  2913. $hs.tips('Hue: ' + nv + ' deg')
  2914. return TERMINATE
  2915. break;
  2916. // 按鍵K:模糊增加 0.1 px
  2917. case 'KeyK':
  2918. $hs.tips(false);
  2919. nv = playerConf.setFilter('blur', (v) => v + 0.1);
  2920. $hs.tips('Blur: ' + nv + ' px')
  2921. return TERMINATE
  2922. break;
  2923. // 按鍵J:模糊減少 0.1 px
  2924. case 'KeyJ':
  2925. $hs.tips(false);
  2926. nv = playerConf.setFilter('blur', (v) => v > 0.1 ? v - 0.1 : 0);
  2927. $hs.tips('Blur: ' + nv + ' px')
  2928. return TERMINATE
  2929. break;
  2930. // 按鍵Q:圖像復位
  2931. case 'KeyQ':
  2932. $hs.tips(false);
  2933. playerConf.filterReset();
  2934. $hs.tips('Video Filter Reset')
  2935. return TERMINATE
  2936. break;
  2937. // 按鍵S:畫面旋轉 90 度
  2938. case 'KeyS':
  2939. $hs.tips(false);
  2940. playerConf.rotate += 90
  2941. if (playerConf.rotate % 360 === 0) playerConf.rotate = 0;
  2942. if (!playerConf.videoHeight || !playerConf.videoWidth) {
  2943. playerConf.videoWidth = playerConf.domElement.videoWidth;
  2944. playerConf.videoHeight = playerConf.domElement.videoHeight;
  2945. }
  2946. if (playerConf.videoWidth > 0 && playerConf.videoHeight > 0) {
  2947.  
  2948.  
  2949. if ((playerConf.rotate % 180) == 90) {
  2950. playerConf.mFactor = playerConf.videoHeight / playerConf.videoWidth;
  2951. } else {
  2952. playerConf.mFactor = 1.0;
  2953. }
  2954.  
  2955.  
  2956. playerConf.cssTransform();
  2957.  
  2958. $hs.tips('Rotation:' + playerConf.rotate + ' deg')
  2959.  
  2960. }
  2961.  
  2962. return TERMINATE
  2963. break;
  2964. // 按鍵迴車,進入FULLSCREEN
  2965. case 'Enter':
  2966. //t.callFullScreenBtn();
  2967. break;
  2968. case 'KeyN':
  2969. $hs.pictureInPicture(player);
  2970. return TERMINATE
  2971. break;
  2972. case 'KeyM':
  2973. //console.log('m!', player.volume,player._volume)
  2974.  
  2975. if (player.volume >= 0) {
  2976.  
  2977. if (!player.volume || player.muted) {
  2978.  
  2979. let newVol = player.volume || player._volume || 0.5;
  2980. if (player.volume !== newVol) {
  2981. player.volume = newVol;
  2982. }
  2983. player.muted = false;
  2984. $hs.tips(false);
  2985. $hs.tips('Mute: Off', undefined);
  2986.  
  2987. } else {
  2988.  
  2989. player._volume = player.volume;
  2990. player._volume_p = player.volume;
  2991. //player.volume = 0;
  2992. player.muted = true;
  2993. $hs.tips(false);
  2994. $hs.tips('Mute: On', undefined);
  2995.  
  2996. }
  2997.  
  2998. }
  2999.  
  3000. return TERMINATE
  3001. break;
  3002. default:
  3003. // 按1-4設置播放速度 49-52;97-100
  3004. numKey = +(event.key)
  3005.  
  3006. if (numKey >= 1 && numKey <= 4) {
  3007. $hs.tips(false);
  3008. $hs.setPlaybackRate(numKey, 1)
  3009. return TERMINATE
  3010. }
  3011. }
  3012.  
  3013. }
  3014. },
  3015.  
  3016. handlerPlayerLockedMouseMove: function(e) {
  3017. let player = $hs.player();
  3018. let rootNode = getRoot(player);
  3019.  
  3020. if (rootNode.pointerLockElement != player) {
  3021. player.removeEventListener('mousemove', $hs.handlerPlayerLockedMouseMove)
  3022. return;
  3023. }
  3024.  
  3025. let movementX = e.movementX || e.mozMovementX || e.webkitMovementX || 0,
  3026. movementY = e.movementY || e.mozMovementY || e.webkitMovementY || 0;
  3027.  
  3028. player.__xyOffset.x += movementX
  3029. player.__xyOffset.y += movementY
  3030. let ld = Math.sqrt(screen.width * screen.width + screen.height * screen.height) * .1
  3031. let md = Math.sqrt(player.__xyOffset.x * player.__xyOffset.x + player.__xyOffset.y * player.__xyOffset.y);
  3032. if (md > ld) $hs.playerActionLeave();
  3033.  
  3034. },
  3035.  
  3036. playerActionEnter: function() {
  3037. let player = $hs.player();
  3038.  
  3039. if (player) {
  3040. player.__requestPointerLock__();
  3041. player.__xyOffset = {
  3042. x: 0,
  3043. y: 0
  3044. };
  3045. player.addEventListener('mousemove', $hs.handlerPlayerLockedMouseMove)
  3046. }
  3047. },
  3048.  
  3049. focusHookVDoc: null,
  3050. focusHookVId: '',
  3051.  
  3052. playerActionLeave: function() {
  3053. let player = $hs.player();
  3054. if (player) player.removeEventListener('mousemove', $hs.handlerPlayerLockedMouseMove)
  3055. document.__exitPointerLock__();
  3056. },
  3057.  
  3058. handlerElementFocus: function(event) {
  3059.  
  3060. function notAtVideo() {
  3061. if ($hs.focusHookVDoc) $hs.focusHookVDoc = null
  3062. if ($hs.focusHookVId) $hs.focusHookVId = ''
  3063. }
  3064.  
  3065. const hookVideo = $hs.focusHookVDoc && $hs.focusHookVId ? $hs.focusHookVDoc.querySelector(`VIDEO[_h5ppid=${$hs.focusHookVId}]`) : null
  3066.  
  3067.  
  3068. if (hookVideo && (event.target == hookVideo || event.target.contains(hookVideo))) {
  3069.  
  3070.  
  3071. } else {
  3072.  
  3073. notAtVideo();
  3074.  
  3075.  
  3076. }
  3077.  
  3078. },
  3079.  
  3080. handlerFullscreenChanged: function(event) {
  3081.  
  3082.  
  3083. let videoElm = null,
  3084. videosQuery = null;
  3085. if (event && event.target) {
  3086.  
  3087. if (event.target.nodeName == "VIDEO") videoElm = event.target;
  3088. else if (videosQuery = event.target.querySelectorAll("VIDEO")) {
  3089. if (videosQuery.length === 1) videoElm = videosQuery[0]
  3090. }
  3091.  
  3092.  
  3093. }
  3094.  
  3095. if (videoElm) {
  3096.  
  3097.  
  3098.  
  3099. const player = videoElm;
  3100. const vpid = player.getAttribute('_h5ppid')
  3101.  
  3102.  
  3103. event.target.setAttribute('_h5p_fsElm_', vpid)
  3104.  
  3105.  
  3106. function hookTheActionedVideo() {
  3107. $hs.focusHookVDoc = getRoot(player)
  3108. $hs.focusHookVId = vpid
  3109. }
  3110.  
  3111. hookTheActionedVideo();
  3112. setTimeout(function() {
  3113. hookTheActionedVideo()
  3114. }, 500)
  3115.  
  3116.  
  3117.  
  3118. } else {
  3119.  
  3120. $hs.focusHookVDoc = null
  3121. $hs.focusHookVId = ''
  3122.  
  3123. }
  3124.  
  3125.  
  3126. },
  3127.  
  3128. /* 按鍵響應方法 */
  3129. handlerRootKeyDownEvent: function(event) {
  3130.  
  3131. function notAtVideo() {
  3132. if ($hs.focusHookVDoc) $hs.focusHookVDoc = null
  3133. if ($hs.focusHookVId) $hs.focusHookVId = ''
  3134. }
  3135.  
  3136.  
  3137.  
  3138.  
  3139. if ($hs.intVideoInitCount > 0) {} else {
  3140. // return notAtVideo();
  3141. }
  3142.  
  3143. // DOM Standard - either .key or .code
  3144. // Here we adopt .code (physical layout)
  3145.  
  3146. let pCode = event.code;
  3147. if (typeof pCode != 'string') return;
  3148. let player = $hs.player()
  3149. if (!player) return; // no video tag
  3150.  
  3151. let rootNode = getRoot(player);
  3152. let isRequiredListen = false;
  3153.  
  3154. let keyAsm = (event.shiftKey ? SHIFT : 0) | ((event.ctrlKey || event.metaKey) ? CTRL : 0) | (event.altKey ? ALT : 0);
  3155.  
  3156.  
  3157. if (document.fullscreenElement || rootNode.pointerLockElement) {
  3158. isRequiredListen = true;
  3159.  
  3160.  
  3161. if (!keyAsm && pCode == 'Escape') {
  3162. setTimeout(() => {
  3163. if (document.fullscreenElement) {
  3164. document.exitFullscreen();
  3165. } else if (document.pointerLockElement) {
  3166. $hs.playerActionLeave();
  3167. }
  3168. }, 700);
  3169. return;
  3170. }
  3171.  
  3172.  
  3173. }
  3174.  
  3175. const actionBoxRelation = $hs.getActionBoxRelationFromDOM(event.target)
  3176. let hookVideo = null;
  3177.  
  3178. if (actionBoxRelation) {
  3179. $hs.focusHookVDoc = getRoot(actionBoxRelation.player);
  3180. $hs.focusHookVId = actionBoxRelation.player.getAttribute('_h5ppid');
  3181. hookVideo = actionBoxRelation.player;
  3182. } else {
  3183. hookVideo = $hs.focusHookVDoc && $hs.focusHookVId ? $hs.focusHookVDoc.querySelector(`VIDEO[_h5ppid=${$hs.focusHookVId}]`) : null
  3184. }
  3185.  
  3186. if (hookVideo) isRequiredListen = true;
  3187.  
  3188. //console.log('root key', isRequiredListen, event.target, hookVideo)
  3189.  
  3190. if (!isRequiredListen) return;
  3191.  
  3192. //console.log('K01')
  3193.  
  3194. /* 切換插件的可用狀態 */
  3195. // Shift-`
  3196. if (keyAsm == SHIFT && pCode == 'Backquote') {
  3197. $hs.enable = !$hs.enable;
  3198. $hs.tips(false);
  3199. if ($hs.enable) {
  3200. $hs.tips('啟用h5Player插件')
  3201. } else {
  3202. $hs.tips('禁用h5Player插件')
  3203. }
  3204. // 阻止事件冒泡
  3205. event.stopPropagation()
  3206. event.preventDefault()
  3207. return false
  3208. }
  3209. if (!$hs.enable) {
  3210. consoleLog('h5Player 已禁用~')
  3211. return false
  3212. }
  3213.  
  3214. /* 非全局模式下,不聚焦則不執行快捷鍵的操作 */
  3215.  
  3216. if (!keyAsm && pCode == 'Enter') { //not NumberpadEnter
  3217. if (!rootNode.pointerLockElement && !document.fullscreenElement) {
  3218. if (rootNode.pointerLockElement != player) {
  3219. $hs.playerActionEnter();
  3220.  
  3221. // 阻止事件冒泡
  3222. event.stopPropagation()
  3223. event.preventDefault()
  3224. return false
  3225. }
  3226. } else if (rootNode.pointerLockElement && !document.fullscreenElement) {
  3227. $hs.playerActionLeave();
  3228.  
  3229. // 阻止事件冒泡
  3230. event.stopPropagation()
  3231. event.preventDefault()
  3232. return false
  3233. } else if (document.fullscreenElement) {
  3234. document.exitFullscreen();
  3235.  
  3236. // 阻止事件冒泡
  3237. event.stopPropagation()
  3238. event.preventDefault()
  3239. return false
  3240. }
  3241. }
  3242.  
  3243.  
  3244.  
  3245. let res = $hs.playerTrigger(player, event)
  3246. if (res == TERMINATE) {
  3247. event.stopPropagation()
  3248. event.preventDefault()
  3249. return false
  3250. }
  3251.  
  3252. },
  3253. /* 設置播放進度 */
  3254. setPlayProgress: function(player, curTime) {
  3255. if (!player) return
  3256. if (!curTime || Number.isNaN(curTime)) return
  3257. player.currentTime = curTime
  3258. if (curTime > 3) {
  3259. $hs.tips(false);
  3260. $hs.tips(`Playback Jumps to ${$hs.toolFormatCT(curTime)}`)
  3261. if (player.paused) player.play();
  3262. }
  3263. }
  3264. }
  3265.  
  3266. function makeFilter(arr, k) {
  3267. let res = ""
  3268. for (const e of arr) {
  3269. for (const d of e) {
  3270. res += " " + (1.0 * d * k).toFixed(9)
  3271. }
  3272. }
  3273. return res.trim()
  3274. }
  3275.  
  3276. function _add_filter(rootElm) {
  3277. let rootView = null;
  3278. if (rootElm && rootElm.nodeType > 0) {
  3279. while (rootElm.parentNode && rootElm.parentNode.nodeType === 1) rootElm = rootElm.parentNode;
  3280. rootView = rootElm.querySelector('body') || rootElm;
  3281. } else {
  3282. return;
  3283. }
  3284.  
  3285. if (rootView && rootView.querySelector && !rootView.querySelector('#_h5player_section_')) {
  3286.  
  3287. let svgFilterElm = document.createElement('section')
  3288. svgFilterElm.style.position = 'fixed';
  3289. svgFilterElm.style.left = '-999px';
  3290. svgFilterElm.style.width = '1px';
  3291. svgFilterElm.style.top = '-999px';
  3292. svgFilterElm.style.height = '1px';
  3293. svgFilterElm.id = '_h5player_section_'
  3294. let svgXML = `
  3295. <svg id='_h5p_image' version="1.1" xmlns="http://www.w3.org/2000/svg">
  3296. <defs>
  3297. <filter id="_h5p_sharpen1">
  3298. <feConvolveMatrix filterRes="100 100" style="color-interpolation-filters:sRGB" order="3" kernelMatrix="` + `
  3299. -0.3 -0.3 -0.3
  3300. -0.3 3.4 -0.3
  3301. -0.3 -0.3 -0.3`.replace(/[\n\r]+/g, ' ').trim() + `" preserveAlpha="true"/>
  3302. </filter>
  3303. <filter id="_h5p_unsharpen1">
  3304. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="5" kernelMatrix="` +
  3305. makeFilter([
  3306. [1, 4, 6, 4, 1],
  3307. [4, 16, 24, 16, 4],
  3308. [6, 24, -476, 24, 6],
  3309. [4, 16, 24, 16, 4],
  3310. [1, 4, 6, 4, 1]
  3311. ], -1 / 256) + `" preserveAlpha="false"/>
  3312. </filter>
  3313. <filter id="_h5p_unsharpen3_05">
  3314. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="3" kernelMatrix="` +
  3315. makeFilter(
  3316. [
  3317. [0.025, 0.05, 0.025],
  3318. [0.05, -1.1, 0.05],
  3319. [0.025, 0.05, 0.025]
  3320. ], -1 / .8) + `" preserveAlpha="false"/>
  3321. </filter>
  3322. <filter id="_h5p_unsharpen3_10">
  3323. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="3" kernelMatrix="` +
  3324. makeFilter(
  3325. [
  3326. [0.05, 0.1, 0.05],
  3327. [0.1, -1.4, 0.1],
  3328. [0.05, 0.1, 0.05]
  3329. ], -1 / .8) + `" preserveAlpha="false"/>
  3330. </filter>
  3331. <filter id="_h5p_unsharpen5_05">
  3332. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="5" kernelMatrix="` +
  3333. makeFilter(
  3334. [
  3335. [0.025, 0.1, 0.15, 0.1, 0.025],
  3336. [0.1, 0.4, 0.6, 0.4, 0.1],
  3337. [0.15, 0.6, -18.3, 0.6, 0.15],
  3338. [0.1, 0.4, 0.6, 0.4, 0.1],
  3339. [0.025, 0.1, 0.15, 0.1, 0.025]
  3340. ], -1 / 12.8) + `" preserveAlpha="false"/>
  3341. </filter>
  3342. <filter id="_h5p_unsharpen5_10">
  3343. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="5" kernelMatrix="` +
  3344. makeFilter(
  3345. [
  3346. [0.05, 0.2, 0.3, 0.2, 0.05],
  3347. [0.2, 0.8, 1.2, 0.8, 0.2],
  3348. [0.3, 1.2, -23.8, 1.2, 0.3],
  3349. [0.2, 0.8, 1.2, 0.8, 0.2],
  3350. [0.05, 0.2, 0.3, 0.2, 0.05]
  3351. ], -1 / 12.8) + `" preserveAlpha="false"/>
  3352. </filter>
  3353. <filter id="_h5p_unsharpen9_05">
  3354. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="9" kernelMatrix="` +
  3355. makeFilter(
  3356. [
  3357. [0.025, 0.2, 0.7, 1.4, 1.75, 1.4, 0.7, 0.2, 0.025],
  3358. [0.2, 1.6, 5.6, 11.2, 14, 11.2, 5.6, 1.6, 0.2],
  3359. [0.7, 5.6, 19.6, 39.2, 49, 39.2, 19.6, 5.6, 0.7],
  3360. [1.4, 11.2, 39.2, 78.4, 98, 78.4, 39.2, 11.2, 1.4],
  3361. [1.75, 14, 49, 98, -4792.7, 98, 49, 14, 1.75],
  3362. [1.4, 11.2, 39.2, 78.4, 98, 78.4, 39.2, 11.2, 1.4],
  3363. [0.7, 5.6, 19.6, 39.2, 49, 39.2, 19.6, 5.6, 0.7],
  3364. [0.2, 1.6, 5.6, 11.2, 14, 11.2, 5.6, 1.6, 0.2],
  3365. [0.025, 0.2, 0.7, 1.4, 1.75, 1.4, 0.7, 0.2, 0.025]
  3366. ], -1 / 3276.8) + `" preserveAlpha="false"/>
  3367. </filter>
  3368. <filter id="_h5p_unsharpen9_10">
  3369. <feConvolveMatrix style="color-interpolation-filters:sRGB;color-interpolation: sRGB;" order="9" kernelMatrix="` +
  3370. makeFilter(
  3371. [
  3372. [0.05, 0.4, 1.4, 2.8, 3.5, 2.8, 1.4, 0.4, 0.05],
  3373. [0.4, 3.2, 11.2, 22.4, 28, 22.4, 11.2, 3.2, 0.4],
  3374. [1.4, 11.2, 39.2, 78.4, 98, 78.4, 39.2, 11.2, 1.4],
  3375. [2.8, 22.4, 78.4, 156.8, 196, 156.8, 78.4, 22.4, 2.8],
  3376. [3.5, 28, 98, 196, -6308.6, 196, 98, 28, 3.5],
  3377. [2.8, 22.4, 78.4, 156.8, 196, 156.8, 78.4, 22.4, 2.8],
  3378. [1.4, 11.2, 39.2, 78.4, 98, 78.4, 39.2, 11.2, 1.4],
  3379. [0.4, 3.2, 11.2, 22.4, 28, 22.4, 11.2, 3.2, 0.4],
  3380. [0.05, 0.4, 1.4, 2.8, 3.5, 2.8, 1.4, 0.4, 0.05]
  3381. ], -1 / 3276.8) + `" preserveAlpha="false"/>
  3382. </filter>
  3383. <filter id="_h5p_grey1">
  3384. <feColorMatrix values="0.3333 0.3333 0.3333 0 0
  3385. 0.3333 0.3333 0.3333 0 0
  3386. 0.3333 0.3333 0.3333 0 0
  3387. 0 0 0 1 0"/>
  3388. <feColorMatrix type="saturate" values="0" />
  3389. </filter>
  3390. </defs>
  3391. </svg>
  3392. `;
  3393.  
  3394. svgFilterElm.innerHTML = svgXML.replace(/[\r\n\s]+/g, ' ').trim();
  3395.  
  3396. rootView.appendChild(svgFilterElm);
  3397. }
  3398.  
  3399. }
  3400.  
  3401. /**
  3402. * 某些網頁用了attachShadow closed mode,需要open才能獲取video標籤,例如百度雲盤
  3403. * 解決參考:
  3404. * https://developers.google.com/web/fundamentals/web-components/shadowdom?hl=zh-cn#closed
  3405. * https://stackoverflow.com/questions/54954383/override-element-prototype-attachshadow-using-chrome-extension
  3406. */
  3407.  
  3408. const initForShadowRoot = async (shadowRoot) => {
  3409. try {
  3410. if (shadowRoot && shadowRoot.nodeType > 0 && shadowRoot.mode == 'open' && 'querySelectorAll' in shadowRoot) {
  3411. if (!shadowRoot.host.hasAttribute('_h5p_shadowroot_')) {
  3412. shadowRoot.host.setAttribute('_h5p_shadowroot_', '')
  3413.  
  3414. $hs.bindDocEvents(shadowRoot);
  3415. captureVideoEvents(shadowRoot);
  3416.  
  3417. shadowRoots.push(shadowRoot)
  3418. }
  3419. }
  3420. } catch (e) {
  3421. console.log('h5Player: initForShadowRoot failed')
  3422. }
  3423. }
  3424.  
  3425. function hackAttachShadow() { // attachShadow - DOM Standard
  3426.  
  3427. let _prototype_ = window && window.HTMLElement ? window.HTMLElement.prototype : null;
  3428. if (_prototype_ && typeof _prototype_.attachShadow == 'function') {
  3429.  
  3430. let _attachShadow = _prototype_.attachShadow
  3431.  
  3432. hackAttachShadow = null
  3433. _prototype_.attachShadow = function() {
  3434. let arg = [...arguments];
  3435. if (arg[0] && arg[0].mode) arg[0].mode = 'open';
  3436. let shadowRoot = _attachShadow.apply(this, arg);
  3437. initForShadowRoot(shadowRoot);
  3438. return shadowRoot
  3439. };
  3440.  
  3441. _prototype_.attachShadow.toString = () => _attachShadow.toString();
  3442.  
  3443. }
  3444.  
  3445. }
  3446.  
  3447. function hackCreateShadowRoot() { // createShadowRoot - Deprecated
  3448.  
  3449. let _prototype_ = window && window.HTMLElement ? window.HTMLElement.prototype : null;
  3450. if (_prototype_ && typeof _prototype_.createShadowRoot == 'function') {
  3451.  
  3452. let _createShadowRoot = _prototype_.createShadowRoot;
  3453.  
  3454. hackCreateShadowRoot = null
  3455. _prototype_.createShadowRoot = function() {
  3456. const shadowRoot = _createShadowRoot.apply(this, arguments);
  3457. initForShadowRoot(shadowRoot);
  3458. return shadowRoot;
  3459. };
  3460. _prototype_.createShadowRoot.toString = () => _createShadowRoot.toString();
  3461.  
  3462. }
  3463. }
  3464.  
  3465. /* 事件偵聽hack */
  3466. function hackEventListener() {
  3467. if (!window.EventTarget) return;
  3468. const eventTargetPrototype = window.EventTarget.prototype;
  3469. let _addEventListener = eventTargetPrototype.addEventListener;
  3470. let _removeEventListener = eventTargetPrototype.removeEventListener;
  3471. if (typeof _addEventListener == 'function' && typeof _removeEventListener == 'function') {} else return;
  3472. hackEventListener = null;
  3473.  
  3474. class Listeners {
  3475.  
  3476. constructor(dom, type) {
  3477. this._dom = dom;
  3478. this._type = type;
  3479. this.listenersCount = 0;
  3480. this.hashList = {};
  3481. }
  3482. get baseFunc() {
  3483. if (this._dom && this._type) {
  3484. return this._dom['on' + this._type];
  3485. }
  3486. }
  3487. get funcCount() {
  3488. if (this._dom && this._type) {
  3489. return (typeof this.baseFunc == 'function') * 1 + (this.listenersCount || 0)
  3490. }
  3491. }
  3492.  
  3493.  
  3494. }
  3495.  
  3496.  
  3497.  
  3498. let hackedEvtCount = 0;
  3499.  
  3500.  
  3501. let watchList = ['click','mousedown','mouseup'];
  3502.  
  3503. eventTargetPrototype.addEventListener = function() {
  3504.  
  3505. let arg = arguments
  3506. let type = arg[0]
  3507. let listener = arg[1]
  3508.  
  3509. if (!this || !(this instanceof EventTarget) || typeof type != 'string' || typeof listener != 'function') {
  3510. return _addEventListener.apply(this, arguments)
  3511. //unknown bug?
  3512. }
  3513.  
  3514. $qmt(()=>{
  3515.  
  3516. if(typeof arg[2]=='object' && arg[2]){
  3517.  
  3518. }
  3519.  
  3520. if (watchList.indexOf(type) < 0) {
  3521.  
  3522.  
  3523. if(type=='mousewheel'||type=='touchstart'){
  3524.  
  3525. if(typeof arg[2] =='boolean' || arguments.length==2){
  3526.  
  3527. const options={
  3528. passive:true,
  3529. capture:arg[2]===true
  3530. }
  3531.  
  3532.  
  3533.  
  3534. return _addEventListener.call(this, type, listener, options);
  3535.  
  3536. }
  3537.  
  3538.  
  3539. }
  3540.  
  3541. if(this.nodeType===1 && this.nodeName!="BODY" && this.nodeName!="HTML"){
  3542.  
  3543.  
  3544. if (type=='mouseout' || type=='mouseover' || type=='focusin' || type=='focusout' || type=='mouseenter' || type=='mouseleave' || type=='mousemove'){
  3545.  
  3546.  
  3547. const nListener=listener.__nListener__ || function(){ return window.requestAnimationFrame(()=>listener.apply(this,arguments)) }
  3548. listener.__nListener__=nListener;
  3549. arguments[1]=nListener
  3550.  
  3551. }else{
  3552. //console.log(type)
  3553.  
  3554. }
  3555.  
  3556. }
  3557.  
  3558. return _addEventListener.apply(this, arguments);
  3559.  
  3560. }
  3561.  
  3562. let res;
  3563. res = _addEventListener.apply(this, arg)
  3564.  
  3565.  
  3566. let boolCapture = (arg[2] && typeof arg[2] == 'object') ? (arg[2].capture === true) : (arg[2] === true)
  3567.  
  3568. this._listeners = this._listeners || {}
  3569. this._listeners[type] = this._listeners[type] || new Listeners(this, type)
  3570. let uid = 100000 + (++hackedEvtCount);
  3571. let listenerObj = {
  3572. listener,
  3573. options: arg[2],
  3574. uid: uid,
  3575. useCapture: boolCapture
  3576. }
  3577. this._listeners[type].hashList[uid + ''] = listenerObj;
  3578. this._listeners[type].listenersCount++;
  3579.  
  3580. //return res
  3581.  
  3582. })
  3583.  
  3584. }
  3585. // hack removeEventListener
  3586. eventTargetPrototype.removeEventListener = function() {
  3587.  
  3588. let arg = arguments
  3589. let type = arg[0]
  3590. let listener = arg[1]
  3591.  
  3592.  
  3593. if (!this || !(this instanceof EventTarget) || typeof type != 'string' || typeof listener != 'function') {
  3594. return _removeEventListener.apply(this, arguments)
  3595. //unknown bug?
  3596. }
  3597.  
  3598. $qmt(()=>{
  3599.  
  3600.  
  3601. if (watchList.indexOf(type) < 0){
  3602. if(typeof listener.__nListener__=='function') arguments[1]=listener.__nListener__
  3603. return _removeEventListener.apply(this, arguments);
  3604. }
  3605.  
  3606. let boolCapture = (arg[2] && typeof arg[2] == 'object') ? (arg[2].capture === true) : (arg[2] === true)
  3607.  
  3608. let defaultRemoval = true;
  3609. if (this._listeners && this._listeners[type] && this._listeners[type].hashList) {
  3610. let hashList = this._listeners[type].hashList
  3611. for (let k in hashList) {
  3612. if (hashList[k].listener === listener && hashList[k].useCapture == boolCapture) {
  3613. delete hashList[k];
  3614. this._listeners[type].listenersCount--;
  3615. break;
  3616. }
  3617. }
  3618. }
  3619. if (defaultRemoval) return _removeEventListener.apply(this, arg);
  3620.  
  3621. })
  3622.  
  3623. }
  3624. eventTargetPrototype.addEventListener.toString = () => _addEventListener.toString();
  3625. eventTargetPrototype.removeEventListener.toString = () => _removeEventListener.toString();
  3626.  
  3627.  
  3628. }
  3629.  
  3630.  
  3631. function initShadowRoots(rootDoc) {
  3632. function onReady() {
  3633. var treeWalker = rootDoc.createTreeWalker(
  3634. rootDoc.documentElement,
  3635. NodeFilter.SHOW_ELEMENT, {
  3636. acceptNode: (node) => (node.shadowRoot ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP)
  3637. }
  3638. );
  3639. var nodeList = [];
  3640. while (treeWalker.nextNode()) nodeList.push(treeWalker.currentNode);
  3641. for (const node of nodeList) {
  3642. initForShadowRoot(node.shadowRoot)
  3643. }
  3644. }
  3645. if (rootDoc.readyState !== 'loading') {
  3646. onReady();
  3647. } else {
  3648. rootDoc.addEventListener('DOMContentLoaded', onReady);
  3649. }
  3650. }
  3651.  
  3652. function captureVideoEvents(rootDoc) {
  3653.  
  3654. var g = function(evt) {
  3655.  
  3656.  
  3657. var domElement = evt.target || this || null
  3658. if (domElement && domElement.nodeType == 1 && domElement.nodeName == "VIDEO") {
  3659. var video = domElement
  3660. if (!domElement.getAttribute('_h5ppid')) handlerVideoFound(video);
  3661. if (domElement.getAttribute('_h5ppid')) {
  3662. switch (evt.type) {
  3663. case 'loadedmetadata':
  3664. return $hs.handlerVideoLoadedMetaData.call(video, evt);
  3665. // case 'playing':
  3666. // return $hs.handlerVideoPlaying.call(video, evt);
  3667. // case 'pause':
  3668. // return $hs.handlerVideoPause.call(video, evt);
  3669. // case 'volumechange':
  3670. // return $hs.handlerVideoVolumeChange.call(video, evt);
  3671. }
  3672. }
  3673. }
  3674.  
  3675.  
  3676. }
  3677.  
  3678. // using capture phase
  3679. rootDoc.addEventListener('loadedmetadata', g, true);
  3680.  
  3681. }
  3682.  
  3683. function handlerVideoFound(video) {
  3684.  
  3685. if (!video) return;
  3686. if (video.getAttribute('_h5ppid')) return;
  3687. let alabel = video.getAttribute('aria-label')
  3688. if (alabel && typeof alabel == "string" && alabel.toUpperCase() == "GIF") return;
  3689.  
  3690.  
  3691. consoleLog('handlerVideoFound', video)
  3692.  
  3693. $hs.intVideoInitCount = ($hs.intVideoInitCount || 0) + 1;
  3694. let vpid = 'h5p-' + $hs.intVideoInitCount
  3695. consoleLog(' - HTML5 Video is detected -', `Number of Videos: ${$hs.intVideoInitCount}`)
  3696. if ($hs.intVideoInitCount === 1) $hs.fireGlobalInit();
  3697. video.setAttribute('_h5ppid', vpid)
  3698.  
  3699.  
  3700. playerConfs[vpid] = new PlayerConf();
  3701. playerConfs[vpid].domElement = video;
  3702. playerConfs[vpid].domActive = DOM_ACTIVE_FOUND;
  3703.  
  3704. let rootNode = getRoot(video);
  3705.  
  3706. if (rootNode.host) $hs.getPlayerBlockElement(video); // shadowing
  3707. let rootElm = domAppender(rootNode) || document.documentElement //48763
  3708. _add_filter(rootElm) // either main document or shadow node
  3709.  
  3710.  
  3711.  
  3712. video.addEventListener('playing', $hs.handlerVideoPlaying, true);
  3713. video.addEventListener('pause', $hs.handlerVideoPause, true);
  3714. video.addEventListener('volumechange', $hs.handlerVideoVolumeChange, true);
  3715.  
  3716.  
  3717.  
  3718. }
  3719.  
  3720.  
  3721.  
  3722. hackAttachShadow()
  3723. hackCreateShadowRoot()
  3724. hackEventListener()
  3725.  
  3726.  
  3727. window.addEventListener('message', $hs.handlerWinMessage, false);
  3728. $hs.bindDocEvents(document);
  3729. captureVideoEvents(document);
  3730. initShadowRoots(document);
  3731.  
  3732.  
  3733. let windowsLD = (function() {
  3734. let ls_res = [];
  3735. try {
  3736. ls_res = [!!window.localStorage, !!window.top.localStorage];
  3737. } catch (e) {}
  3738. try {
  3739. let winp = window;
  3740. let winc = 0;
  3741. while (winp !== window.top && winp && ++winc) winp = winp.parentNode;
  3742. ls_res.push(winc);
  3743. } catch (e) {}
  3744. return ls_res;
  3745. })();
  3746.  
  3747. consoleLogF('- h5Player Plugin Loaded -', ...windowsLD)
  3748.  
  3749. function isInCrossOriginFrame() {
  3750. let result = true;
  3751. try {
  3752. if (window.top.localStorage || window.top.location.href) result = false;
  3753. } catch (e) {}
  3754. return result
  3755. }
  3756.  
  3757. if (isInCrossOriginFrame()) consoleLog('cross origin frame detected');
  3758.  
  3759. /*
  3760. function dd(f, $this, $arguments) {
  3761. queueMicrotask(() => f.apply($this, $arguments))
  3762. }
  3763. */
  3764.  
  3765. //const functionReplacerMap = new Map();
  3766. /*
  3767. function functionReplacer(f) {
  3768.  
  3769. if (f.constructor.name != 'Function') return f;
  3770. const reducedArguments = [...arguments];
  3771. reducedArguments[0] = '';
  3772. const r = reducedArguments.join('***')
  3773. const fs = f.toString() + "%%%" + r
  3774. if (fs.indexOf(' { [native code] }') > 0) return f;
  3775.  
  3776. let res = functionReplacerMap.get(fs);
  3777. if (res) return res;
  3778. functionReplacerMap.set(fs, res = f)
  3779.  
  3780. return res;
  3781.  
  3782.  
  3783. }
  3784. */
  3785.  
  3786. const $rAf = $$uWin.requestAnimationFrame;
  3787. const $cAf = $$uWin.cancelAnimationFrame;
  3788.  
  3789. const $bv = {
  3790.  
  3791. uWin: (window.unsafeWindow || window),
  3792. /*
  3793. rAfss: function() {
  3794. const gs = $bv.gs;
  3795. if (gs.length > 0) {
  3796. if (document.fff) document.fff.push(gs.length)
  3797. for (const f of gs) dd(f, this, arguments);
  3798. }
  3799. gs.length = 0;
  3800. },
  3801. */
  3802. // qfs: {},
  3803.  
  3804.  
  3805. // qfsCount: 0,
  3806.  
  3807. boostVideoPerformanceActivate: function() {
  3808.  
  3809. if ($bz.boosted) return;
  3810.  
  3811.  
  3812. //$bv.kSTC = $rAf.call($$uWin, () => 0) * 2;
  3813.  
  3814. //document.fff = [];
  3815. // document.gg1 = 0;
  3816. // document.gg2 = 0;
  3817. // document.nnc = [];
  3818. // functionReplacerMap.clear();
  3819. /*
  3820. $bv.mbf = function() {
  3821.  
  3822. const qfs = $bv.qfs
  3823.  
  3824.  
  3825. for (let k in qfs) {
  3826. const f = qfs[k]
  3827. f.__bv_f__.apply(this, arguments);
  3828. delete qfs[k]
  3829. }
  3830.  
  3831. }
  3832. */
  3833. if ($mb.nightly_isSupportQueueMicrotask()) {
  3834. // $bv.rAf = window.requestAnimationFrame;
  3835. // $bv.cAf = window.cancelAnimationFrame;
  3836. // $bv.setTimeout = window.setTimeout;
  3837. // $bv.clearTimeout = window.clearTimeout;
  3838.  
  3839.  
  3840.  
  3841.  
  3842. }
  3843.  
  3844.  
  3845. $bz.boosted = true;
  3846.  
  3847. },
  3848.  
  3849.  
  3850. boostVideoPerformanceDeactivate: function() {
  3851.  
  3852. const window = $bv.uWin
  3853. if (!$bz.boosted) return;
  3854. $bz.boosted = false;
  3855.  
  3856. if ($mb.nightly_isSupportQueueMicrotask()) {
  3857. // window.requestAnimationFrame = $bv.rAf;
  3858. // window.cancelAnimationFrame = $bv.cAf;
  3859. //window.setTimeout = $bv.setTimeout;
  3860. // window.clearTimeout = $bv.clearTimeout;
  3861. // $bv.rAf = null;
  3862. // $bv.cAf = null;
  3863. // $bv.setTimeout = null;
  3864. // $bv.clearTimeout = null;
  3865. }
  3866.  
  3867.  
  3868. // functionReplacerMap.clear();
  3869.  
  3870.  
  3871. }
  3872.  
  3873. }
  3874.  
  3875. function $onReady() {
  3876.  
  3877. const window = $$uWin
  3878.  
  3879. // const $rAf = window.requestAnimationFrame;
  3880. // const $cAf = window.cancelAnimationFrame;
  3881.  
  3882. /*
  3883. window.requestAnimationFrame = function(f) {
  3884.  
  3885. let boosted = $bz.boosted;
  3886. boosted = false
  3887. if (!boosted) return $rAf.apply(this, arguments) << 1
  3888.  
  3889. const h=functionReplacer(f)
  3890. const nt=+new Date;
  3891. const lastCall = h.__lastCall
  3892.  
  3893. h.__lastCall=nt;
  3894.  
  3895. if(f!==h){
  3896. */
  3897.  
  3898. /*
  3899. if(lastCall>0 && lastCall <= nt && lastCall+60>nt){
  3900.  
  3901. f=h;
  3902.  
  3903. }else{
  3904. console.log('nn', lastCall-nt)
  3905. }*/
  3906. /*
  3907. f=h;
  3908.  
  3909. }
  3910.  
  3911. if (!f.__bv_stack__) f.__bv_stack__ = 0;
  3912.  
  3913. f.__bv_stack__++;
  3914.  
  3915. if (f.__bv_stack__ > 1) return f.__bv_cid__;
  3916.  
  3917. if (!f.__bv_f__) {
  3918. f.__bv_f__ = function() {
  3919. const cid = f.__bv_cid__
  3920. if (cid > 0 && $bv.qfs[cid] === f) {
  3921. queueMicrotask(() => f.apply(this, arguments))
  3922. delete $bv.qfs[cid];
  3923. delete f.__bv_cid__;
  3924. f.__bv_stack__ = 0;
  3925. return
  3926. }
  3927. //$bv._exx=0
  3928.  
  3929. };
  3930. document.nnc.push(f + "")
  3931. }
  3932. f.__bv_cid__ = ($rAf.call(window, f.__bv_f__) << 1) | 1
  3933. //if(!$bv._exx){
  3934. //$bv._exx=(($rAf.call(window, f.__bv_f__)%20000000)<<16)|1
  3935. //f.__bv_cid__ = $bv._exx;
  3936. //}else{
  3937. // $bv._exx+=2;
  3938. // f.__bv_cid__ = $bv._exx ;
  3939. // }
  3940.  
  3941. $bv.qfs[f.__bv_cid__] = f
  3942.  
  3943. return f.__bv_cid__
  3944.  
  3945. };
  3946.  
  3947. window.cancelAnimationFrame = function(cid) {
  3948.  
  3949.  
  3950. if ((cid & 1) == 0) {
  3951.  
  3952. return $cAf.call(this, cid >> 1)
  3953.  
  3954. }
  3955.  
  3956.  
  3957. let boosted = $bz.boosted;
  3958. boosted = false
  3959.  
  3960. const f = $bv.qfs[cid]
  3961. if (typeof f == 'function') {
  3962.  
  3963. f.__bv_stack__--;
  3964. if (f.__bv_stack__ !== 0) return;
  3965. delete $bv.qfs[f.__bv_cid__];
  3966. delete f.__bv_cid__;
  3967.  
  3968. return;
  3969.  
  3970. }
  3971.  
  3972. $cAf.call(window, cid);
  3973.  
  3974.  
  3975. }
  3976. */
  3977.  
  3978.  
  3979. }
  3980.  
  3981. // if (document.readyState !== 'loading') {
  3982. $onReady();
  3983. //} else {
  3984. // document.addEventListener('DOMContentLoaded', $onReady);
  3985. // }
  3986.  
  3987.  
  3988.  
  3989.  
  3990. })(window.unsafeWindow || window);