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

QingJ © 2025

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