HTML5 Video Player Enhance

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

目前為 2021-07-19 提交的版本,檢視 最新版本

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

QingJ © 2025

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