HTML5 Video Player Enhance

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

目前為 2021-06-26 提交的版本,檢視 最新版本

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

QingJ © 2025

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