YouTube: Audio Only

No Video Streaming

当前为 2024-12-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube: Audio Only
  3. // @description No Video Streaming
  4. // @namespace UserScript
  5. // @version 2.1.2
  6. // @author CY Fung
  7. // @match https://www.youtube.com/*
  8. // @match https://www.youtube.com/embed/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @match https://m.youtube.com/*
  11. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  12. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/YouTube-Audio-Only.png
  13. // @grant GM_registerMenuCommand
  14. // @grant GM.setValue
  15. // @grant GM.getValue
  16. // @grant GM.listValues
  17. // @grant GM.deleteValue
  18. // @run-at document-start
  19. // @license MIT
  20. // @compatible chrome
  21. // @compatible firefox
  22. // @compatible opera
  23. // @compatible edge
  24. // @compatible safari
  25. // @allFrames true
  26. //
  27. // ==/UserScript==
  28.  
  29. (async function () {
  30. 'use strict';
  31.  
  32.  
  33. !window.TTP && (() => {
  34. // credit to Benjamin Philipp
  35. // original source: https://greasyfork.org/en/scripts/433051-trusted-types-helper
  36.  
  37. // --------------------------------------------------- Trusted Types Helper ---------------------------------------------------
  38.  
  39. const overwrite_default = false; // If a default policy already exists, it might be best not to overwrite it, but to try and set a custom policy and use it to manually generate trusted types. Try at your own risk
  40. const prefix = `TTP`;
  41. var passThroughFunc = function (string, sink) {
  42. return string; // Anything passing through this function will be returned without change
  43. }
  44. var TTPName = "passthrough";
  45. var TTP_default, TTP = { createHTML: passThroughFunc, createScript: passThroughFunc, createScriptURL: passThroughFunc }; // We can use TTP.createHTML for all our assignments even if we don't need or even have Trusted Types; this should make fallbacks and polyfills easy
  46. var needsTrustedHTML = false;
  47. function doit() {
  48. try {
  49. if (typeof window.isSecureContext !== 'undefined' && window.isSecureContext) {
  50. if (window.trustedTypes && window.trustedTypes.createPolicy) {
  51. needsTrustedHTML = true;
  52. if (trustedTypes.defaultPolicy) {
  53. log("TT Default Policy exists");
  54. if (overwrite_default)
  55. TTP = window.trustedTypes.createPolicy("default", TTP);
  56. else
  57. TTP = window.trustedTypes.createPolicy(TTPName, TTP); // Is the default policy permissive enough? If it already exists, best not to overwrite it
  58. TTP_default = trustedTypes.defaultPolicy;
  59.  
  60. log("Created custom passthrough policy, in case the default policy is too restrictive: Use Policy '" + TTPName + "' in var 'TTP':", TTP);
  61. }
  62. else {
  63. TTP_default = TTP = window.trustedTypes.createPolicy("default", TTP);
  64. }
  65. log("Trusted-Type Policies: TTP:", TTP, "TTP_default:", TTP_default);
  66. }
  67. }
  68. } catch (e) {
  69. log(e);
  70. }
  71. }
  72.  
  73. function log(...args) {
  74. if ("undefined" != typeof (prefix) && !!prefix)
  75. args = [prefix + ":", ...args];
  76. if ("undefined" != typeof (debugging) && !!debugging)
  77. args = [...args, new Error().stack.replace(/^\s*(Error|Stack trace):?\n/gi, "").replace(/^([^\n]*\n)/, "\n")];
  78. console.log(...args);
  79. }
  80.  
  81. doit();
  82.  
  83. // --------------------------------------------------- Trusted Types Helper ---------------------------------------------------
  84.  
  85. window.TTP = TTP;
  86.  
  87. })();
  88.  
  89. function createHTML(s) {
  90. if (typeof TTP !== 'undefined' && typeof TTP.createHTML === 'function') return TTP.createHTML(s);
  91. return s;
  92. }
  93.  
  94. let trustHTMLErr = null;
  95. try {
  96. document.createElement('div').innerHTML = createHTML('1');
  97. } catch (e) {
  98. trustHTMLErr = e;
  99. }
  100.  
  101. if (trustHTMLErr) {
  102. console.log(`trustHTMLErr`, trustHTMLErr);
  103. trustHTMLErr(); // exit userscript
  104. }
  105.  
  106. /** @type {globalThis.PromiseConstructor} */
  107. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  108.  
  109. if (typeof AbortSignal === 'undefined') throw new DOMException("Please update your browser.", "NotSupportedError");
  110.  
  111. async function confirm(message) {
  112. // Create the HTML for the dialog
  113.  
  114. if (!document.body) return;
  115.  
  116. let dialog = document.getElementById('confirmDialog794');
  117. if (!dialog) {
  118.  
  119. const dialogHTML = `
  120. <div id="confirmDialog794" class="dialog-style" style="display: block;">
  121. <div class="confirm-box">
  122. <p>${message}</p>
  123. <div class="confirm-buttons">
  124. <button id="confirmBtn">Confirm</button>
  125. <button id="cancelBtn">Cancel</button>
  126. </div>
  127. </div>
  128. </div>
  129. `;
  130.  
  131. // Append the dialog to the document body
  132. document.body.insertAdjacentHTML('beforeend', createHTML(dialogHTML));
  133. dialog = document.getElementById('confirmDialog794');
  134.  
  135. }
  136.  
  137. // Return a promise that resolves or rejects based on the user's choice
  138. return new Promise((resolve) => {
  139. document.getElementById('confirmBtn').onclick = () => {
  140. resolve(true);
  141. cleanup();
  142. };
  143.  
  144. document.getElementById('cancelBtn').onclick = () => {
  145. resolve(false);
  146. cleanup();
  147. };
  148.  
  149. function cleanup() {
  150. dialog && dialog.remove();
  151. dialog = null;
  152. }
  153. });
  154. }
  155.  
  156.  
  157.  
  158. if (location.pathname === '/live_chat' || location.pathname === 'live_chat_replay') return;
  159.  
  160. const kEventListener = (evt) => {
  161. if (document.documentElement.hasAttribute('forceRefresh032')) {
  162. evt.stopImmediatePropagation();
  163. evt.stopPropagation();
  164. }
  165. }
  166. window.addEventListener('beforeunload', kEventListener, false);
  167.  
  168. const pageInjectionCode = function () {
  169.  
  170. let debugFlg001 = false;
  171. // let debugFlg002 = false;
  172. // let globalPlayer = null;
  173. const SHOW_VIDEO_STATIC_IMAGE = true;
  174. const PATCH_MEDIA_PUBLISH = true;
  175.  
  176. if (typeof AbortSignal === 'undefined') throw new DOMException("Please update your browser.", "NotSupportedError");
  177.  
  178. const URL = window.URL || new Function('return URL')();
  179. const createObjectURL = URL.createObjectURL.bind(URL);
  180.  
  181. /** @type {globalThis.PromiseConstructor} */
  182. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  183.  
  184. const PromiseExternal = ((resolve_, reject_) => {
  185. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  186. return class PromiseExternal extends Promise {
  187. constructor(cb = h) {
  188. super(cb);
  189. if (cb === h) {
  190. /** @type {(value: any) => void} */
  191. this.resolve = resolve_;
  192. /** @type {(reason?: any) => void} */
  193. this.reject = reject_;
  194. }
  195. }
  196. };
  197. })();
  198.  
  199. const [setTimeout_, clearTimeout_] = [setTimeout, clearTimeout];
  200.  
  201. /* globals WeakRef:false */
  202.  
  203. /** @type {(o: Object | null) => WeakRef | null} */
  204. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  205.  
  206. /** @type {(wr: Object | null) => Object | null} */
  207. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  208.  
  209. const isIterable = (x) => Symbol.iterator in Object(x);
  210.  
  211.  
  212. let byPassSync = false;
  213. let byPassNonFatalError = false;
  214. let skipPlayPause = 0;
  215. let byPassPublishPatch = false;
  216.  
  217. const dmo = {};
  218.  
  219.  
  220. const observablePromise = (proc, timeoutPromise) => {
  221. let promise = null;
  222. return {
  223. obtain() {
  224. if (!promise) {
  225. promise = new Promise(resolve => {
  226. let mo = null;
  227. const f = () => {
  228. let t = proc();
  229. if (t) {
  230. mo.disconnect();
  231. mo.takeRecords();
  232. mo = null;
  233. resolve(t);
  234. }
  235. }
  236. mo = new MutationObserver(f);
  237. mo.observe(document, { subtree: true, childList: true })
  238. f();
  239. timeoutPromise && timeoutPromise.then(() => {
  240. resolve(null)
  241. });
  242. });
  243. }
  244. return promise
  245. }
  246. }
  247. }
  248.  
  249.  
  250. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  251.  
  252. const prototypeInherit = (d, b) => {
  253. const m = Object.getOwnPropertyDescriptors(b);
  254. for (const p in m) {
  255. if (!Object.getOwnPropertyDescriptor(d, p)) {
  256. Object.defineProperty(d, p, m[p]);
  257. }
  258. }
  259. };
  260.  
  261. const delayPn = delay => new Promise((fn => setTimeout_(fn, delay)));
  262.  
  263. const mockEvent = (o, elem) => {
  264. o = o || {};
  265. elem = elem || null;
  266. return {
  267. preventDefault: () => { },
  268. stopPropagation: () => { },
  269. stopImmediatePropagation: () => { },
  270. returnValue: true,
  271. target: elem,
  272. srcElement: elem,
  273. defaultPrevented: false,
  274. cancelable: true,
  275. timeStamp: performance.now(),
  276. ...o
  277. }
  278. };
  279.  
  280.  
  281. const generalRegister = (prop, symbol, checker, pg) => {
  282. const objSet = new Set();
  283. let done = false;
  284. const f = (o) => {
  285. const ct = o.constructor;
  286. const proto = ct.prototype;
  287. if (!done && proto && ct !== Function && ct !== Object && checker(proto)) {
  288. done = true;
  289. delete Object.prototype[prop];
  290. objSet.delete(proto);
  291. objSet.delete(o);
  292. for (const obj of objSet) {
  293. obj[prop] = obj[symbol];
  294. delete obj[symbol];
  295. }
  296. objSet.clear();
  297. Object.defineProperty(proto, prop, pg);
  298. return proto;
  299. }
  300. return false;
  301. };
  302. Object.defineProperty(Object.prototype, prop, {
  303. get() {
  304. const p = f(this);
  305. if (p) {
  306. return p[prop];
  307. } else {
  308. return this[symbol];
  309. }
  310. },
  311. set(nv) {
  312. const p = f(this);
  313. if (p) {
  314. p[prop] = nv;
  315. } else {
  316. objSet.add(this);
  317. this[symbol] = nv;
  318. }
  319. return true;
  320. },
  321. enumerable: false,
  322. configurable: true
  323. });
  324.  
  325. };
  326.  
  327.  
  328. const attachOneTimeEvent = function (eventType, callback) {
  329. let kz = false;
  330. document.addEventListener(eventType, function (evt) {
  331. if (kz) return;
  332. kz = true;
  333. callback(evt);
  334. }, { capture: true, passive: true, once: true });
  335. }
  336.  
  337. const evaluateInternalAppScore = (internalApp) => {
  338.  
  339.  
  340. let r = 0;
  341. if (!internalApp || typeof internalApp !== 'object') {
  342. return -999;
  343. }
  344.  
  345. if (internalApp.app) r -= 100;
  346.  
  347. if (!('mediaElement' in internalApp)) r -= 500;
  348.  
  349. if (!('videoData' in internalApp)) r -= 50;
  350.  
  351. if (!('playerState' in internalApp)) r -= 50;
  352.  
  353. if ('getVisibilityState' in internalApp) r += 20;
  354. if ('visibility' in internalApp) r += 40;
  355. if ('isBackground' in internalApp) r += 40;
  356. if ('publish' in internalApp) r += 10;
  357.  
  358.  
  359. if (('playerType' in internalApp)) r += 10;
  360. if (('playbackRate' in internalApp)) r += 10;
  361. if (('playerState' in internalApp)) r += 10;
  362. if (typeof (internalApp.playerState || 0) === 'object') r += 50;
  363.  
  364.  
  365. return r;
  366.  
  367.  
  368.  
  369. }
  370.  
  371.  
  372. const { remapString } = (() => {
  373.  
  374. function shuffleArray(array) {
  375. for (let i = array.length - 1; i > 0; i--) {
  376. const j = Math.floor(Math.random() * (i + 1));
  377. [array[i], array[j]] = [array[j], array[i]];
  378. }
  379. return array;
  380. }
  381.  
  382. /**
  383. * Create a deterministic "random" mapping from 'a'..'z' -> shuffled letters.
  384. * Returns a Map for O(1) lookups.
  385. */
  386. function createRandomAlphabetMap() {
  387. const baseAlphabet = "abcdefghijklmnopqrstuvwxyz";
  388. const letters = baseAlphabet.split("");
  389.  
  390.  
  391. // Shuffle letters with that seeded generator
  392. const shuffledLetters = shuffleArray(letters);
  393.  
  394. // Build the Map
  395. const map = new Map();
  396. for (let i = 0, l = baseAlphabet.length; i < l; i++) {
  397. map.set(baseAlphabet[i], shuffledLetters[i]);
  398. map.set(baseAlphabet[i].toUpperCase(), shuffledLetters[i].toUpperCase());
  399. }
  400. return map;
  401. }
  402.  
  403. // Create the random map once at initialization
  404. let randomAlphabetMap = null;
  405.  
  406. /**
  407. * Remaps alphabetic letters in a string according to randomAlphabetMap.
  408. * Preserves the case of letters and leaves non-alphabet characters unchanged.
  409. */
  410. function remapString(input) {
  411. if (!randomAlphabetMap) return input;
  412. let result = new Array(input.length);
  413. let i = 0;
  414. for (const char of input) {
  415. result[i++] = randomAlphabetMap.get(char) || char;
  416. }
  417. return result.join('');
  418. }
  419.  
  420. const listA = [
  421. "error",
  422. "internalvideodatachange",
  423. "statechange",
  424. "SEEK_TO",
  425. "videoelementevent",
  426. "onLoadedMetadata",
  427. "progresssync",
  428. "onVideoProgress",
  429. "SEEK_COMPLETE",
  430. "playbackstarted",
  431. "onLoadProgress",
  432. "nonfatalerror",
  433. "internalAbandon",
  434. "internalvideoformatchange",
  435. "internalaudioformatchange",
  436. "playbackready",
  437. "mediasourceattached",
  438. "beginseeking",
  439. "endseeking"
  440. ];
  441.  
  442. const mdA = listA.join('|');
  443.  
  444. loop1:
  445. for (let tryCount = 8; tryCount > 0; tryCount--) {
  446. randomAlphabetMap = createRandomAlphabetMap();
  447. const listB = listA.map(remapString);
  448. const mdB = listB.join('|');
  449. for (const a of listA) {
  450. if (mdB.includes(a)) {
  451. randomAlphabetMap = null;
  452. continue loop1;
  453. }
  454. }
  455. for (const b of listB) {
  456. if (mdA.includes(b)) {
  457. randomAlphabetMap = null;
  458. continue loop1;
  459. }
  460. }
  461. break;
  462. }
  463. if (!randomAlphabetMap) {
  464. console.error('randomAlphabetMap is not available.')
  465. }
  466.  
  467. return { remapString };
  468. })();
  469.  
  470.  
  471. function removeTempObjectProp01() {
  472. delete Object.prototype['kevlar_non_watch_unified_player'];
  473. delete Object.prototype['kevlar_unified_player'];
  474. }
  475.  
  476. function ytConfigFix(config__) {
  477. const config_ = config__;
  478.  
  479. if (config_) {
  480.  
  481. const playerKevlar = ((config_ || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0;
  482.  
  483. if (playerKevlar) {
  484.  
  485. // console.log(322, playerKevlar)
  486. playerKevlar.allowWoffleManagement = false;
  487. playerKevlar.cinematicSettingsAvailable = false;
  488. playerKevlar.showMiniplayerButton = false;
  489. playerKevlar.showMiniplayerUiWhenMinimized = false;
  490. playerKevlar.transparentBackground = false;
  491.  
  492. playerKevlar.enableCsiLogging = false;
  493. playerKevlar.externalFullscreen = false;
  494.  
  495. if (typeof playerKevlar.serializedExperimentFlags === 'string') {
  496. playerKevlar.serializedExperimentFlags = '';
  497. // playerKevlar.serializedExperimentFlags = playerKevlar.serializedExperimentFlags.replace(/[-\w]+=(\[\]|[.-\d]+|[_a-z]+|)(&|$)/g,'').replace(/&$/,'')
  498. }
  499.  
  500. if (typeof playerKevlar.serializedExperimentIds === 'string') {
  501. playerKevlar.serializedExperimentIds = '';
  502. // playerKevlar.serializedExperimentIds = playerKevlar.serializedExperimentIds.replace(/\d+\s*(,\s*|$)/g,'')
  503. }
  504.  
  505. }
  506.  
  507. removeTempObjectProp01();
  508.  
  509. let configs = config_.WEB_PLAYER_CONTEXT_CONFIGS || {};
  510. for (const [key, entry] of Object.entries(configs)) {
  511.  
  512. if (entry && typeof entry.serializedExperimentFlags === 'string' && entry.serializedExperimentFlags.length > 16) {
  513. // prevent idle playback failure
  514. entry.serializedExperimentFlags = entry.serializedExperimentFlags.replace(/\b(html5_check_for_idle_network_interval_ms|html5_trigger_loader_when_idle_network|html5_sabr_fetch_on_idle_network_preloaded_players|html5_autonav_cap_idle_secs|html5_autonav_quality_cap|html5_disable_client_autonav_cap_for_onesie|html5_idle_rate_limit_ms|html5_sabr_fetch_on_idle_network_preloaded_players|html5_webpo_idle_priority_job|html5_server_playback_start_policy|html5_check_video_data_errors_before_playback_start|html5_check_unstarted|html5_check_queue_on_data_loaded)=([-_\w]+)(\&|$)/g, (_, a, b, c) => {
  515. return a + '00' + '=' + b + c;
  516. });
  517.  
  518. }
  519.  
  520. }
  521.  
  522. const EXPERIMENT_FLAGS = config_.EXPERIMENT_FLAGS;
  523.  
  524. if (EXPERIMENT_FLAGS) {
  525. EXPERIMENT_FLAGS.kevlar_unified_player = true;
  526. EXPERIMENT_FLAGS.kevlar_non_watch_unified_player = true;
  527. }
  528.  
  529.  
  530. const EXPERIMENTS_FORCED_FLAGS = config_.EXPERIMENTS_FORCED_FLAGS;
  531.  
  532. if (EXPERIMENTS_FORCED_FLAGS) {
  533. EXPERIMENTS_FORCED_FLAGS.kevlar_unified_player = true;
  534. EXPERIMENTS_FORCED_FLAGS.kevlar_non_watch_unified_player = true;
  535. }
  536.  
  537. }
  538. }
  539.  
  540. Object.defineProperty(Object.prototype, 'kevlar_non_watch_unified_player', {
  541. get() {
  542. // console.log(501, this.constructor.prototype)
  543. return true;
  544. },
  545. set(nv) {
  546. return true;
  547. },
  548. enumerable: false,
  549. configurable: true
  550. });
  551.  
  552.  
  553. Object.defineProperty(Object.prototype, 'kevlar_unified_player', {
  554. get() {
  555. // console.log(501, this.constructor.prototype)
  556. return true;
  557. },
  558. set(nv) {
  559. return true;
  560. },
  561. enumerable: false,
  562. configurable: true
  563. });
  564.  
  565. // let prr = new PromiseExternal();
  566. // const prrPipeline = createPipeline();
  567. // let stopAndReload = false;
  568.  
  569. let fa = 0;
  570.  
  571. let cv = null;
  572. let durationchangeForMobile = false;
  573. function fixThumbnailURL(src) {
  574. if (typeof src === 'string' && src.length >= 4) {
  575. let m = /\b[a-z0-9]{4,13}\.jpg\b/.exec(src);
  576. if (m && m[0]) {
  577. const t = m[0];
  578. let idx = src.indexOf(t);
  579. let nSrc = idx >= 0 ? src.substring(0, idx + t.length) : '';
  580. return nSrc;
  581. }
  582. }
  583. return src;
  584. }
  585.  
  586. const isDesktopSite = location.origin === 'https://www.youtube.com' && !location.pathname.startsWith('/embed/');
  587.  
  588. const getThumbnailUrlFromThumbnails = (thumbnails) => {
  589.  
  590. let thumbnailUrl = '';
  591. if (thumbnails && thumbnails.length >= 1) {
  592. const arr = thumbnails.map(e => {
  593. return e.url ? [e.width * e.height, e.url] : typeof e === 'string' ? [0, e] : [0, '']
  594. });
  595. arr.sort((a, b) => b[0] - a[0]);
  596. thumbnailUrl = arr[0][1]
  597. if (typeof thumbnailUrl === 'string') {
  598. thumbnailUrl = fixThumbnailURL(thumbnailUrl);
  599. }
  600. }
  601. return thumbnailUrl;
  602. }
  603.  
  604. const pmof = () => {
  605.  
  606. if (SHOW_VIDEO_STATIC_IMAGE) {
  607.  
  608. const medias = [...document.querySelectorAll('ytd-watch-flexy #player .html5-video-container .video-stream.html5-main-video')].filter(e => !e.closest('[hidden]'));
  609. if (medias.length !== 1) return;
  610. const mediaElm = medias[0];
  611.  
  612. const container = mediaElm ? mediaElm.closest('.html5-video-container') : null;
  613. if (!container) return;
  614.  
  615. let thumbnailUrl = '';
  616. const ytdPage = container.closest('ytd-watch-flexy');
  617. if (ytdPage && ytdPage.is === 'ytd-watch-flexy') {
  618. const cnt = insp(ytdPage);
  619. let thumbnails = null;
  620. try {
  621. thumbnails = cnt.polymerController.__data.playerData.videoDetails.thumbnail.thumbnails
  622. // thumbnails = cnt.__data.watchNextData.playerOverlays.playerOverlayRenderer.autoplay.playerOverlayAutoplayRenderer.background.thumbnails
  623. } catch (e) { }
  624.  
  625. thumbnailUrl = getThumbnailUrlFromThumbnails(thumbnails);
  626. }
  627.  
  628.  
  629. if (thumbnailUrl && typeof thumbnailUrl === 'string') {
  630. container.style.setProperty('--audio-only-thumbnail-image', `url(${thumbnailUrl})`);
  631. } else {
  632. container.style.removeProperty('--audio-only-thumbnail-image')
  633. }
  634.  
  635. }
  636.  
  637.  
  638. }
  639. const pmo = new MutationObserver(pmof);
  640.  
  641. isDesktopSite && document.addEventListener('yt-navigate-finish', () => {
  642. const ytdWatchFlexy = document.querySelector('ytd-watch-flexy');
  643. if (ytdWatchFlexy) {
  644. pmo.observe(ytdWatchFlexy, { attributes: true });
  645. ytdWatchFlexy.setAttribute('ytzNavigateFinish', Date.now());
  646. }
  647. });
  648. document.addEventListener('durationchange', (evt) => {
  649. const target = (evt || 0).target;
  650. if (!(target instanceof HTMLMediaElement)) return;
  651. const targetClassList = target.classList || 0;
  652. const isPlayerVideo = typeof targetClassList.contains === 'function' ? targetClassList.contains('video-stream') && targetClassList.contains('html5-main-video') : false;
  653.  
  654. if (durationchangeForMobile || isPlayerVideo) {
  655. if (target.readyState !== 1) {
  656. fa = 1;
  657. } else {
  658. fa = 2;
  659. }
  660. }
  661.  
  662. if (isPlayerVideo) {
  663.  
  664. if (target.readyState === 1 && target.networkState === 2) {
  665. target.__spfgs__ = true;
  666. if (cv) {
  667. cv.resolve();
  668. cv = null;
  669. }
  670. } else {
  671. target.__spfgs__ = false;
  672. }
  673.  
  674. if (isDesktopSite) {
  675. const ytdWatchFlexy = document.querySelector('ytd-watch-flexy');
  676. if (ytdWatchFlexy) {
  677. ytdWatchFlexy.setAttribute('ytzMediaDurationChanged', Date.now());
  678. }
  679. }
  680.  
  681. if (onVideoChangeForMobile) {
  682. onVideoChangeForMobile();
  683. }
  684.  
  685. }
  686. }, true);
  687.  
  688.  
  689.  
  690. // XMLHttpRequest.prototype.open299 = XMLHttpRequest.prototype.open;
  691. /*
  692.  
  693. XMLHttpRequest.prototype.open2 = function(method, url, ...args){
  694.  
  695. if (typeof url === 'string' && url.length > 24 && url.includes('/videoplayback?') && url.replace('?', '&').includes('&source=')) {
  696. if (vcc !== vdd) {
  697. vdd = vcc;
  698. window.postMessage({ ZECxh: url.includes('source=yt_live_broadcast') }, "*");
  699. }
  700. }
  701.  
  702. return this.open299(method, url, ...args)
  703. }*/
  704.  
  705.  
  706.  
  707. // desktop only
  708. // document.addEventListener('yt-page-data-fetched', async (evt) => {
  709.  
  710. // const pageFetchedDataLocal = evt.detail;
  711. // let isLiveNow;
  712. // try {
  713. // isLiveNow = pageFetchedDataLocal.pageData.playerResponse.microformat.playerMicroformatRenderer.liveBroadcastDetails.isLiveNow;
  714. // } catch (e) { }
  715. // window.postMessage({ ZECxh: isLiveNow === true }, "*");
  716.  
  717. // }, false);
  718.  
  719. // return;
  720.  
  721. // let clickLockFn = null;
  722.  
  723.  
  724. let onVideoChangeForMobile = null;
  725.  
  726. let removeBottomOverlayForMobile = null;
  727.  
  728. let clickLockFn = null;
  729. let clickTarget = null;
  730. if (location.origin === 'https://m.youtube.com') {
  731.  
  732. EventTarget.prototype.addEventListener322 = EventTarget.prototype.addEventListener;
  733.  
  734. const dummyFn = () => { };
  735. EventTarget.prototype.addEventListener = function (evt, fn, opts) {
  736.  
  737. let hn = fn;
  738.  
  739. // if (evt === 'player-error') {
  740. // } else if (evt === 'player-detailed-error') {
  741. // } else if (evt === 'video-data-change') {
  742. // } else if (evt === 'player-state-change') {
  743. // } else
  744. if (evt === 'player-autonav-pause' || evt === 'visibilitychange') {
  745. evt += 'y'
  746. fn = dummyFn;
  747. } else if (evt === 'click' && this.id === 'movie_player') {
  748. clickLockFn = fn;
  749. clickTarget = this;
  750. }
  751. return this.addEventListener322(evt, hn, opts)
  752.  
  753. }
  754.  
  755. }
  756.  
  757.  
  758.  
  759. (() => {
  760.  
  761. XMLHttpRequest = (() => {
  762. const XMLHttpRequest_ = XMLHttpRequest;
  763. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  764. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  765. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  766. constructor(...args) {
  767. super(...args);
  768. }
  769. open(method, url, ...args) {
  770. let skip = false;
  771. if (!url || typeof url !== 'string') skip = true;
  772. else if (typeof url === 'string') {
  773. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  774. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  775. skip = true;
  776. } else if (turl.includes('.youtube.com/pagead/')) {
  777. skip = true;
  778. } else if (turl.includes('.youtube.com/ptracking')) {
  779. skip = true;
  780. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  781. // skip = true; // for user activity logging e.g. watched videos
  782. } else if (turl.includes('play.google.com/log')) {
  783. skip = true;
  784. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  785. skip = true;
  786. }
  787. }
  788. if (!skip) {
  789. this.__xmMc8__ = 1;
  790. return super.open(method, url, ...args);
  791. } else {
  792. this.__xmMc8__ = 2;
  793. return super.open('GET', url0);
  794. }
  795. }
  796. send(...args) {
  797. if (this.__xmMc8__ === 1) {
  798. return super.send(...args);
  799. } else if (this.__xmMc8__ === 2) {
  800. return super.send();
  801. } else {
  802. console.log('xhr warning');
  803. return super.send(...args);
  804. }
  805. }
  806. }
  807. c.prototype.__xmMc8__ = 0;
  808. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  809. return c;
  810. })();
  811.  
  812. const s7 = Symbol();
  813. const f7 = () => true;
  814.  
  815. !window.canRetry9048 && generalRegister('canRetry', s7, (p) => {
  816. return typeof p.onStateChange === 'function' && typeof p.dispose === 'function' && typeof p.hide === 'undefined' && typeof p.show === 'undefined' && typeof p.isComplete === 'undefined' && typeof p.getDuration === 'undefined'
  817. }, {
  818. get() {
  819. if ('logger' in this && 'policy' in this && 'xhr' && this) {
  820. if (this.errorMessage && typeof this.errorMessage === 'string' && this.errorMessage.includes('XMLHttpRequest') && this.errorMessage.includes('Invalid URL')) { // "SyntaxError_Failed to execute 'open' on 'XMLHttpRequest': Invalid URL"
  821. // OKAY !
  822. console.log('canRetry05 - ', this.errorMessage)
  823. return f7;
  824. }
  825. // console.log(this)
  826. console.log('canRetry02 - ', this.errorMessage, this)
  827. } else {
  828. console.log('canRetry ERR - ', this.errorMessage)
  829. }
  830. return this[s7];
  831. },
  832. set(nv) {
  833. this[s7] = nv;
  834. return true;
  835. },
  836. enumerable: false,
  837. configurable: true
  838. });
  839. window.canRetry9048 = 1;
  840.  
  841. })();
  842.  
  843.  
  844. const updateLastActiveTimeAsync_ = (player_) => {
  845. if (player_ && typeof player_.updateLastActiveTime === 'function') {
  846. player_.updateLastActiveTime();
  847. }
  848. };
  849.  
  850. const updateLastActiveTimeAsync = (evt) => {
  851. Promise.resolve(evt?.updateLastActiveTime ? evt : evt?.target).then(updateLastActiveTimeAsync_);
  852. };
  853.  
  854.  
  855.  
  856. const { setupAudioPlaying, internalAppPTFn, standardAppPTFn, playerDapPTFn } = (() => {
  857.  
  858. // playerApp: external API [ external use ]
  859. // playerDap: internal player ( with this.app and this.state ) [ the internal interface for both app and state ]
  860. // standardApp: .app of internal player [without isBackground, with fn getVideoDate(), etc]
  861. // internalApp: internal controller inside standardApp (normally non-accessible) [with isBackground, data field videoData, etc]
  862.  
  863. // window.gt1 -> playerApp
  864. // window.gt11 -> playerDap
  865. // window.gt2 -> standardApp
  866. // window.gt3 -> internalApp
  867.  
  868. let key_mediaElementT = '';
  869.  
  870. let key_yn = '';
  871. let key_nS = '';
  872.  
  873. let key_L1 = ''; // playerDap -> internalDap
  874.  
  875. let listAllPublish = false;
  876. let promiseSeek = null;
  877.  
  878. let internalAppXT = null;
  879. let standardAppXT = null;
  880. let playerAppXT = null;
  881. let playerDapXT = null;
  882.  
  883.  
  884.  
  885. /*
  886. const __wmObjectRefs__ = new WeakMap();
  887. class WeakRefSet extends Set {
  888. constructor() {
  889. super();
  890. }
  891. add(obj) {
  892. if (typeof (obj || 0) === 'object') {
  893. let ref = __wmObjectRefs__.get(obj);
  894. if (!ref) {
  895. __wmObjectRefs__.set(obj, (ref = mWeakRef(obj)));
  896. }
  897. super.add(ref);
  898. }
  899. return this;
  900. }
  901. delete(obj) {
  902. if (!obj) return null;
  903. const ref = __wmObjectRefs__.get(obj);
  904. if (ref) {
  905. if(kRef(ref)) return super.delete(ref);
  906. super.delete(ref);
  907. return false;
  908. }
  909. return false;
  910. }
  911. *[Symbol.iterator]() {
  912. for (const value of super.values()) {
  913. const obj = (kRef(value) || null);
  914. if (!obj) {
  915. super.delete(value);
  916. continue;
  917. }
  918. yield obj;
  919. }
  920. }
  921. has(obj) {
  922. if (!obj) return null;
  923. const ref = __wmObjectRefs__.get(obj);
  924. if (!ref) return false;
  925. if (kRef(ref)) return super.has(ref);
  926. super.delete(ref);
  927. return false;
  928. }
  929. }
  930. */
  931.  
  932. const internalAppUT = new Set();
  933. const standardAppUT = new Set();
  934. const playerAppUT = new Set();
  935. const playerDapUT = new Set();
  936. let dirtyMark = 1 | 2 | 4 | 8;
  937.  
  938.  
  939. let playerDapPTDone = false;
  940. // let playerAppPTDone = false;
  941. let standardAppPTDone = false;
  942. let internalAppPTDone = false;
  943.  
  944.  
  945. window.gtz = () => {
  946. return {
  947. internalAppUT, standardAppUT, playerAppUT, playerDapUT, dirtyMark
  948. }
  949. }
  950.  
  951. const getMediaElement = () => {
  952.  
  953. const internalApp = internalAppXM();
  954. const standardApp = standardAppXM();
  955.  
  956. let t;
  957.  
  958. if (t = internalApp?.mediaElement?.[key_mediaElementT]) return t;
  959.  
  960.  
  961. if (t = standardApp?.mediaElement?.[key_mediaElementT]) return t;
  962.  
  963. return null;
  964.  
  965.  
  966.  
  967. }
  968.  
  969. const internalApp_ZZ_sync = function () {
  970. if (byPassSync) {
  971. return;
  972. }
  973. return this.sync9383(...arguments)
  974. };
  975.  
  976. const updateInternalAppFn_ = () => {
  977.  
  978. const internalApp = internalAppXT;
  979. if (internalApp && !internalApp.__s4538__) {
  980. if (internalApp.mediaElement) internalApp.__s4538__ = true;
  981.  
  982. const arr = Object.entries(internalApp).filter(e => e[1] && typeof e[1].sync === 'function');
  983. for (const [key, o] of arr) {
  984. const p = o.__proto__ || o;
  985. if (!p.sync9383 && typeof p.sync === 'function') {
  986. p.sync9383 = p.sync;
  987. p.sync = internalApp_ZZ_sync;
  988. }
  989. }
  990.  
  991. if (!key_yn || !key_nS) {
  992.  
  993. for (const [key, value] of Object.entries(internalApp)) {
  994. if (!key_yn && typeof (value || 0) === 'object' && value.experiments && value.experiments.flags && !isIterable(value)) {
  995. key_yn = key;
  996. console.log(1959, 'key_yn', key_yn)
  997. } else if (!key_nS && typeof (value || 0) === 'object' && 'videoTrack' in value && 'audioTrack' in value && 'isSuspended' in value && !isIterable(value)) {
  998. key_nS = key;
  999. console.log(1959, 'key_nS', key_nS)
  1000. }
  1001. }
  1002.  
  1003. }
  1004.  
  1005. if (!key_mediaElementT) {
  1006. const iaMedia = internalApp.mediaElement || 0;
  1007. // console.log(1959, internalApp, iaMedia)
  1008.  
  1009. if (internalApp && typeof iaMedia === 'object') {
  1010. for (const [key, value] of Object.entries(iaMedia)) {
  1011. if (value instanceof HTMLMediaElement) {
  1012. key_mediaElementT = key;
  1013. console.log(1959, 'key_mediaElementT', key_mediaElementT)
  1014. }
  1015. }
  1016. }
  1017.  
  1018. }
  1019.  
  1020. }
  1021.  
  1022.  
  1023. if (!internalAppPTDone) {
  1024. const proto = internalApp ? internalApp.__proto__ : null;
  1025. if (proto) {
  1026. internalAppPTDone = true;
  1027. internalAppPTFn(proto);
  1028. }
  1029. }
  1030.  
  1031. }
  1032.  
  1033. const updateInternalAppFn = (x) => {
  1034. if (x !== internalAppXT) {
  1035. dirtyMark = 1 | 2 | 4 | 8;
  1036. internalAppUT.add(x);
  1037. internalAppXT = x;
  1038. // videoData
  1039. // stopVideo
  1040. // pauseVideo
  1041.  
  1042. }
  1043. updateInternalAppFn_();
  1044. }
  1045.  
  1046. window.gt3 = () => internalAppXM();
  1047. const internalAppXM = () => {
  1048. if (!(dirtyMark & 4)) return internalAppXT;
  1049. if (!key_mediaElementT) return internalAppXT;
  1050. let result = null;
  1051. for (const p of internalAppUT) {
  1052. const iaMediaP = p.mediaElement;
  1053. if (!iaMediaP) {
  1054. internalAppUT.delete(p);
  1055. } else {
  1056. const element = iaMediaP[key_mediaElementT];
  1057. if (element instanceof Element) {
  1058. if (!element.isConnected) {
  1059. // valid entry but audio is not on the page
  1060.  
  1061. } else if (element.closest('[hidden]')) {
  1062.  
  1063. } else if (result === null) {
  1064. result = p;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. if (!result) return result;
  1070. internalAppUT.add(result);
  1071. internalAppXT = result;
  1072. updateInternalAppFn_();
  1073. if (dirtyMark & 4) dirtyMark -= 4;
  1074. return result;
  1075. }
  1076.  
  1077. const updateStandardAppFn_ = () => {
  1078. const standardAppXT_ = standardAppXT;
  1079. if (!standardAppPTDone) {
  1080. const proto = standardAppXT_ ? standardAppXT_.__proto__ : null;
  1081. if (proto) {
  1082. standardAppPTDone = true;
  1083. standardAppPTFn(proto);
  1084. }
  1085. }
  1086. }
  1087.  
  1088. const updateStandardAppFn = (x) => {
  1089. if (x !== standardAppXT) {
  1090. dirtyMark = 1 | 2 | 4 | 8;
  1091. standardAppUT.add(x);
  1092. standardAppXT = x;
  1093. // isAtLiveHead
  1094. // cancelPlayback
  1095. // stopVideo
  1096. // pauseVideo
  1097. }
  1098. updateStandardAppFn_(x);
  1099. }
  1100. window.gt2 = () => standardAppXM();
  1101.  
  1102. const loadVideoByPlayerVarsP20 = {};
  1103. const loadVideoByPlayerVarsQ20 = new Map();
  1104.  
  1105.  
  1106. const standardAppXM = () => {
  1107.  
  1108. if (!(dirtyMark & 2)) return standardAppXT;
  1109.  
  1110. const internalApp = internalAppXM();
  1111. if (!internalApp) return standardAppXT;
  1112. const iaMedia = internalApp.mediaElement;
  1113.  
  1114.  
  1115. let result = null;
  1116. for (const p of standardAppUT) {
  1117. const iaMediaP = p.mediaElement;
  1118. if (!iaMediaP) {
  1119. standardAppUT.delete(p);
  1120. } else {
  1121. if (iaMediaP === iaMedia) result = p;
  1122. }
  1123. }
  1124. if (!result) return result;
  1125. standardAppUT.add(result);
  1126. standardAppXT = result;
  1127. updateStandardAppFn_();
  1128. if (dirtyMark & 2) dirtyMark -= 2;
  1129. return result;
  1130.  
  1131. }
  1132.  
  1133. const updatePlayerDapFn_ = () => {
  1134.  
  1135. const playerD_ = playerDapXT;
  1136. if (!playerD_.__onVideoProgressF381__) {
  1137. playerD_.__onVideoProgressF381__ = true;
  1138. try {
  1139. playerD_.removeEventListener('onVideoProgress', updateLastActiveTimeAsync); // desktop
  1140. } catch (e) { }
  1141. playerD_.addEventListener('onVideoProgress', updateLastActiveTimeAsync); // desktop
  1142. }
  1143.  
  1144. if (!playerDapPTDone) {
  1145. const proto = playerD_ ? playerD_.__proto__ : null;
  1146. if (proto) {
  1147. playerDapPTDone = true;
  1148. playerDapPTFn(proto);
  1149. }
  1150. }
  1151.  
  1152. const standardApp_ = playerD_.app || 0;
  1153. if (standardApp_) {
  1154. updateStandardAppFn(standardApp_);
  1155. }
  1156. }
  1157.  
  1158. const updatePlayerDapFn = (x) => {
  1159. if (x !== playerDapXT) {
  1160. dirtyMark = 1 | 2 | 4 | 8;
  1161. // console.log('updatePlayerDapFn')
  1162. playerDapUT.add(x);
  1163. playerDapXT = x;
  1164. }
  1165. updatePlayerDapFn_(x);
  1166.  
  1167. }
  1168.  
  1169. window.gt11 = () => {
  1170. return playerDapXM();
  1171. }
  1172. const playerDapXM = () => {
  1173.  
  1174. if (!(dirtyMark & 8)) return playerDapXT;
  1175. const standardApp = standardAppXM();
  1176. if (!standardApp) return playerDapXT;
  1177. let result = null;
  1178. for (const p of playerDapUT) {
  1179. if (!p.app || !p.app.mediaElement) playerDapUT.delete(p);
  1180. else if (p.app === standardApp) result = p;
  1181. }
  1182. if (!result) return result;
  1183. playerDapUT.add(result);
  1184. playerDapXT = result;
  1185. updatePlayerDapFn_();
  1186. if (dirtyMark & 8) dirtyMark -= 8;
  1187. return result;
  1188. }
  1189.  
  1190. const updatePlayerAppFn_ = () => {
  1191.  
  1192. const player_ = playerAppXT;
  1193.  
  1194.  
  1195. if (!player_.__s4539__ || !player_.__s4549__) {
  1196. player_.__s4539__ = true;
  1197.  
  1198.  
  1199. if (!player_.__onVideoProgressF381__ && typeof player_.addEventListener === 'function') {
  1200. player_.__onVideoProgressF381__ = true;
  1201. try {
  1202. player_.removeEventListener('onVideoProgress', updateLastActiveTimeAsync); // desktop
  1203. } catch (e) { }
  1204. player_.addEventListener('onVideoProgress', updateLastActiveTimeAsync); // desktop
  1205. }
  1206.  
  1207. const playerPT = player_.__proto__;
  1208. if (playerPT && typeof playerPT.getPlayerStateObject === 'function' && !playerPT.getPlayerStateObject949) {
  1209. playerPT.getPlayerStateObject949 = playerPT.getPlayerStateObject;
  1210. playerPT.getPlayerStateObject = function () {
  1211. updatePlayerAppFn(this);
  1212. return this.getPlayerStateObject949(...arguments);
  1213. }
  1214. } else if (player_ && typeof player_.getPlayerStateObject === 'function' && !player_.getPlayerStateObject949) {
  1215. player_.getPlayerStateObject949 = player_.getPlayerStateObject;
  1216. player_.getPlayerStateObject = function () {
  1217. updatePlayerAppFn(this);
  1218. return this.getPlayerStateObject949(...arguments);
  1219. }
  1220. }
  1221.  
  1222.  
  1223.  
  1224. // globalPlayer = mWeakRef(player_);
  1225. // window.gp3 = player_;
  1226.  
  1227.  
  1228. let playerDap_ = null;
  1229. {
  1230.  
  1231.  
  1232. const objectSets = new Set();
  1233. Function.prototype.apply129 = Function.prototype.apply;
  1234. Function.prototype.apply = function () {
  1235. objectSets.add([this, ...arguments]);
  1236. return this.apply129(...arguments)
  1237. }
  1238. player_.getPlayerState();
  1239.  
  1240. Function.prototype.apply = Function.prototype.apply129;
  1241.  
  1242. console.log(39912, [...objectSets]);
  1243. let filteredObjects = [...objectSets].filter(e => {
  1244. return Object(e[1]).getPlayerState === e[0]
  1245. });
  1246. console.log(39914, filteredObjects);
  1247.  
  1248. if (filteredObjects.length > 1) {
  1249. filteredObjects = filteredObjects.filter((e) => !(e[1] instanceof Node));
  1250. }
  1251.  
  1252. if (filteredObjects.length === 1) {
  1253. playerDap_ = filteredObjects[0][1];
  1254. }
  1255.  
  1256. objectSets.clear();
  1257. filteredObjects.length = 0;
  1258.  
  1259. }
  1260. {
  1261.  
  1262.  
  1263. let internalApp_ = null;
  1264. if (playerDap_ && playerDap_.app && playerDap_.state) {
  1265. const playerDapP_ = playerDap_.__proto__;
  1266. if (playerDapP_ && (playerDapP_.stopVideo || playerDapP_.pauseVideo) && (playerDapP_.playVideo)) {
  1267. if (!key_L1) {
  1268. const listOfPossibles = [];
  1269. for (const [key, value] of Object.entries(playerDapP_)) {
  1270. if (typeof value === 'function' && value.length === 0 && `${value}`.endsWith('(this.app)}')) { // return g.O5(this.app)
  1271. let m = null;
  1272. try {
  1273. m = playerDap_[key]()
  1274. } catch (e) { }
  1275. if (typeof (m || 0) === 'object') {
  1276. listOfPossibles.push([key, m, evaluateInternalAppScore(m)]);
  1277. }
  1278. }
  1279. }
  1280.  
  1281. if (listOfPossibles.length >= 2) {
  1282. listOfPossibles.sort((a, b) => {
  1283. return b[2] - a[2];
  1284. })
  1285. }
  1286. if (listOfPossibles.length >= 1) {
  1287. key_L1 = listOfPossibles[0][0];
  1288. internalApp_ = listOfPossibles[0][1];
  1289. }
  1290. listOfPossibles.length = 0;
  1291. // key_L1 = '';
  1292. }
  1293. updatePlayerDapFn(playerDap_);
  1294. }
  1295. }
  1296.  
  1297. if (key_L1) {
  1298. const internalApp = internalApp_ || playerDap_[key_L1]();
  1299. if (internalApp) {
  1300. updateInternalAppFn(internalApp);
  1301. player_.__s4549__ = true;
  1302. }
  1303. }
  1304. }
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310. setupFns();
  1311.  
  1312.  
  1313. }
  1314.  
  1315. }
  1316.  
  1317. // player could be just a DOM element without __proto__
  1318. // will this update fail?
  1319. const updatePlayerAppFn = (x) => {
  1320. if (x !== playerAppXT) {
  1321. dirtyMark = 1 | 2 | 4 | 8;
  1322. // console.log('updatePlayerAppFn')
  1323. playerAppUT.add(x);
  1324. playerAppXT = x;
  1325. }
  1326. updatePlayerAppFn_();
  1327. }
  1328. const playerAppXM = () => {
  1329.  
  1330. if (!(dirtyMark & 1)) return playerAppXT;
  1331.  
  1332. const standardApp = standardAppXM();
  1333. if (!standardApp) return playerAppXT;
  1334.  
  1335. const playerAppUA = [...playerAppUT];
  1336. loadVideoByPlayerVarsQ20.clear();
  1337. for (let i = 0; i < playerAppUA.length; i++) {
  1338. const playerApp = playerAppUA[i];
  1339. loadVideoByPlayerVarsP20.index = i;
  1340. try {
  1341. playerApp.loadVideoByPlayerVars(loadVideoByPlayerVarsP20, 0, 0);
  1342. } catch (e) { }
  1343. loadVideoByPlayerVarsP20.index = -1;
  1344. }
  1345. window.loadVideoByPlayerVarsQ20 = loadVideoByPlayerVarsQ20;
  1346.  
  1347. const j = loadVideoByPlayerVarsQ20.get(standardApp);
  1348.  
  1349. const result = Number.isFinite(j) && j >= 0 ? playerAppUA[j] : null;
  1350.  
  1351. const idxSet = new Set(loadVideoByPlayerVarsQ20.values());
  1352.  
  1353. for (let i = 0; i < playerAppUA.length; i++) {
  1354. if (!idxSet.has(i)) playerAppUT.delete(playerAppUA[i]);
  1355. }
  1356. // loadVideoByPlayerVarsQ20.clear();
  1357. if (!result) return result;
  1358. playerAppUT.add(result);
  1359. playerAppXT = result;
  1360. updatePlayerAppFn_();
  1361. if (dirtyMark & 1) dirtyMark -= 1;
  1362. return result;
  1363.  
  1364. }
  1365. window.gt1 = () => playerAppXM();
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371. const playerDapPTFn = (playerDapPT_) => {
  1372.  
  1373. const playerDapPT = playerDapPT_;
  1374.  
  1375.  
  1376. if (playerDapPT && typeof playerDapPT.getPlayerStateObject === 'function' && !playerDapPT.getPlayerStateObject949) {
  1377.  
  1378. playerDapPT.getPlayerStateObject949 = playerDapPT.getPlayerStateObject;
  1379. playerDapPT.getPlayerStateObject = function () {
  1380. updatePlayerDapFn(this);
  1381. return this.getPlayerStateObject949(...arguments);
  1382. };
  1383.  
  1384. }
  1385. };
  1386.  
  1387.  
  1388. const standardAppPTFn = (standardAppPT_) => {
  1389.  
  1390. const standardAppPT = standardAppPT_;
  1391.  
  1392. if (standardAppPT && typeof standardAppPT.loadVideoByPlayerVars === 'function' && !standardAppPT.loadVideoByPlayerVars311) {
  1393.  
  1394. let lastRecord = [];
  1395.  
  1396. standardAppPT.loadVideoByPlayerVars311 = standardAppPT.loadVideoByPlayerVars;
  1397.  
  1398. standardAppPT.loadVideoByPlayerVars = function (p, C, V, N, H) {
  1399. if (p === loadVideoByPlayerVarsP20) {
  1400. // console.log('loadVideoByPlayerVarsP20', p, p.index)
  1401. loadVideoByPlayerVarsQ20.set(this, p.index);
  1402. return;
  1403. }
  1404. updateStandardAppFn(this)
  1405. if (p && typeof p === 'object') {
  1406.  
  1407. const { adPlacements, adSlots } = p.raw_player_response || {};
  1408. if (isIterable(adPlacements)) adPlacements.length = 0;
  1409. if (isIterable(adSlots)) adSlots.length = 0;
  1410.  
  1411. lastRecord.length = 0;
  1412. lastRecord.push(...[p, C, V, N, H]);
  1413. console.log('lastRecord 03022', [...lastRecord])
  1414. }
  1415.  
  1416. return this.loadVideoByPlayerVars311(...arguments);
  1417. }
  1418. }
  1419.  
  1420.  
  1421. };
  1422.  
  1423.  
  1424.  
  1425. const { internalAppPTFn } = (() => {
  1426.  
  1427. const flags_ = {}
  1428. let qma = 0;
  1429. const flagOn_ = (flags, key, bool) => {
  1430. flags_[key] = flags[key];
  1431. flags[key] = typeof flags[key] === 'boolean' ? bool : `${bool}`;
  1432. }
  1433. const flagOn = () => {
  1434. // return;
  1435. const internalApp = internalAppXM();
  1436. if (!key_yn) return;
  1437. const flags = internalApp?.[key_yn]?.experiments?.flags || 0;
  1438. if (!flags) return;
  1439. if (qma < 0) return;
  1440. qma++;
  1441. if (qma > 1) return;
  1442. flagOn_(flags, 'html5_enable_ssap_autoplay_debug_logging', false);
  1443. // flagOn_(flags, 'enable_visit_advertiser_support_on_ipad_mweb', false);
  1444. // flagOn_(flags, 'html5_shorts_onesie_mismatched_fix', false);
  1445. // flagOn_(flags, 'html5_early_media_for_drm', false);
  1446. // flagOn_(flags, 'allow_vp9_1080p_mq_enc', false);
  1447. // flagOn_(flags, 'html5_onesie_preload_use_content_owner', false);
  1448. flagOn_(flags, 'html5_exponential_memory_for_sticky', false);
  1449. // flagOn_(flags, 'html5_perf_cap_override_sticky', false);
  1450. // flagOn_(flags, 'html5_perserve_av1_perf_cap', false);
  1451. // flagOn_(flags, 'html5_disable_low_pipeline', false);
  1452. flagOn_(flags, 'html5_publish_all_cuepoints', false);
  1453. flagOn_(flags, 'html5_ultra_low_latency_subsegment_readahead', false);
  1454. // flagOn_(flags, 'html5_disable_move_pssh_to_moov', false);
  1455. flagOn_(flags, 'html5_sunset_aac_high_codec_family', false);
  1456. // flagOn_(flags, 'html5_enable_ssap_seteos', false);
  1457.  
  1458. // flagOn_(flags, 'html5_catch_errors_for_rollback', false);
  1459. // flagOn_(flags, 'html5_sabr_enable_utc_seek_requests', false);
  1460. // flagOn_(flags, 'html5_sabr_enable_live_clock_offset', false);
  1461. // flagOn_(flags, 'html5_disable_client_resume_policy_for_sabr', false);
  1462. flagOn_(flags, 'html5_trigger_loader_when_idle_network', false);
  1463.  
  1464. flagOn_(flags, 'web_key_moments_markers', false);
  1465. flagOn_(flags, 'embeds_use_parent_visibility_in_ve_logging', false);
  1466. flagOn_(flags, 'html5_onesie', false);
  1467. qma = 1;
  1468. }
  1469.  
  1470. const flagOff = () => {
  1471.  
  1472. // return;
  1473. const internalApp = internalAppXM();
  1474. if (!key_yn) return;
  1475. const flags = internalApp?.[key_yn]?.experiments?.flags || 0;
  1476. if (!flags) return;
  1477. if (qma <= 0) return;
  1478. qma--;
  1479. if (qma > 1) return;
  1480. for (const [key, value] of Object.entries(flags_)) {
  1481. flags[key] = value;
  1482. }
  1483. qma = 0;
  1484. }
  1485.  
  1486.  
  1487. const internalAppPTFn = (internalAppPT_) => {
  1488.  
  1489. const internalAppPT = internalAppPT_;
  1490.  
  1491.  
  1492. if (internalAppPT && internalAppPT.playVideo && !internalAppPT.playVideo9391) {
  1493. internalAppPT.playVideo9391 = internalAppPT.playVideo;
  1494.  
  1495. internalAppPT.playVideo = function (p, C) {
  1496. updateInternalAppFn(this);
  1497. console.log(`[yt-audio-only] internalApp.playVideo; skipPlayPause=${skipPlayPause ? 1 : 0}`);
  1498. try {
  1499. flagOn();
  1500. return this.playVideo9391(...arguments);
  1501. } catch (e) {
  1502. console.warn(e);
  1503. } finally {
  1504. flagOff();
  1505. }
  1506. }
  1507. internalAppPT.playVideo.toString = internalAppPT.playVideo9391.toString.bind(internalAppPT.playVideo9391);
  1508.  
  1509.  
  1510.  
  1511. }
  1512.  
  1513.  
  1514. if (internalAppPT && internalAppPT.pauseVideo && !internalAppPT.pauseVideo9391) {
  1515.  
  1516. internalAppPT.pauseVideo9391 = internalAppPT.pauseVideo;
  1517.  
  1518. internalAppPT.pauseVideo = function (p) {
  1519. updateInternalAppFn(this);
  1520. console.log(`[yt-audio-only] internalApp.pauseVideo; skipPlayPause=${skipPlayPause ? 1 : 0}`);
  1521. try {
  1522. flagOn();
  1523. return this.pauseVideo9391(...arguments);
  1524. } catch (e) {
  1525. console.warn(e);
  1526. } finally {
  1527. flagOff();
  1528. }
  1529. }
  1530. internalAppPT.pauseVideo.toString = internalAppPT.pauseVideo9391.toString.bind(internalAppPT.pauseVideo9391);
  1531.  
  1532.  
  1533. }
  1534.  
  1535.  
  1536. if (internalAppPT && internalAppPT.stopVideo && !internalAppPT.stopVideo9391) {
  1537.  
  1538. internalAppPT.stopVideo9391 = internalAppPT.stopVideo;
  1539.  
  1540. internalAppPT.stopVideo = function () {
  1541. updateInternalAppFn(this);
  1542. console.log(`[yt-audio-only] internalApp.stopVideo; skipPlayPause=${skipPlayPause ? 1 : 0}`);
  1543. try {
  1544. flagOn();
  1545. return this.stopVideo9391(...arguments);
  1546. } catch (e) {
  1547. console.warn(e);
  1548. } finally {
  1549. flagOff();
  1550. }
  1551. }
  1552. internalAppPT.stopVideo.toString = internalAppPT.stopVideo9391.toString.bind(internalAppPT.stopVideo9391);
  1553.  
  1554.  
  1555. }
  1556.  
  1557. if (internalAppPT && internalAppPT.isBackground && !internalAppPT.isBackground9391) {
  1558. internalAppPT.isBackground9391 = internalAppPT.isBackground;
  1559.  
  1560. const f = () => false;
  1561. internalAppPT.isBackground = function () {
  1562. try {
  1563. if (this.visibility.isBackground !== f) this.visibility.isBackground = f;
  1564. return f();
  1565. } catch (e) {
  1566. }
  1567. return false;
  1568. }
  1569.  
  1570. }
  1571.  
  1572. if (internalAppPT && internalAppPT.sendAbandonmentPing && !internalAppPT.sendAbandonmentPing9391) {
  1573. internalAppPT.sendAbandonmentPing9391 = internalAppPT.sendAbandonmentPing;
  1574.  
  1575. internalAppPT.sendAbandonmentPing = function () {
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581. console.log('[yt-audio-only] sendAbandonmentPing');
  1582.  
  1583. const internalApp = this;
  1584. const iaMedia = internalApp ? internalApp.mediaElement : null;
  1585. if (iaMedia) {
  1586. iaMedia.__publishStatus17__ = 0;
  1587. iaMedia.__publishStatus18__ = 0;
  1588. }
  1589.  
  1590. byPassSync = false;
  1591. skipPlayPause = 0;
  1592. byPassNonFatalError = true;
  1593. byPassPublishPatch = true;
  1594.  
  1595. dirtyMark = 1 | 2 | 4 | 8;
  1596.  
  1597. return this.sendAbandonmentPing9391(...arguments);
  1598. }
  1599. }
  1600.  
  1601.  
  1602.  
  1603. if (internalAppPT && internalAppPT.publish && !internalAppPT.publish48) {
  1604.  
  1605.  
  1606. internalAppPT.publish48 = internalAppPT.publish;
  1607.  
  1608. if (PATCH_MEDIA_PUBLISH) {
  1609.  
  1610.  
  1611.  
  1612. const printObject = (b) => {
  1613. return JSON.stringify(Object.entries(b || {}).filter(e => typeof (e[1] || 0) !== 'object'));
  1614. };
  1615.  
  1616.  
  1617. const errorRS = remapString('error');
  1618.  
  1619. internalAppPT.publish33 = async function (a, b) {
  1620. // console.log(3888, a,b);
  1621.  
  1622.  
  1623. if (byPassPublishPatch) return;
  1624. const isLoaded = await dmo.isLoadedW();
  1625. if (!isLoaded) return;
  1626.  
  1627. // window.gt6 = this;
  1628. const player_ = dmo.playerDapXM() || dmo.playerAppXM();
  1629. if (!player_) return;
  1630.  
  1631.  
  1632. const stateObject = dmo.getPlayerWrappedStateObject();
  1633.  
  1634.  
  1635.  
  1636. let publishStatus = 0;
  1637. const iaMedia = this.mediaElement;
  1638.  
  1639. if (!stateObject) return;
  1640.  
  1641. if (stateObject.isUnstarted === true) {
  1642.  
  1643. } else if (iaMedia.__publishStatus17__ >= 100 && iaMedia.__publishStatus17__ < 300) {
  1644.  
  1645. if (iaMedia.__publishStatus18__ < Date.now()) {
  1646. iaMedia.__publishStatus17__ = 0;
  1647. iaMedia.__publishStatus18__ = 0;
  1648. return;
  1649. }
  1650. } else {
  1651. return;
  1652. }
  1653.  
  1654.  
  1655. let kb = false;
  1656.  
  1657. if (a === 'internalaudioformatchange' && typeof (b.author || 0) === 'string' && iaMedia) {
  1658.  
  1659. kb = kb ? true : ((dmo.updateAtPublish && dmo.updateAtPublish(this)), true);
  1660.  
  1661. // byPassSync = true;
  1662. byPassNonFatalError = true;
  1663. await dmo.clearVideoAndQueue();
  1664. await dmo.refreshAllStaleEntitiesForNonReadyAudio();
  1665. byPassNonFatalError = false;
  1666. // byPassSync = false;
  1667. // await cancelPlayback();
  1668. publishStatus = iaMedia.__publishStatus17__ = 100;
  1669.  
  1670. console.log(`[yt-audio-only] publish (internalaudioformatchange, =>100)`);
  1671. iaMedia.__publishStatus18__ = Date.now() + 240;
  1672. }
  1673.  
  1674. const audio = dmo.getMediaElement();
  1675.  
  1676. if (this.mediaElement && audio && a !== 'internalvideoformatchange') {
  1677.  
  1678.  
  1679.  
  1680. if (a.includes('error') || a.includes(errorRS)) {
  1681.  
  1682. if (!iaMedia.__publishStatus17__ || iaMedia.__publishStatus17__ < 200) {
  1683.  
  1684. kb = kb ? true : ((dmo.updateAtPublish && dmo.updateAtPublish(this)), true);
  1685. // byPassSync = true;
  1686. byPassNonFatalError = true;
  1687. await dmo.clearVideoAndQueue(); // avoid error in live streaming
  1688. await dmo.refreshAllStaleEntitiesForNonReadyAudio();
  1689. byPassNonFatalError = false;
  1690. // byPassSync = false;
  1691.  
  1692. console.log(`[yt-audio-only] publish (*error*, <200)`);
  1693. }
  1694.  
  1695.  
  1696. } else {
  1697.  
  1698. iaMedia.__publishStatus17__ = iaMedia.__publishStatus17__ || 100;
  1699. iaMedia.__publishStatus18__ = iaMedia.__publishStatus18__ || (Date.now() + 240);
  1700.  
  1701. // const utv = player_.isAtLiveHead();
  1702.  
  1703.  
  1704. if (iaMedia.__publishStatus17__ === 100) {
  1705. kb = kb ? true : ((dmo.updateAtPublish && dmo.updateAtPublish(this)), true);
  1706. byPassNonFatalError = true;
  1707. await dmo.refreshAllStaleEntitiesForNonReadyAudio();
  1708. byPassNonFatalError = false;
  1709. console.log(`[yt-audio-only] publish (***, =100)`);
  1710. }
  1711. if (iaMedia.__publishStatus17__ === 100 && audio.duration > 0 /* && (dmo.getPlayerStateInt() === 3 || dmo.getPlayerStateInt() === 2) */) {
  1712.  
  1713. iaMedia.__publishStatus17__ = 200
  1714.  
  1715. kb = kb ? true : ((dmo.updateAtPublish && dmo.updateAtPublish(this)), true);
  1716.  
  1717. byPassSync = true;
  1718. skipPlayPause = 3;
  1719. byPassNonFatalError = true;
  1720. await dmo.cancelPlayback();
  1721. await dmo.playVideo();
  1722. byPassNonFatalError = false;
  1723. skipPlayPause = 0;
  1724. byPassSync = false;
  1725. await dmo.seekToLiveHeadForLiveStream();
  1726.  
  1727.  
  1728. await dmo.playVideo();
  1729.  
  1730. console.log(`[yt-audio-only] publish (***, duration>0, stateInt=3, =100, =>200)`);
  1731. iaMedia.__publishStatus18__ = Date.now() + 240;
  1732.  
  1733. }
  1734.  
  1735.  
  1736.  
  1737. if (a === 'onLoadedMetadata' && iaMedia.__publishStatus17__ === 200) {
  1738. iaMedia.__publishStatus17__ = 201;
  1739. console.log(`[yt-audio-only] publish (onLoadedMetadata, =200, =>201)`);
  1740. iaMedia.__publishStatus18__ = Date.now() + 240;
  1741. }
  1742. if (a === 'videoelementevent' && b.type === 'loadedmetadata' && iaMedia.__publishStatus17__ === 201) {
  1743. iaMedia.__publishStatus17__ = 202;
  1744. console.log(`[yt-audio-only] publish (videoelementevent.loadedmetadata, =201, =>202)`);
  1745. iaMedia.__publishStatus18__ = Date.now() + 240;
  1746. }
  1747. if (a === 'videoelementevent' && b.type === 'progress' && iaMedia.__publishStatus17__ === 202) {
  1748.  
  1749. iaMedia.__publishStatus17__ = 203;
  1750. // window.debug_mfk = this;
  1751. // window.debug_mfp = player_;
  1752. console.log(`[yt-audio-only] publish (videoelementevent.progress, =202, =>203)`);
  1753. iaMedia.__publishStatus18__ = Date.now() + 240;
  1754. }
  1755. if (iaMedia.__publishStatus17__ === 203 && audio && audio.readyState === 1) {
  1756.  
  1757. // byPassSync = true;
  1758. iaMedia.__publishStatus17__ = 204;
  1759.  
  1760. kb = kb ? true : ((dmo.updateAtPublish && dmo.updateAtPublish(this)), true);
  1761.  
  1762. byPassSync = true;
  1763. skipPlayPause = 3;
  1764. byPassNonFatalError = true;
  1765. await dmo.pauseVideo();
  1766. await dmo.playVideo();
  1767. byPassNonFatalError = false;
  1768. skipPlayPause = 0;
  1769. byPassSync = false;
  1770. await dmo.seekToLiveHeadForLiveStream();
  1771. // byPassSync = false;
  1772.  
  1773. await dmo.playVideo();
  1774. delayPn(80).then(async () => {
  1775. const internalApp = internalAppXM();
  1776. if (internalApp !== this) return;
  1777. const iaMedia = internalApp.mediaElement;
  1778.  
  1779. if (iaMedia.__publishStatus17__ === 204) {
  1780.  
  1781. iaMedia.__publishStatus17__ = 200
  1782.  
  1783. byPassSync = true;
  1784. skipPlayPause = 3;
  1785. byPassNonFatalError = true;
  1786. await dmo.cancelPlayback();
  1787. await dmo.playVideo();
  1788. byPassNonFatalError = false;
  1789. skipPlayPause = 0;
  1790. byPassSync = false;
  1791. await delayPn(80);
  1792.  
  1793. await dmo.seekToLiveHeadForLiveStream();
  1794. // byPassSync = false;
  1795.  
  1796. await dmo.playVideo();
  1797.  
  1798. console.log(`[yt-audio-only] publish (***, =204, =>200)`);
  1799.  
  1800. }
  1801. });
  1802.  
  1803. console.log(`[yt-audio-only] publish (***, audio.readyState=1, =203, =>204)`);
  1804. iaMedia.__publishStatus18__ = Date.now() + 240;
  1805.  
  1806. }
  1807.  
  1808.  
  1809. if (iaMedia.__publishStatus17__ < 300 && iaMedia.__publishStatus17__ >= 200 && a === 'videoelementevent' && b.type === 'timeupdate' && !audio.paused && audio.readyState >= 4 && audio.duration > 0) {
  1810. iaMedia.__publishStatus17__ = 300;
  1811. if (!dmo.isAtLiveHeadW()) {
  1812. kb = kb ? true : ((dmo.updateAtPublish && dmo.updateAtPublish(this)), true);
  1813. await dmo.seekToLiveHeadForLiveStream();
  1814. }
  1815.  
  1816. console.log(`[yt-audio-only] publish (videoelementevent.timeupdate, {audio playing}, [200, 300), =>300)`);
  1817. iaMedia.__publishStatus18__ = Date.now() + 240;
  1818. }
  1819.  
  1820.  
  1821. }
  1822.  
  1823.  
  1824. publishStatus = iaMedia.__publishStatus17__;
  1825.  
  1826. if (debugFlg001) console.log('gkps0 publish | ' + publishStatus, a, printObject(b))
  1827.  
  1828. }
  1829. }
  1830.  
  1831. }
  1832.  
  1833. internalAppPT.publish = function (p, C) {
  1834. if (promiseSeek) {
  1835. if (p === 'videoelementevent' && C && C.type === 'playing') {
  1836. promiseSeek.resolve();
  1837. } else if (p === 'SEEK_COMPLETE') {
  1838. promiseSeek.resolve();
  1839. }
  1840. }
  1841.  
  1842. let qb = false;
  1843. if (byPassSync || (byPassNonFatalError && p === 'nonfatalerror')) {
  1844. qb = true;
  1845. }
  1846. if (qb) {
  1847. arguments[0] = p = typeof p === 'string' ? remapString(p) : p;
  1848. }
  1849.  
  1850.  
  1851. if (listAllPublish) console.log('[yt-audio-only] list publish', p, C)
  1852. if (this.publish33) {
  1853. try {
  1854. if (dmo.ready) this.publish33(p, C);
  1855. } catch (e) {
  1856. console.warn(e);
  1857. }
  1858. }
  1859. return this.publish48(...arguments);
  1860. }
  1861.  
  1862. }
  1863.  
  1864.  
  1865.  
  1866.  
  1867. if (!internalAppPT.setMediaElement661 && typeof internalAppPT.setMediaElement === 'function') {
  1868. internalAppPT.setMediaElement661 = internalAppPT.setMediaElement;
  1869. internalAppPT.setMediaElement = function (p) {
  1870. updateInternalAppFn(this);
  1871. console.log('setMediaElement', p)
  1872. return this.setMediaElement661(...arguments);
  1873. }
  1874. }
  1875.  
  1876.  
  1877.  
  1878. }
  1879.  
  1880. return { internalAppPTFn }
  1881.  
  1882.  
  1883. })();
  1884.  
  1885.  
  1886.  
  1887. let setupFnsB = false;
  1888. const setupFns = () => {
  1889. if (setupFnsB) return;
  1890. setupFnsB = true;
  1891.  
  1892. try {
  1893.  
  1894. const clearVideoAndQueue = async () => { // avoid error in live streaming
  1895. const player_ = playerAppXM();
  1896. const playerD_ = playerDapXM();
  1897. const standardApp = standardAppXM();
  1898. if (standardApp && standardApp.clearQueue) {
  1899. return await standardApp.clearQueue();
  1900. } else if (playerD_ && playerD_.clearQueue) {
  1901. return await playerD_.clearQueue();
  1902. } else if (player_ && player_.clearQueue) {
  1903. return await player_.clearQueue();
  1904. } else {
  1905. return null;
  1906. }
  1907. }
  1908.  
  1909. const cancelPlayback = async () => {
  1910.  
  1911. const player_ = playerAppXM();
  1912. const playerD_ = playerDapXM();
  1913. const standardApp = standardAppXM();
  1914. const internalApp = internalAppXM();
  1915.  
  1916. if (internalApp && internalApp.stopVideo && internalApp.pauseVideo && !internalApp.cancelPlayback) {
  1917. return await internalApp.stopVideo();
  1918. } else if (standardApp && standardApp.cancelPlayback) {
  1919. return await standardApp.cancelPlayback();
  1920. } else if (playerD_ && playerD_.cancelPlayback) {
  1921. return await playerD_.cancelPlayback();
  1922. } else if (player_ && player_.cancelPlayback) {
  1923. return await player_.cancelPlayback();
  1924. } else {
  1925. return null;
  1926. }
  1927. }
  1928.  
  1929. const pauseVideo = async () => {
  1930.  
  1931.  
  1932. const player_ = playerAppXM();
  1933. const playerD_ = playerDapXM();
  1934. const standardApp = standardAppXM();
  1935. const internalApp = internalAppXM();
  1936.  
  1937. if (internalApp && internalApp.stopVideo && internalApp.pauseVideo && !internalApp.cancelPlayback) {
  1938. return await internalApp.pauseVideo();
  1939. } else if (standardApp && standardApp.pauseVideo) {
  1940. return await standardApp.pauseVideo();
  1941. } else if (playerD_ && playerD_.pauseVideo) {
  1942. return await playerD_.pauseVideo();
  1943. } else if (player_ && player_.pauseVideo) {
  1944. return await player_.pauseVideo();
  1945. } else {
  1946. return null
  1947. }
  1948. }
  1949.  
  1950. const playVideo = async () => {
  1951.  
  1952. const player_ = playerAppXM();
  1953. const playerD_ = playerDapXM();
  1954. const standardApp = standardAppXM();
  1955. const internalApp = internalAppXM();
  1956.  
  1957. if (internalApp && internalApp.stopVideo && internalApp.pauseVideo && !internalApp.cancelPlayback && internalApp.playVideo) {
  1958. return await internalApp.playVideo();
  1959. } else if (standardApp && standardApp.playVideo) {
  1960. return await standardApp.playVideo();
  1961. } else if (playerD_ && playerD_.playVideo) {
  1962. return await playerD_.playVideo();
  1963. } else if (player_ && player_.playVideo) {
  1964. return await player_.playVideo();
  1965. } else {
  1966. return null
  1967. }
  1968. }
  1969.  
  1970. const isAtLiveHeadW = async () => {
  1971.  
  1972. const player_ = playerAppXM();
  1973. const playerD_ = playerDapXM();
  1974. const standardApp = standardAppXM();
  1975. const internalApp = internalAppXM();
  1976.  
  1977.  
  1978. if (internalApp && internalApp.isAtLiveHead) {
  1979. return await internalApp.isAtLiveHead()
  1980. } else if (standardApp && standardApp.isAtLiveHead) {
  1981. return await standardApp.isAtLiveHead()
  1982. } else if (playerD_ && playerD_.isAtLiveHead) {
  1983. return await playerD_.isAtLiveHead()
  1984. } else if (player_ && player_.isAtLiveHead) {
  1985. return await player_.isAtLiveHead()
  1986. } else {
  1987. return null;
  1988. }
  1989. }
  1990.  
  1991.  
  1992. const isAdW = async () => {
  1993.  
  1994. const standardApp = standardAppXM();
  1995. const internalApp = internalAppXM();
  1996.  
  1997. const vd = (internalApp ? internalApp.videoData : (standardApp ? standardApp.getVideoData() : null)) || 0;
  1998.  
  1999. if (vd && typeof vd.isAd === 'function') {
  2000. return await vd.isAd();
  2001. } else if (vd && typeof vd.isAd === 'boolean') {
  2002.  
  2003. return vd.isAd;
  2004.  
  2005. } else {
  2006. return null;
  2007. }
  2008. }
  2009.  
  2010. const isLoadedW = async () => {
  2011.  
  2012. const standardApp = standardAppXM();
  2013. const internalApp = internalAppXM();
  2014.  
  2015.  
  2016. const vd = (internalApp ? internalApp.videoData : (standardApp ? standardApp.getVideoData() : null)) || 0;
  2017.  
  2018. if (vd && typeof vd.isLoaded === 'function') {
  2019. return await vd.isLoaded();
  2020. } else if (vd && typeof vd.isLoaded === 'boolean') {
  2021.  
  2022. return vd.isLoaded;
  2023.  
  2024. } else {
  2025. return null;
  2026. }
  2027.  
  2028. }
  2029.  
  2030. const getPlayerWrappedStateObject = () => {
  2031.  
  2032.  
  2033. // g.h.oD = function(p) {
  2034. // p = this.app.getPlayerStateObject(p);
  2035. // return {
  2036. // isBuffering: g.r(p, 1),
  2037. // isCued: p.isCued(),
  2038. // isDomPaused: g.r(p, 1024),
  2039. // isEnded: g.r(p, 2),
  2040. // isError: g.r(p, 128),
  2041. // isOrWillBePlaying: p.isOrWillBePlaying(),
  2042. // isPaused: p.isPaused(),
  2043. // isPlaying: p.isPlaying(),
  2044. // isSeeking: g.r(p, 16),
  2045. // isUiSeeking: g.r(p, 32),
  2046. // isUnstarted: g.r(p, 64)
  2047. // }
  2048. // }
  2049.  
  2050.  
  2051. const standardApp = standardAppXM();
  2052. const playerD_ = playerDapXM();
  2053. const player_ = playerAppXM();
  2054. const app = standardApp || playerD_;
  2055. if (app && typeof app.getPlayerStateObject === 'function') {
  2056. const fo = app.getPlayerStateObject();
  2057. const flag = fo ? (fo.state || 0) : 0;
  2058. return {
  2059. isBuffering: (flag & 1) === 1,
  2060. isCued: (flag & 64) === 64 && (flag & 8) === 0 && (flag & 4) === 0,
  2061. isDomPaused: (flag & 1024) === 1024,
  2062. isEnded: (flag & 2) === 2,
  2063. isError: (flag & 128) === 128,
  2064. isOrWillBePlaying: (flag & 8) === 8 && (flag & 2) === 0 && (flag & 1024) === 0,
  2065. isPaused: (flag & 4) === 4,
  2066. isPlaying: (flag & 8) === 8 && (flag & 512) === 0 && (flag & 64) === 0 && (flag & 2) === 0,
  2067. isSeeking: (flag & 16) === 16,
  2068. isUiSeeking: (flag & 32) === 32,
  2069. isUnstarted: (flag & 64) === 64,
  2070. };
  2071. } else if (player_ && typeof player_.getPlayerStateObject === 'function') {
  2072. return player_.getPlayerStateObject();
  2073. } else {
  2074. return {};
  2075. }
  2076.  
  2077. }
  2078.  
  2079. const getPlayerStateInt = () => {
  2080.  
  2081. const playerD_ = playerDapXM();
  2082. const player_ = playerAppXM();
  2083.  
  2084. if (playerD_ && typeof playerD_.getPlayerState === 'function') {
  2085. return playerD_.getPlayerState();
  2086.  
  2087. } else if (player_ && typeof player_.getPlayerState === 'function') {
  2088. return player_.getPlayerState();
  2089.  
  2090. } else {
  2091. return null;
  2092. }
  2093. }
  2094.  
  2095. const updateAtPublish = (x) => {
  2096. dirtyMark = 1 | 2 | 4 | 8;
  2097. updateInternalAppFn(x);
  2098. }
  2099.  
  2100. const refreshAllStaleEntitiesForNonReadyAudio = async () => {
  2101.  
  2102. const player_ = playerAppXM(); // player or xj
  2103. if (!player_) return;
  2104. const audio = getMediaElement();
  2105. try {
  2106. // byPassSync = true;
  2107. if (audio.readyState == 0 && audio.isConnected === true) await player_.refreshAllStaleEntities();
  2108. // byPassSync = false;
  2109. } catch (e) {
  2110. }
  2111. };
  2112. const seekToLiveHeadForLiveStream = async () => {
  2113. const player_ = playerDapXM() || playerAppXM(); // player or xj
  2114. const audio = getMediaElement();
  2115. try {
  2116. audio.isConnected === true && await player_.seekToLiveHead();
  2117. if (audio.isConnected === true && (await player_.isAtLiveHead()) === true) {
  2118. audio.isConnected === true && await player_.seekToStreamTime();
  2119. return true;
  2120. }
  2121. } catch (e) {
  2122. console.log('error_F7', e);
  2123. }
  2124. };
  2125.  
  2126. const trySeekToLiveHead = async () => {
  2127. const player_ = playerDapXM() || playerAppXM(); // player or xj
  2128. try {
  2129. await player_.seekToLiveHead();
  2130. if ((await player_.isAtLiveHead()) === true) {
  2131. await player_.seekToStreamTime();
  2132. }
  2133. } catch (e) { }
  2134. }
  2135.  
  2136. Object.assign(dmo, { clearVideoAndQueue, cancelPlayback, pauseVideo, playVideo, isAtLiveHeadW, updateAtPublish, refreshAllStaleEntitiesForNonReadyAudio, seekToLiveHeadForLiveStream, ready: true, isLoadedW, getMediaElement, playerAppXM, standardAppXM, internalAppXM, playerDapXM, getPlayerStateInt, getPlayerWrappedStateObject });
  2137.  
  2138.  
  2139.  
  2140. const getPublishStatus17 = () => {
  2141.  
  2142. const internalApp = internalAppXM();
  2143. const iaMedia = internalApp ? internalApp.mediaElement : null;
  2144. return iaMedia ? iaMedia.__publishStatus17__ : null;
  2145. }
  2146.  
  2147. const shouldWaitPublish = () => {
  2148. let waitPublish = false;
  2149. const internalApp = internalAppXM();
  2150. const iaMedia = internalApp ? internalApp.mediaElement : null;
  2151. const stateObject = getPlayerWrappedStateObject();
  2152. if (stateObject && stateObject.isUnstarted === true) {
  2153. waitPublish = true;
  2154. } else if (iaMedia && iaMedia.__publishStatus17__ >= 100 && iaMedia.__publishStatus17__ < 300) {
  2155. waitPublish = true;
  2156. } else {
  2157. waitPublish = false;
  2158. }
  2159. return waitPublish;
  2160. }
  2161.  
  2162. let playBusy = 0;
  2163. if (!HTMLAudioElement.prototype.play3828 && !HTMLAudioElement.prototype.pause3828) {
  2164.  
  2165. HTMLAudioElement.prototype.pause3828 = HTMLAudioElement.prototype.pause;
  2166. HTMLAudioElement.prototype.pause = function () {
  2167. if (skipPlayPause & 2) return;
  2168.  
  2169. if (getMediaElement() === this) {
  2170.  
  2171. const internalApp = internalAppXM();
  2172. const iaMedia = internalApp ? internalApp.mediaElement : null;
  2173. if (iaMedia) {
  2174. iaMedia.__publishStatus17__ = 0;
  2175. iaMedia.__publishStatus18__ = 0;
  2176. }
  2177. }
  2178.  
  2179. return this.pause3828();
  2180. }
  2181.  
  2182. HTMLAudioElement.prototype.play3828 = HTMLAudioElement.prototype.play;
  2183. HTMLAudioElement.prototype.play = async function () {
  2184. if (skipPlayPause & 1) return;
  2185.  
  2186. if (playBusy > 0) return await this.play3828();
  2187. console.log('[yt-audio-only] video.play01');
  2188. if (getMediaElement() !== this) {
  2189. dirtyMark = 1 | 2 | 4 | 8;
  2190. }
  2191.  
  2192.  
  2193. const audio = this;
  2194. const internalApp = internalAppXM();
  2195. if (!internalApp.mediaElement) return await this.play3828();
  2196. if (audio !== getMediaElement()) return await this.play3828();
  2197.  
  2198. console.log('[yt-audio-only] video.play02', getPublishStatus17())
  2199. // if ((await isAdW()) === true) return;
  2200.  
  2201.  
  2202. let isAtLiveHead = await isAtLiveHeadW();
  2203. Promise.resolve().then(async () => {
  2204. dirtyMark = 1 | 2 | 4 | 8;
  2205.  
  2206. // between play02 and play03, < publish (***, duration>0, stateInt=3, =100, =>200) > should occur
  2207. console.log('[yt-audio-only] video.play03', getPublishStatus17())
  2208.  
  2209.  
  2210.  
  2211. if (!shouldWaitPublish()) {
  2212. await delayPn(80);
  2213. dirtyMark = 1 | 2 | 4 | 8;
  2214. }
  2215.  
  2216. if (shouldWaitPublish()) {
  2217. await delayPn(400);
  2218. dirtyMark = 1 | 2 | 4 | 8;
  2219. }
  2220.  
  2221. console.log('[yt-audio-only] video.play04', getPublishStatus17());
  2222.  
  2223. if (getMediaElement() !== this) {
  2224. dirtyMark = 1 | 2 | 4 | 8;
  2225. }
  2226. if (internalApp !== internalAppXM()) return;
  2227. if (!internalApp.mediaElement) return;
  2228. if (audio !== getMediaElement()) return;
  2229. const stateObject = getPlayerWrappedStateObject();
  2230. if (stateObject.isOrWillBePlaying === false || stateObject.isPaused === true || stateObject.isEnded === true) return;
  2231.  
  2232. console.log('[yt-audio-only] video.play05')
  2233.  
  2234. console.log(1293, stateObject);
  2235.  
  2236. let bool = false;
  2237. if (stateObject.isBuffering && !stateObject.isEnded && !stateObject.isError && stateObject.isSeeking && stateObject.isUnstarted && !stateObject.isCued) {
  2238. bool = true;
  2239. } else if (stateObject.isOrWillBePlaying && stateObject.isSeeking && !stateObject.isCued && stateObject.isPlaying) {
  2240. bool = true;
  2241. // } else if( stateObject.isBuffering && !stateObject.isSeeking && !stateObject.isCued && !stateObject.isEnded && !stateObject.isError && stateObject.isOrWillBePlaying && stateObject.isPlaying && !stateObject.isUnstarted){
  2242. // // bool = true;
  2243. }
  2244.  
  2245.  
  2246. if (!isAtLiveHead && stateObject.isUnstarted === true && stateObject.isOrWillBePlaying) {
  2247.  
  2248. const vd = internalApp.videoData;
  2249. if (vd.isLivePlayback && vd.isLiveHeadPlayable) {
  2250. console.log('isAtLiveHead: false -> true')
  2251. isAtLiveHead = true;
  2252. }
  2253.  
  2254. }
  2255.  
  2256. console.log(3882, bool, isAtLiveHead)
  2257.  
  2258. if (bool) {
  2259.  
  2260. console.log('[yt-audio-only] video.play06')
  2261.  
  2262.  
  2263.  
  2264. if (internalApp !== internalAppXM()) return;
  2265. if (!internalApp.mediaElement) return;
  2266.  
  2267.  
  2268. playBusy++;
  2269.  
  2270. console.log('[yt-audio-only] video.play07')
  2271.  
  2272. // byPassSync = true;
  2273. byPassNonFatalError = true;
  2274. byPassPublishPatch = true;
  2275. if ((await isLoadedW()) === false) {
  2276. await clearVideoAndQueue();
  2277. await cancelPlayback();
  2278. } else {
  2279. await cancelPlayback();
  2280. }
  2281. byPassNonFatalError = false;
  2282. byPassPublishPatch = false;
  2283.  
  2284. dirtyMark = 1 | 2 | 4 | 8;
  2285.  
  2286.  
  2287. console.log('[yt-audio-only] video.play08')
  2288.  
  2289.  
  2290. // await delayPn(40);
  2291. // await audio.pause();
  2292.  
  2293. promiseSeek = new PromiseExternal();
  2294. // listAllPublish = true;
  2295. if (isAtLiveHead) {
  2296. console.log('[yt-audio-only] video.play08.1')
  2297. await trySeekToLiveHead();
  2298. dirtyMark = 1 | 2 | 4 | 8;
  2299. console.log('[yt-audio-only] video.play08.2')
  2300. }
  2301.  
  2302. // await delayPn(40);
  2303.  
  2304. console.log('[yt-audio-only] video.play09')
  2305. const qX = getPlayerWrappedStateObject();
  2306. if (qX.isBuffering || qX.isSeeking || qX.isUnstarted) {
  2307.  
  2308. console.log('[yt-audio-only] video.play09.1')
  2309. await playVideo();
  2310. dirtyMark = 1 | 2 | 4 | 8;
  2311.  
  2312. console.log('[yt-audio-only] video.play09.2')
  2313. }
  2314.  
  2315.  
  2316.  
  2317.  
  2318. // byPassSync = false;
  2319. playBusy--;
  2320.  
  2321. const r = await Promise.race([promiseSeek, delayPn(800).then(() => 123)]);
  2322. promiseSeek = null;
  2323.  
  2324. if (r !== 123) {
  2325. try {
  2326. // listAllPublish = false;
  2327. await playVideo();
  2328. dirtyMark = 1 | 2 | 4 | 8;
  2329. } catch (e) {
  2330. }
  2331. return;
  2332. } else {
  2333. try {
  2334. // listAllPublish = false;
  2335. await playVideo();
  2336. dirtyMark = 1 | 2 | 4 | 8;
  2337. } catch (e) {
  2338. }
  2339. setTimeout_(() => {
  2340. audio.play();
  2341. }, 80);
  2342. return;
  2343. }
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349. }
  2350.  
  2351.  
  2352.  
  2353. }).catch(console.warn);
  2354.  
  2355.  
  2356. try {
  2357. dirtyMark = 1 | 2 | 4 | 8;
  2358. playBusy++;
  2359.  
  2360. return await this.play3828();
  2361. } catch (e) {
  2362.  
  2363. } finally {
  2364.  
  2365.  
  2366. playBusy--;
  2367. dirtyMark = 1 | 2 | 4 | 8;
  2368. }
  2369.  
  2370.  
  2371.  
  2372. }
  2373.  
  2374.  
  2375. }
  2376.  
  2377.  
  2378.  
  2379. console.log('[yt-audio-only] DONE')
  2380.  
  2381. } catch (e) {
  2382. console.warn(e);
  2383. }
  2384.  
  2385.  
  2386.  
  2387.  
  2388. }
  2389.  
  2390. const setupAudioPlaying = (player00_) => {
  2391.  
  2392. // console.log(5939,player00_);
  2393.  
  2394. try {
  2395. const player_ = player00_;
  2396. if (!player_) return;
  2397. if (player_.__audio544__) return;
  2398. player_.__audio544__ = 1;
  2399.  
  2400. updatePlayerAppFn(player_);
  2401.  
  2402. } catch (e) {
  2403. console.warn(e);
  2404. }
  2405. }
  2406.  
  2407. if (!window.__ugAtg3747__) {
  2408. window.__ugAtg3747__ = true;
  2409. const updateLastActiveTimeGeneral = () => {
  2410. // player_ -> yuu
  2411. const player_ = playerDapXM() || playerAppXM();
  2412. if (player_) player_.updateLastActiveTime();
  2413. };
  2414. document.addEventListener('timeupdate', updateLastActiveTimeGeneral, true);
  2415. }
  2416.  
  2417. return { setupAudioPlaying, internalAppPTFn, standardAppPTFn, playerDapPTFn };
  2418.  
  2419. })();
  2420.  
  2421.  
  2422. if (location.origin === 'https://www.youtube.com') {
  2423.  
  2424.  
  2425.  
  2426. if (location.pathname.startsWith('/embed/')) {
  2427.  
  2428. // youtube embed
  2429.  
  2430. const ytEmbedReady = observablePromise(() => document.querySelector('#player > .ytp-embed')).obtain();
  2431.  
  2432. const embedConfigFix = (async () => {
  2433. while (true) {
  2434. const config_ = typeof yt !== 'undefined' ? (yt || 0).config_ : 0;
  2435. if (config_) {
  2436. ytConfigFix(config_);
  2437. break;
  2438. }
  2439. await delayPn(60);
  2440. }
  2441. });
  2442.  
  2443. ytEmbedReady.then(async (embedPlayer) => {
  2444.  
  2445. embedConfigFix();
  2446.  
  2447. const player_ = embedPlayer;
  2448. console.log(5919, player_)
  2449.  
  2450. setupAudioPlaying(player_); // dekstop embed
  2451.  
  2452.  
  2453. if (SHOW_VIDEO_STATIC_IMAGE) {
  2454.  
  2455. let displayImage = '';
  2456. let html5Container = null;
  2457.  
  2458.  
  2459. const moviePlayer = document.querySelector('#movie_player .html5-video-container .video-stream.html5-main-video');
  2460. if (moviePlayer) {
  2461. html5Container = moviePlayer.closest('.html5-video-container');
  2462. }
  2463.  
  2464. if (html5Container) {
  2465.  
  2466. const overlayImage = document.querySelector('#movie_player .ytp-cued-thumbnail-overlay-image[style]');
  2467. if (overlayImage) {
  2468.  
  2469. const cStyle = window.getComputedStyle(overlayImage);
  2470. const cssImageValue = cStyle.backgroundImage;
  2471. if (cssImageValue && typeof cssImageValue === 'string' && cssImageValue.startsWith('url(')) {
  2472. displayImage = cssImageValue;
  2473.  
  2474. }
  2475.  
  2476. }
  2477.  
  2478. if (!displayImage) {
  2479.  
  2480. const config_ = typeof yt !== 'undefined' ? (yt || 0).config_ : 0;
  2481. let embedded_player_response = null;
  2482. if (config_) {
  2483. embedded_player_response = ((config_.PLAYER_VARS || 0).embedded_player_response || 0)
  2484. }
  2485. if (embedded_player_response && typeof embedded_player_response === 'string') {
  2486.  
  2487. let idx1 = embedded_player_response.indexOf('"defaultThumbnail"');
  2488. let idx2 = idx1 >= 0 ? embedded_player_response.lastIndexOf('"defaultThumbnail"') : -1;
  2489.  
  2490. if (idx1 === idx2 && idx1 > 0) {
  2491.  
  2492. let bk = 0;
  2493. let j = -1;
  2494. for (let i = idx1; i < embedded_player_response.length; i++) {
  2495. if (i > idx1 + 40 && bk === 0) {
  2496. j = i;
  2497. break;
  2498. }
  2499. let t = embedded_player_response.charAt(i);
  2500. if (t === '{') bk++;
  2501. else if (t === '}') bk--;
  2502. }
  2503.  
  2504. if (j > idx1) {
  2505.  
  2506. let defaultThumbnailString = embedded_player_response.substring(idx1, j);
  2507. let defaultThumbnailObject = null;
  2508.  
  2509. try {
  2510. defaultThumbnailObject = JSON.parse(`{${defaultThumbnailString}}`);
  2511.  
  2512. } catch (e) { }
  2513.  
  2514. const thumbnails = ((defaultThumbnailObject.defaultThumbnail || 0).thumbnails || 0);
  2515.  
  2516. if (thumbnails && thumbnails.length >= 1) {
  2517.  
  2518. let thumbnailUrl = getThumbnailUrlFromThumbnails(thumbnails);
  2519.  
  2520. if (thumbnailUrl && thumbnailUrl.length > 3) {
  2521. displayImage = `url(${thumbnailUrl})`;
  2522. }
  2523. }
  2524. }
  2525.  
  2526. }
  2527.  
  2528.  
  2529. }
  2530.  
  2531.  
  2532. }
  2533.  
  2534. if (displayImage) {
  2535.  
  2536. html5Container.style.setProperty('--audio-only-thumbnail-image', `${displayImage}`);
  2537. } else {
  2538. html5Container.style.removeProperty('--audio-only-thumbnail-image')
  2539. }
  2540.  
  2541. }
  2542.  
  2543.  
  2544. }
  2545.  
  2546. });
  2547.  
  2548.  
  2549. } else {
  2550.  
  2551.  
  2552. // youtube normal
  2553.  
  2554. attachOneTimeEvent('yt-action', () => {
  2555. const config_ = typeof yt !== 'undefined' ? (yt || 0).config_ : 0;
  2556. ytConfigFix(config_);
  2557. });
  2558.  
  2559. let r3 = new PromiseExternal();
  2560. document.addEventListener('yt-action', () => {
  2561. let u = document.querySelector('ytd-watch-flexy');
  2562. if (u && typeof insp(u).calculateCurrentPlayerSize_ === 'function') {
  2563. r3.resolve(u);
  2564. }
  2565.  
  2566. }, true);
  2567.  
  2568. r3.then((watchFlexy) => {
  2569. // for offline video, without audio -> so no size
  2570.  
  2571. if (!watchFlexy) return;
  2572. const cnt = insp(watchFlexy);
  2573. if (typeof cnt.calculateCurrentPlayerSize_ === 'function' && !cnt.calculateCurrentPlayerSize3991_) {
  2574.  
  2575. cnt.calculateCurrentPlayerSize3991_ = cnt.calculateCurrentPlayerSize_;
  2576. cnt.calculateCurrentPlayerSize_ = function () {
  2577. const r = this.calculateCurrentPlayerSize3991_(...arguments);
  2578.  
  2579. if (r && r.width > 10 && !Number.isFinite(r.height)) {
  2580. r.height = Math.round(r.width / 16 * 9);
  2581. }
  2582. return r;
  2583.  
  2584. }
  2585.  
  2586. }
  2587.  
  2588. });
  2589.  
  2590.  
  2591.  
  2592. customElements.whenDefined('ytd-player').then(() => {
  2593. const dummy = document.querySelector('ytd-player') || document.createElement('ytd-player');
  2594. const cnt = insp(dummy);
  2595. const cProto = cnt.constructor.prototype;
  2596. cProto.createMainAppPlayer932_ = cProto.createMainAppPlayer_;
  2597. cProto.initPlayer932_ = cProto.initPlayer_;
  2598. const configFixBeforeCreate = () => {
  2599. try {
  2600. const config_ = typeof yt !== 'undefined' ? (yt || 0).config_ : 0;
  2601. if (config_) {
  2602. ytConfigFix(config_);
  2603. }
  2604. } catch (e) { }
  2605. }
  2606. cProto.createMainAppPlayer_ = function (a, b, c) {
  2607. configFixBeforeCreate();
  2608. let r = this.createMainAppPlayer932_(a, b, c);
  2609. try {
  2610. (async () => {
  2611. const e = await this.mainAppPlayer_.api;
  2612. setupAudioPlaying(e); // desktop normal
  2613. })();
  2614. } finally {
  2615. return r;
  2616. }
  2617. }
  2618. cProto.initPlayer_ = function (a) {
  2619. configFixBeforeCreate();
  2620. let r = this.initPlayer932_(a);
  2621. try {
  2622. (async () => {
  2623. const e = await r;
  2624. setupAudioPlaying(this.player_); // desktop normal
  2625. })();
  2626. } finally {
  2627. return r;
  2628. }
  2629. }
  2630. });
  2631.  
  2632. }
  2633.  
  2634.  
  2635. } else if (location.origin === 'https://m.youtube.com') {
  2636.  
  2637. removeBottomOverlayForMobile = async (delay) => {
  2638.  
  2639.  
  2640. let closeBtnRenderer = document.querySelector('.ytm-bottom-sheet-overlay-renderer-close.icon-close');
  2641. if (closeBtnRenderer) {
  2642.  
  2643. const btn = closeBtnRenderer.querySelector('button');
  2644. const container = closeBtnRenderer.closest('#global-loader ~ .ytm-bottom-sheet-overlay-container');
  2645.  
  2646. if (container) {
  2647. container.style.visibility = 'collapse';
  2648. container.style.zIndex = '-1';
  2649. }
  2650. if (btn) {
  2651. if (delay) {
  2652. await delayPn(delay);
  2653. }
  2654. btn.click();
  2655. }
  2656. }
  2657.  
  2658. }
  2659.  
  2660. const getAppJSON = () => {
  2661. let t;
  2662. t = document.querySelector('player-microformat-renderer.PlayerMicroformatRendererHost script[type="application/ld+json"]');
  2663. if (t) return t;
  2664. t = document.querySelector('player-microformat-renderer.playerMicroformatRendererHost script[type="application/ld+json"]');
  2665. if (t) return t;
  2666.  
  2667. return null;
  2668.  
  2669. }
  2670.  
  2671.  
  2672. let lastPlayerInfoText = '';
  2673. let mz = 0;
  2674. onVideoChangeForMobile = async () => {
  2675.  
  2676.  
  2677. let html5Container = null;
  2678.  
  2679. const moviePlayer = document.querySelector('#player .html5-video-container .video-stream.html5-main-video');
  2680. if (moviePlayer) {
  2681. html5Container = moviePlayer.closest('.html5-video-container');
  2682. }
  2683.  
  2684. console.log('STx00', html5Container)
  2685. if (!html5Container) return;
  2686. let thumbnailUrl = '';
  2687.  
  2688. if (mz > 1e9) mz = 9;
  2689. let mt = ++mz;
  2690.  
  2691. const scriptText = await observablePromise(() => {
  2692. if (mt !== mz) return 1;
  2693. const t = getAppJSON();
  2694. const tt = (t ? t.textContent : '') || '';
  2695. if (tt === lastPlayerInfoText) return;
  2696. return tt;
  2697. }).obtain();
  2698. if (typeof scriptText !== 'string') return; // 1
  2699. lastPlayerInfoText = scriptText;
  2700.  
  2701. if (!scriptText) return;
  2702.  
  2703.  
  2704. if (SHOW_VIDEO_STATIC_IMAGE) {
  2705. console.log('STx01')
  2706.  
  2707. let idx1 = scriptText.indexOf('"thumbnailUrl"');
  2708. let idx2 = idx1 >= 0 ? scriptText.lastIndexOf('"thumbnailUrl"') : -1;
  2709.  
  2710. if (idx1 === idx2 && idx1 > 0) {
  2711.  
  2712. let bk = 0;
  2713. let j = -1;
  2714. for (let i = idx1; i < scriptText.length; i++) {
  2715. if (i > idx1 + 20 && bk === 0) {
  2716. j = i;
  2717. break;
  2718. }
  2719. let t = scriptText.charAt(i);
  2720. if (t === '[') bk++;
  2721. else if (t === ']') bk--;
  2722. else if (t === '{') bk++;
  2723. else if (t === '}') bk--;
  2724. }
  2725.  
  2726.  
  2727. if (j > idx1) {
  2728.  
  2729. let thumbnailUrlString = scriptText.substring(idx1, j);
  2730. let thumbnailUrlObject = null;
  2731.  
  2732. try {
  2733. thumbnailUrlObject = JSON.parse(`{${thumbnailUrlString}}`);
  2734.  
  2735. } catch (e) { }
  2736.  
  2737. const thumbnails = thumbnailUrlObject.thumbnailUrl;
  2738.  
  2739. if (thumbnails && thumbnails.length >= 1 && typeof thumbnails[0] === 'string') {
  2740. if (thumbnails[0] && thumbnails[0].length > 3) {
  2741. thumbnailUrl = thumbnails[0];
  2742. }
  2743. }
  2744. }
  2745.  
  2746. }
  2747. console.log('STx02', thumbnailUrl);
  2748.  
  2749. if (thumbnailUrl && typeof thumbnailUrl === 'string') {
  2750. html5Container.style.setProperty('--audio-only-thumbnail-image', `url(${thumbnailUrl})`);
  2751. } else {
  2752. html5Container.style.removeProperty('--audio-only-thumbnail-image')
  2753. }
  2754.  
  2755. }
  2756.  
  2757.  
  2758. if (removeBottomOverlayForMobile) await removeBottomOverlayForMobile(40);
  2759.  
  2760. await delayPn(80);
  2761. const audio = moviePlayer;
  2762. if (audio && audio.muted === true && audio.isConnected === true && audio.readyState >= 0 && audio.networkState >= 2 && audio.paused === false) {
  2763. await audio.click();
  2764. }
  2765.  
  2766. }
  2767.  
  2768. let player0 = null;
  2769. const mff = function (e) {
  2770. const target = (e || 0).target || 0;
  2771. if (target !== player0 && target && typeof target.getPlayerState === 'function') {
  2772. player0 = target;
  2773. setupAudioPlaying(target); // mobile
  2774. }
  2775. }
  2776.  
  2777. document.addEventListener('player-initialized', mff, true);
  2778. document.addEventListener('player-state-change', mff, true);
  2779. document.addEventListener('player-ad-state-change', mff, true);
  2780. document.addEventListener('player-detailed-error', mff, true);
  2781. document.addEventListener('player-error', mff, true);
  2782. document.addEventListener('on-play-autonav-video', mff, true);
  2783. document.addEventListener('on-play-previous-autonav-video', mff, true);
  2784. document.addEventListener('player-fullscreen-change', mff, true);
  2785. document.addEventListener('player-fullscreen-toggled', mff, true);
  2786. document.addEventListener('player-dom-paused', mff, true);
  2787. document.addEventListener('yt-show-toast', mff, true);
  2788. document.addEventListener('yt-innertube-command', mff, true);
  2789. document.addEventListener('yt-update-c3-companion', mff, true);
  2790. document.addEventListener('video-data-change', mff, true);
  2791. document.addEventListener('video-progress', mff, true);
  2792. document.addEventListener('local-media-change', mff, true);
  2793.  
  2794.  
  2795.  
  2796. document.addEventListener('video-progress', updateLastActiveTimeAsync, true); // mobile
  2797.  
  2798.  
  2799.  
  2800. // document.addEventListener('DOMContentLoaded', (evt) => {
  2801. // const mo = new MutationObserver((mutations)=>{
  2802. // console.log(5899, mutations)
  2803. // });
  2804. // mo.observe(document, {subtree: true, childList: true})
  2805. // })
  2806.  
  2807. // window.addEventListener('onReady', (evt) => {
  2808. // console.log(6811)
  2809. // }, true);
  2810.  
  2811. // window.addEventListener('localmediachange', (evt) => {
  2812. // console.log(6812)
  2813. // }, true);
  2814.  
  2815. // window.addEventListener('onVideoDataChange', (evt) => {
  2816. // console.log(6813)
  2817. // }, true);
  2818.  
  2819. window.addEventListener('state-navigateend', async (evt) => {
  2820.  
  2821. delayPn(200).then(() => {
  2822. if (!getAppJSON()) {
  2823. console.log('[mobile youtube audio only] getAppJSON fails.', document.querySelectorAll('script[type="application/ld+json"]').length);
  2824. }
  2825. });
  2826.  
  2827. const config_ = typeof yt !== 'undefined' ? (yt || 0).config_ : 0;
  2828. ytConfigFix(config_);
  2829.  
  2830. try {
  2831. if (clickLockFn && clickTarget) {
  2832.  
  2833. let a = HTMLElement.prototype.querySelector.call(clickTarget, '.video-stream.html5-main-video');
  2834. if (!a) return;
  2835.  
  2836. if (a.muted === true && a.__spfgs__ !== true && a.paused === true && a.networkState === 0 && a.readyState === 0) {
  2837.  
  2838. const pr = new Promise(resolve => {
  2839.  
  2840. document.addEventListener('player-state-change', resolve, { once: true, passive: true, capture: false });
  2841.  
  2842. }).then();
  2843.  
  2844. clickLockFn.call(clickTarget, mockEvent({ type: 'click', target: clickTarget, detail: 1 }));
  2845. await delayPn(1);
  2846.  
  2847. if (a.muted === false && a.__spfgs__ !== true && a.paused === true && a.networkState === 0 && a.readyState === 0) {
  2848. clickLockFn.call(clickTarget, mockEvent({ type: 'click', target: clickTarget, detail: 1 }));
  2849. await delayPn(1);
  2850. }
  2851.  
  2852. delayRun(pr);
  2853.  
  2854. }
  2855.  
  2856. }
  2857.  
  2858. } catch (e) { console.log('error_F12', e) }
  2859.  
  2860.  
  2861. }, false);
  2862.  
  2863.  
  2864.  
  2865. // document.addEventListener('volumechange', (evt) => {
  2866. // console.log('volumechange')
  2867. // }, true)
  2868. // document.addEventListener('play', (evt) => {
  2869. // console.log('play')
  2870. // }, true)
  2871.  
  2872.  
  2873. // document.addEventListener('player-initialized', (evt) => {
  2874. // console.log(evt.type)
  2875. // }, true)
  2876. // document.addEventListener('renderer-module-load-start', (evt) => {
  2877. // console.log(evt.type)
  2878. // }, true)
  2879. // document.addEventListener('video-data-change', (evt) => {
  2880. // console.log(evt.type)
  2881. // }, true)
  2882. // document.addEventListener('player-state-change', (evt) => {
  2883. // console.log(evt.type)
  2884. // }, true)
  2885. // document.addEventListener('updateui', (evt) => {
  2886. // console.log(evt.type)
  2887. // }, true)
  2888. // document.addEventListener('renderer-module-load-end', (evt) => {
  2889. // console.log(evt.type)
  2890. // }, true)
  2891.  
  2892. // document.addEventListener('player-autonav-pause', (evt) => {
  2893. // console.log(evt.type)
  2894. // }, true)
  2895.  
  2896.  
  2897.  
  2898. // document.addEventListener('player-ad-state-change', (evt) => {
  2899. // console.log(evt.type)
  2900. // }, true)
  2901.  
  2902. // document.addEventListener('player-detailed-error', (evt) => {
  2903. // console.log(evt.type)
  2904. // }, true)
  2905.  
  2906. // document.addEventListener('player-error', (evt) => {
  2907. // console.log(evt.type)
  2908. // }, true)
  2909.  
  2910. // document.addEventListener('on-play-autonav-video', (evt) => {
  2911. // console.log(evt.type)
  2912. // }, true)
  2913.  
  2914. // document.addEventListener('on-play-previous-autonav-video', (evt) => {
  2915. // console.log(evt.type)
  2916. // }, true)
  2917.  
  2918. // document.addEventListener('player-fullscreen-change', (evt) => {
  2919. // console.log(evt.type)
  2920. // }, true)
  2921.  
  2922. // document.addEventListener('player-fullscreen-toggled', (evt) => {
  2923. // console.log(evt.type)
  2924. // }, true)
  2925.  
  2926. // document.addEventListener('player-dom-paused', (evt) => {
  2927. // console.log(evt.type)
  2928. // }, true)
  2929.  
  2930. // document.addEventListener('yt-show-toast', (evt) => {
  2931. // console.log(evt.type)
  2932. // }, true)
  2933. // document.addEventListener('yt-innertube-command', (evt) => {
  2934. // console.log(evt.type)
  2935. // }, true)
  2936. // document.addEventListener('yt-update-c3-companion', (evt) => {
  2937. // console.log(evt.type)
  2938. // }, true)
  2939. // document.addEventListener('video-progress', (evt) => {
  2940. // // console.log(evt.type)
  2941. // }, true)
  2942. // document.addEventListener('localmediachange', (evt) => {
  2943. // console.log(evt.type)
  2944. // }, true)
  2945.  
  2946.  
  2947.  
  2948. // window.addEventListener('player-initialized', (evt) => {
  2949. // console.log(evt.type)
  2950. // }, true)
  2951. // window.addEventListener('renderer-module-load-start', (evt) => {
  2952. // console.log(evt.type)
  2953. // }, true)
  2954. // window.addEventListener('video-data-change', (evt) => {
  2955. // console.log(evt.type)
  2956. // }, true)
  2957. // window.addEventListener('player-state-change', (evt) => {
  2958. // console.log(evt.type)
  2959. // }, true)
  2960. // window.addEventListener('updateui', (evt) => {
  2961. // console.log(evt.type)
  2962. // }, true)
  2963. // window.addEventListener('renderer-module-load-end', (evt) => {
  2964. // console.log(evt.type)
  2965. // }, true)
  2966.  
  2967. // window.addEventListener('player-autonav-pause', (evt) => {
  2968. // console.log(evt.type)
  2969. // }, true)
  2970.  
  2971.  
  2972.  
  2973. // window.addEventListener('player-ad-state-change', (evt) => {
  2974. // console.log(evt.type)
  2975. // }, true)
  2976.  
  2977. // window.addEventListener('player-detailed-error', (evt) => {
  2978. // console.log(evt.type)
  2979. // }, true)
  2980.  
  2981. // window.addEventListener('player-error', (evt) => {
  2982. // console.log(evt.type)
  2983. // }, true)
  2984.  
  2985. // window.addEventListener('on-play-autonav-video', (evt) => {
  2986. // console.log(evt.type)
  2987. // }, true)
  2988.  
  2989. // window.addEventListener('on-play-previous-autonav-video', (evt) => {
  2990. // console.log(evt.type)
  2991. // }, true)
  2992.  
  2993. // window.addEventListener('player-fullscreen-change', (evt) => {
  2994. // console.log(evt.type)
  2995. // }, true)
  2996.  
  2997. // window.addEventListener('player-fullscreen-toggled', (evt) => {
  2998. // console.log(evt.type)
  2999. // }, true)
  3000.  
  3001. // window.addEventListener('player-dom-paused', (evt) => {
  3002. // console.log(evt.type)
  3003. // }, true)
  3004.  
  3005. // window.addEventListener('yt-show-toast', (evt) => {
  3006. // console.log(evt.type)
  3007. // }, true)
  3008. // window.addEventListener('yt-innertube-command', (evt) => {
  3009. // console.log(evt.type)
  3010. // }, true)
  3011. // window.addEventListener('yt-update-c3-companion', (evt) => {
  3012. // console.log(evt.type)
  3013. // }, true)
  3014. // window.addEventListener('video-progress', (evt) => {
  3015. // // console.log(evt.type)
  3016. // }, true)
  3017. // window.addEventListener('localmediachange', (evt) => {
  3018. // console.log(evt.type)
  3019. // }, true)
  3020.  
  3021.  
  3022.  
  3023. // document.addEventListener('player-error', (evt) => {
  3024. // console.log(3001, evt.type, evt)
  3025. // }, true)
  3026. // document.addEventListener('player-detailed-error', (evt) => {
  3027. // console.log(3002, evt.type, evt)
  3028. // }, true)
  3029.  
  3030.  
  3031.  
  3032. async function delayRun(pr) {
  3033.  
  3034. let q = document.querySelector('#movie_player');
  3035. if (!q) return;
  3036. let a = document.querySelector('.video-stream.html5-main-video');
  3037. if (!a) return;
  3038.  
  3039. await pr.then();
  3040.  
  3041. if (fa !== 1) {
  3042. return;
  3043. } else if (a.muted === true) {
  3044. return;
  3045. } else if (a.muted === false && a.readyState === 0 && a.networkState === 2) {
  3046. if (a.paused === false) return;
  3047. } else {
  3048. return;
  3049. }
  3050.  
  3051. if (document.querySelector('.player-controls-content')) return;
  3052.  
  3053. if (a.paused === true && a.muted === false && a.readyState === 0 && a.networkState === 2) {
  3054.  
  3055. clickLockFn.call(clickTarget, mockEvent({ type: 'click', target: clickTarget, detail: 1 }));
  3056.  
  3057. }
  3058.  
  3059. if (a.paused === true && a.muted === false && a.networkState === 2 && a.readyState === 0) {
  3060.  
  3061. if (typeof clickTarget.seekToLiveHead === 'function') await clickTarget.seekToLiveHead();
  3062. if (typeof clickTarget.isAtLiveHead === 'function' && (await clickTarget.isAtLiveHead()) === true) {
  3063. if (typeof clickTarget.seekToStreamTime === 'function') await clickTarget.seekToStreamTime();
  3064. }
  3065. }
  3066.  
  3067. }
  3068.  
  3069. durationchangeForMobile = true;
  3070.  
  3071. }
  3072.  
  3073.  
  3074. attachOneTimeEvent('yt-action', function () {
  3075. const config_ = typeof yt !== 'undefined' ? (yt || 0).config_ : 0;
  3076. ytConfigFix(config_);
  3077. });
  3078.  
  3079. let prepared = false;
  3080. function prepare() {
  3081. if (prepared) return;
  3082. prepared = true;
  3083.  
  3084. if (typeof _yt_player !== 'undefined' && _yt_player && typeof _yt_player === 'object') {
  3085.  
  3086. for (const [k, v] of Object.entries(_yt_player)) {
  3087.  
  3088. const p = typeof v === 'function' ? v.prototype : 0;
  3089.  
  3090. if (p
  3091. && typeof p.clone === 'function'
  3092. && typeof p.get === 'function' && typeof p.set === 'function'
  3093. && typeof p.isEmpty === 'undefined' && typeof p.forEach === 'undefined'
  3094. && typeof p.clear === 'undefined'
  3095. ) {
  3096.  
  3097. key = k;
  3098.  
  3099. }
  3100.  
  3101. }
  3102.  
  3103. }
  3104.  
  3105. if (key) {
  3106.  
  3107. const ClassX = _yt_player[key];
  3108. _yt_player[key] = class extends ClassX {
  3109. constructor(...args) {
  3110.  
  3111. if (typeof args[0] === 'string' && args[0].startsWith('http://')) args[0] = '';
  3112. super(...args);
  3113.  
  3114. }
  3115. }
  3116. _yt_player[key].luX1Y = 1;
  3117. prototypeInherit(_yt_player[key].prototype, ClassX.prototype);
  3118. }
  3119.  
  3120. }
  3121. let s3 = Symbol();
  3122.  
  3123. generalRegister('deviceIsAudioOnly', s3, (p) => {
  3124. return typeof p.getPlayerType === 'function' && typeof p.getVideoEmbedCode === 'function' && typeof p.getVideoUrl === 'function' && !p.onCueRangeEnter && !p.getVideoData && !('ATTRIBUTE_NODE' in p)
  3125. }, {
  3126.  
  3127. get() {
  3128. return this[s3];
  3129. },
  3130. set(nv) {
  3131. if (typeof nv === 'boolean') this[s3] = true;
  3132. else this[s3] = undefined;
  3133. prepare();
  3134. return true;
  3135. },
  3136. enumerable: false,
  3137. configurable: true
  3138.  
  3139. });
  3140.  
  3141.  
  3142. let s1 = Symbol();
  3143. let s2 = Symbol();
  3144. Object.defineProperty(Object.prototype, 'defraggedFromSubfragments', {
  3145. get() {
  3146. // console.log(501, this.constructor.prototype)
  3147. return undefined;
  3148. },
  3149. set(nv) {
  3150. return true;
  3151. },
  3152. enumerable: false,
  3153. configurable: true
  3154. });
  3155.  
  3156. Object.defineProperty(Object.prototype, 'hasSubfragmentedFmp4', {
  3157. get() {
  3158. // console.log(502, this.constructor.prototype)
  3159. return this[s1];
  3160. },
  3161. set(nv) {
  3162. if (typeof nv === 'boolean') this[s1] = false;
  3163. else this[s1] = undefined;
  3164. return true;
  3165. },
  3166. enumerable: false,
  3167. configurable: true
  3168. });
  3169.  
  3170. Object.defineProperty(Object.prototype, 'hasSubfragmentedWebm', {
  3171. get() {
  3172. // console.log(503, this.constructor.prototype)
  3173. return this[s2];
  3174. },
  3175. set(nv) {
  3176. if (typeof nv === 'boolean') this[s2] = false;
  3177. else this[s2] = undefined;
  3178. return true;
  3179. },
  3180. enumerable: false,
  3181. configurable: true
  3182. });
  3183.  
  3184.  
  3185. const supportedFormatsConfig = () => {
  3186.  
  3187. function typeTest(type) {
  3188. if (typeof type === 'string' && type.startsWith('video/')) {
  3189. return false;
  3190. }
  3191. }
  3192.  
  3193. // return a custom MIME type checker that can defer to the original function
  3194. function makeModifiedTypeChecker(origChecker) {
  3195. // Check if a video type is allowed
  3196. return function (type) {
  3197. let res = undefined;
  3198. if (type === undefined) res = false;
  3199. else {
  3200. res = typeTest.call(this, type);
  3201. }
  3202. if (res === undefined) res = origChecker.apply(this, arguments);
  3203. return res;
  3204. };
  3205. }
  3206.  
  3207. // Override video element canPlayType() function
  3208. const proto = (HTMLVideoElement || 0).prototype;
  3209. if (proto && typeof proto.canPlayType == 'function') {
  3210. proto.canPlayType = makeModifiedTypeChecker(proto.canPlayType);
  3211. }
  3212.  
  3213. // Override media source extension isTypeSupported() function
  3214. const mse = window.MediaSource;
  3215. // Check for MSE support before use
  3216. if (mse && typeof mse.isTypeSupported == 'function') {
  3217. mse.isTypeSupported = makeModifiedTypeChecker(mse.isTypeSupported);
  3218. }
  3219.  
  3220. };
  3221.  
  3222. supportedFormatsConfig();
  3223.  
  3224.  
  3225. ; (async () => {
  3226.  
  3227.  
  3228. const _yt_player_observable = observablePromise(() => {
  3229. return (((window || 0)._yt_player || 0) || 0);
  3230. });
  3231.  
  3232.  
  3233. const addProtoToArr = (parent, key, arr) => {
  3234.  
  3235.  
  3236. let isChildProto = false;
  3237. for (const sr of arr) {
  3238. if (parent[key].prototype instanceof parent[sr]) {
  3239. isChildProto = true;
  3240. break;
  3241. }
  3242. }
  3243.  
  3244. if (isChildProto) return;
  3245.  
  3246. arr = arr.filter(sr => {
  3247. if (parent[sr].prototype instanceof parent[key]) {
  3248. return false;
  3249. }
  3250. return true;
  3251. });
  3252.  
  3253. arr.push(key);
  3254.  
  3255. return arr;
  3256.  
  3257.  
  3258. };
  3259.  
  3260. const getEntriesForPlayerInterfaces = (_yt_player) => {
  3261.  
  3262. const entries = Object.entries(_yt_player);
  3263.  
  3264. const arr = new Array(entries.length);
  3265. let arrI = 0;
  3266.  
  3267. for (const entry of entries) {
  3268. const [k, v] = entry;
  3269.  
  3270. const p = typeof v === 'function' ? v.prototype : 0;
  3271. if (p) {
  3272.  
  3273. const b = (
  3274. typeof p.cancelPlayback === 'function' ||
  3275. typeof p.stopVideo === 'function' ||
  3276. typeof p.pauseVideo === 'function' ||
  3277. typeof p.playVideo === 'function' ||
  3278. typeof p.getPlayerStateObject === 'function'
  3279. );
  3280. if (b) arr[arrI++] = entry;
  3281. }
  3282. }
  3283.  
  3284. arr.length = arrI;
  3285. return arr;
  3286.  
  3287.  
  3288. }
  3289.  
  3290.  
  3291. const getKeyPlayerDap = (_yt_player, filteredEntries) => {
  3292. // one is quu (this.app.getPlayerStateObject(p))
  3293. // one is standardApp (return this.getPresentingPlayerType()===3?R$(this.C7).g7:g.O5(this,p).getPlayerState())
  3294.  
  3295.  
  3296. const w = 'keyPlayerDap';
  3297.  
  3298. let arr = [];
  3299. let brr = new Map();
  3300.  
  3301. for (const [k, v] of filteredEntries) {
  3302.  
  3303. const p = typeof v === 'function' ? v.prototype : 0;
  3304. if (p) {
  3305.  
  3306. let q = 0;
  3307.  
  3308. if (typeof p.cancelPlayback === 'function') q += 50;
  3309. if (typeof p.stopVideo === 'function') q += 50;
  3310. if (typeof p.pauseVideo === 'function') q += 50;
  3311. if (typeof p.playVideo === 'function') q += 50;
  3312. if (typeof p.getPlayerStateObject === 'function') q += 50;
  3313.  
  3314. if (q < 250) continue;
  3315.  
  3316. if (typeof p.cancelPlayback === 'function' && p.cancelPlayback.length === 0) q += 20;
  3317. if (typeof p.stopVideo === 'function' && p.stopVideo.length === 1) q += 20;
  3318. if (typeof p.pauseVideo === 'function' && p.pauseVideo.length === 1) q += 20;
  3319. if (typeof p.playVideo === 'function' && p.playVideo.length === 2) q += 20;
  3320. if (typeof p.getPlayerStateObject === 'function' && p.getPlayerStateObject.length === 1) q += 20;
  3321.  
  3322.  
  3323. if (typeof p.isBackground === 'function') q -= 5;
  3324. if (typeof p.isBackground === 'function' && p.isBackground.length === 0) q -= 2;
  3325.  
  3326. if (typeof p.getPlaybackRate === 'function') q += 25;
  3327. if (typeof p.getPlaybackRate === 'function' && p.getPlaybackRate.length === 0) q += 15;
  3328.  
  3329. if (typeof p.publish === 'function') q += 25;
  3330. if (typeof p.publish === 'function' && p.publish.length === 1) q += 15;
  3331.  
  3332. if (typeof p.addEventListener === 'function') q += 40;
  3333. if (typeof p.addEventListener === 'function' && p.addEventListener.length === 2) q += 25;
  3334. if (typeof p.removeEventListener === 'function') q += 40;
  3335. if (typeof p.removeEventListener === 'function' && p.removeEventListener.length === 2) q += 25;
  3336.  
  3337. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  3338.  
  3339. if (q > 0) brr.set(k, q);
  3340.  
  3341. }
  3342.  
  3343.  
  3344. }
  3345.  
  3346. if (arr.length === 0) {
  3347.  
  3348. console.warn(`[yt-audio-only] (key-extraction) Key does not exist (1). [${w}]`);
  3349. } else {
  3350.  
  3351. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  3352.  
  3353. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  3354.  
  3355. let match = null;
  3356. for (const [key, _] of arr) {
  3357. const p = _yt_player[key].prototype
  3358. const f = (p ? p.getPlayerStateObject : null) || 0;
  3359. if (f) {
  3360. const o = {};
  3361. const w = new Proxy({}, {
  3362. get(target, p) {
  3363. o[p] = 1;
  3364. return w;
  3365. },
  3366. set(target, p, v) {
  3367. return true;
  3368. }
  3369. });
  3370. try {
  3371. f.call(w)
  3372. } catch (e) { }
  3373. if (o.app) {
  3374. match = key;
  3375. }
  3376. }
  3377. }
  3378.  
  3379.  
  3380. if (!match) {
  3381.  
  3382. console.warn(`[yt-audio-only] (key-extraction) Key does not exist (2). [${w}]`);
  3383.  
  3384. } else {
  3385. return match;
  3386. }
  3387.  
  3388. }
  3389.  
  3390.  
  3391.  
  3392. }
  3393.  
  3394. const getKeyStandardApp = (_yt_player, filteredEntries) => {
  3395. // one is quu (this.app.getPlayerStateObject(p))
  3396. // one is standardApp (return this.getPresentingPlayerType()===3?R$(this.C7).g7:g.O5(this,p).getPlayerState())
  3397.  
  3398.  
  3399. const w = 'keyStandardApp';
  3400.  
  3401. let arr = [];
  3402. let brr = new Map();
  3403.  
  3404. for (const [k, v] of filteredEntries) {
  3405.  
  3406. const p = typeof v === 'function' ? v.prototype : 0;
  3407. if (p) {
  3408.  
  3409. let q = 0;
  3410.  
  3411. if (typeof p.cancelPlayback === 'function') q += 50;
  3412. if (typeof p.stopVideo === 'function') q += 50;
  3413. if (typeof p.pauseVideo === 'function') q += 50;
  3414. if (typeof p.playVideo === 'function') q += 50;
  3415. if (typeof p.getPlayerStateObject === 'function') q += 50;
  3416.  
  3417. if (q < 250) continue;
  3418.  
  3419. if (typeof p.cancelPlayback === 'function' && p.cancelPlayback.length === 2) q += 20;
  3420. if (typeof p.stopVideo === 'function' && p.stopVideo.length === 1) q += 20;
  3421. if (typeof p.pauseVideo === 'function' && p.pauseVideo.length === 2) q += 20;
  3422. if (typeof p.playVideo === 'function' && p.playVideo.length === 2) q += 20;
  3423. if (typeof p.getPlayerStateObject === 'function' && p.getPlayerStateObject.length === 1) q += 20;
  3424.  
  3425.  
  3426. if (typeof p.isBackground === 'function') q -= 5;
  3427. if (typeof p.isBackground === 'function' && p.isBackground.length === 0) q -= 2;
  3428.  
  3429. if (typeof p.getPlaybackRate === 'function') q -= 5;
  3430. if (typeof p.getPlaybackRate === 'function' && p.getPlaybackRate.length === 0) q -= 2;
  3431.  
  3432. if (typeof p.publish === 'function') q -= 5;
  3433. if (typeof p.publish === 'function' && p.publish.length === 2) q -= 2;
  3434.  
  3435. if (typeof p.addEventListener === 'function') q -= 5;
  3436. if (typeof p.addEventListener === 'function' && p.addEventListener.length === 2) q -= 2;
  3437. if (typeof p.removeEventListener === 'function') q -= 5;
  3438. if (typeof p.removeEventListener === 'function' && p.removeEventListener.length === 2) q -= 2;
  3439.  
  3440.  
  3441. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  3442.  
  3443. if (q > 0) brr.set(k, q);
  3444.  
  3445. }
  3446.  
  3447.  
  3448. }
  3449.  
  3450. if (arr.length === 0) {
  3451.  
  3452. console.warn(`[yt-audio-only] (key-extraction) Key does not exist (1). [${w}]`);
  3453. } else {
  3454.  
  3455. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  3456.  
  3457. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  3458.  
  3459. let match = null;
  3460. for (const [key, _] of arr) {
  3461. const p = _yt_player[key].prototype
  3462. const f = (p ? p.getPlayerStateObject : null) || 0;
  3463. if (f) {
  3464. const o = {};
  3465. const w = new Proxy({}, {
  3466. get(target, p) {
  3467. o[p] = 1;
  3468. return w;
  3469. },
  3470. set(target, p, v) {
  3471. return true;
  3472. }
  3473. });
  3474. try {
  3475. f.call(w)
  3476. } catch (e) { }
  3477. if (!o.app) {
  3478. match = key;
  3479. }
  3480. }
  3481. }
  3482.  
  3483.  
  3484. if (!match) {
  3485.  
  3486. console.warn(`[yt-audio-only] (key-extraction) Key does not exist (2). [${w}]`);
  3487.  
  3488. } else {
  3489. return match;
  3490. }
  3491.  
  3492. }
  3493.  
  3494.  
  3495.  
  3496. }
  3497.  
  3498.  
  3499. const getKeyInternalApp = (_yt_player, filteredEntries) => {
  3500. // internalApp
  3501.  
  3502. const w = 'keyInternalApp';
  3503.  
  3504. let arr = [];
  3505. let brr = new Map();
  3506.  
  3507. for (const [k, v] of filteredEntries) {
  3508.  
  3509. const p = typeof v === 'function' ? v.prototype : 0;
  3510. if (p) {
  3511.  
  3512. let q = 0;
  3513.  
  3514. if (typeof p.stopVideo === 'function') q += 1;
  3515. if (typeof p.playVideo === 'function') q += 1;
  3516. if (typeof p.pauseVideo === 'function') q += 1;
  3517.  
  3518. if (q < 2) continue;
  3519.  
  3520. if (typeof p.isBackground === 'function') q += 120;
  3521. if (typeof p.getPlaybackRate === 'function') q += 50;
  3522. // if (typeof p.publish === 'function') q += 50;
  3523. if (typeof p.isAtLiveHead === 'function') q += 50;
  3524. if (typeof p.getVideoData === 'function') q += 10;
  3525. if (typeof p.getVolume === 'function') q += 10;
  3526. if (typeof p.getStreamTimeOffset === 'function') q += 10;
  3527. if (typeof p.getPlayerType === 'function') q += 10;
  3528. if (typeof p.getPlayerState === 'function') q += 10;
  3529. if (typeof p.getPlayerSize === 'function') q += 10;
  3530. if (typeof p.cancelPlayback === 'function') q -= 4;
  3531.  
  3532. if (q < 10) continue;
  3533.  
  3534. if ('mediaElement' in p) q += 50;
  3535. if ('videoData' in p) q += 50;
  3536. if ('visibility' in p) q += 50;
  3537.  
  3538. if (typeof p.isBackground === 'function' && p.isBackground.length === 0) q += 20;
  3539. if (typeof p.getPlaybackRate === 'function' && p.getPlaybackRate.length === 0) q += 20;
  3540. if (typeof p.publish === 'function' && p.publish.length === 2) q += 18;
  3541. if (typeof p.isAtLiveHead === 'function' && p.isAtLiveHead.length === 2) q += 18;
  3542.  
  3543. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  3544.  
  3545. if (q > 0) brr.set(k, q);
  3546.  
  3547. }
  3548.  
  3549.  
  3550. }
  3551.  
  3552. if (arr.length === 0) {
  3553.  
  3554. console.warn(`[yt-audio-only] (key-extraction) Key does not exist. [${w}]`);
  3555. } else {
  3556.  
  3557. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  3558.  
  3559. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  3560.  
  3561. if (arr.length > 2) console.log(`[yt-audio-only] (key-extraction) [${w}]`, arr);
  3562. return arr[0][0];
  3563. }
  3564.  
  3565.  
  3566.  
  3567. };
  3568.  
  3569.  
  3570. (async () => {
  3571. // rAf scheduling
  3572.  
  3573. const _yt_player = await _yt_player_observable.obtain();
  3574.  
  3575. if (!_yt_player || typeof _yt_player !== 'object') return;
  3576.  
  3577. window.ktg = _yt_player;
  3578.  
  3579. // console.log(keys0)
  3580.  
  3581. const entriesForPlayerInterfaces = getEntriesForPlayerInterfaces(_yt_player);
  3582.  
  3583. const keyPlayerDap = getKeyPlayerDap(_yt_player, entriesForPlayerInterfaces)
  3584. const keyStandardApp = getKeyStandardApp(_yt_player, entriesForPlayerInterfaces)
  3585. const keyInternalApp = getKeyInternalApp(_yt_player, entriesForPlayerInterfaces);
  3586.  
  3587. console.log('[yt-audio-only] key obtained', [keyPlayerDap, keyStandardApp, keyInternalApp]);
  3588.  
  3589. if (!keyPlayerDap || !keyStandardApp || !keyInternalApp) {
  3590. console.warn('[yt-audio-only] key failure', [keyPlayerDap, keyStandardApp, keyInternalApp]);
  3591. }
  3592.  
  3593.  
  3594. if (keyPlayerDap) {
  3595. const playerDapCT = _yt_player[keyPlayerDap];
  3596. if (typeof playerDapCT === 'function') {
  3597. const playerDapPT = playerDapCT.prototype;
  3598. playerDapPTFn(playerDapPT);
  3599. }
  3600. }
  3601.  
  3602.  
  3603. if (keyStandardApp) {
  3604. const standardAppCT = _yt_player[keyStandardApp];
  3605. if (typeof standardAppCT === 'function') {
  3606. const standardAppPT = standardAppCT.prototype;
  3607. standardAppPTFn(standardAppPT);
  3608. }
  3609. }
  3610.  
  3611. if (keyInternalApp) {
  3612. const internalAppCT = _yt_player[keyInternalApp];
  3613. if (typeof internalAppCT === 'function') {
  3614. const internalAppPT = internalAppCT.prototype;
  3615. internalAppPTFn(internalAppPT);
  3616. }
  3617. }
  3618.  
  3619.  
  3620.  
  3621. })();
  3622.  
  3623. })();
  3624.  
  3625.  
  3626. //# sourceURL=debug://userscript/yt-audio-only.js
  3627.  
  3628.  
  3629. }
  3630.  
  3631. const getVideoIdByURL = () => {
  3632. // It's almost certainly going to stay at 11 characters. The individual characters come from a set of 64 possibilities (A-Za-z0-9_-).
  3633. // base64 form; 26+26+10+2; 64^len
  3634. // Math.pow(64,11) = 73786976294838210000
  3635.  
  3636. const url = new URL(location.href);
  3637. let m;
  3638.  
  3639. if (m = /^\/watch\?v=([A-Za-z0-9_-]+)/.exec(`${url.pathname}?v=${url.searchParams.get('v')}`)) return `${m[1]}`;
  3640. if (m = /^\/live\/([A-Za-z0-9_-]+)/.exec(url.pathname)) return `${m[1]}`;
  3641.  
  3642. if (m = /^\/embed\/live_stream\?channel=([A-Za-z0-9_-]+)/.exec(`${url.pathname}?channel=${url.searchParams.get('channel')}`)) return `L:${m[1]}`;
  3643. if (m = /^\/embed\/([A-Za-z0-9_-]+)/.exec(url.pathname)) return `${m[1]}`;
  3644.  
  3645. if (m = /^\/channel\/([A-Za-z0-9_-]+)\/live\b/.exec(url.pathname)) return `L:${m[1]}`;
  3646. if (url.hostname === 'youtu.be' && (m = /\/([A-Za-z0-9_-]+)/.exec(url.pathname))) return `${m[1]}`;
  3647.  
  3648. return '';
  3649.  
  3650. };
  3651.  
  3652. const getVideoIdByElement = () => {
  3653. const videoIdElements = [...document.querySelectorAll('[video-id]')].filter(v => !v.closest('[hidden]'));
  3654. const videoId = videoIdElements.length > 0 ? videoIdElements[0].getAttribute('video-id') : null;
  3655. return videoId || '';
  3656. };
  3657.  
  3658. const getEnableValue = async () => {
  3659. const videoId = getVideoIdByURL() || getVideoIdByElement();
  3660. const siteVal = videoId ? await GM.getValue(`isEnable_aWsjF_${videoId}`, null) : null;
  3661. return (siteVal !== null) ? siteVal : await GM.getValue("isEnable_aWsjF", true);
  3662. };
  3663.  
  3664. const setEnableVal = async (val) => {
  3665. const videoId = getVideoIdByURL() || getVideoIdByElement();
  3666. if (videoId) {
  3667. try {
  3668. const cv = await GM.getValue(`isEnable_aWsjF_${videoId}`, null);
  3669. if (typeof cv === typeof val) await GM.setValue(`isEnable_aWsjF_${videoId}`, val);
  3670. } catch (e) { }
  3671. }
  3672. await GM.setValue("isEnable_aWsjF", val);
  3673. }
  3674.  
  3675. const isEnable = (typeof GM !== 'undefined' && typeof GM.getValue === 'function') ? await getEnableValue() : null;
  3676. if (typeof isEnable !== 'boolean') throw new DOMException("Please Update your browser", "NotSupportedError");
  3677. if (isEnable) {
  3678. const element = document.createElement('button');
  3679. element.setAttribute('onclick', createHTML(`(${pageInjectionCode})()`));
  3680. element.click();
  3681. }
  3682.  
  3683. GM_registerMenuCommand(`Turn ${isEnable ? 'OFF' : 'ON'} YouTube Audio Mode`, async function () {
  3684. await setEnableVal(!isEnable);
  3685. await GM.setValue('lastCheck_bWsm5', Date.now());
  3686. document.documentElement.setAttribute('forceRefresh032', '');
  3687. location.reload();
  3688. });
  3689.  
  3690. let messageCount = 0;
  3691. let busy = false;
  3692. window.addEventListener('message', (evt) => {
  3693.  
  3694. const v = ((evt || 0).data || 0).ZECxh;
  3695. if (typeof v === 'boolean') {
  3696. if (messageCount > 1e9) messageCount = 9;
  3697. const t = ++messageCount;
  3698. if (v && isEnable) {
  3699. requestAnimationFrame(async () => {
  3700. if (t !== messageCount) return;
  3701. if (busy) return;
  3702. busy = true;
  3703. if (await confirm("Livestream is detected. Press OK to disable YouTube Audio Mode.")) {
  3704. await setEnableVal(!isEnable);
  3705. await GM.setValue('lastCheck_bWsm5', Date.now());
  3706. document.documentElement.setAttribute('forceRefresh032', '');
  3707. location.reload();
  3708. }
  3709. busy = false;
  3710. });
  3711. }
  3712. }
  3713.  
  3714. });
  3715.  
  3716.  
  3717. const pLoad = new Promise(resolve => {
  3718. if (document.readyState !== 'loading') {
  3719. resolve();
  3720. } else {
  3721. window.addEventListener("DOMContentLoaded", resolve, false);
  3722. }
  3723. });
  3724.  
  3725.  
  3726. function contextmenuInfoItemAppearedFn(target) {
  3727.  
  3728. const btn = target.closest('.ytp-menuitem[role="menuitem"]');
  3729. if (!btn) return;
  3730. if (btn.parentNode.querySelector('.ytp-menuitem[role="menuitem"].audio-only-toggle-btn')) return;
  3731. document.documentElement.classList.add('with-audio-only-toggle-btn');
  3732. const newBtn = btn.cloneNode(true)
  3733. newBtn.querySelector('.ytp-menuitem-label').textContent = `Turn ${isEnable ? 'OFF' : 'ON'} YouTube Audio Mode`;
  3734. newBtn.classList.add('audio-only-toggle-btn');
  3735. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  3736. newBtn.addEventListener('click', async (evt) => {
  3737. try {
  3738. evt.stopPropagation();
  3739. evt.stopImmediatePropagation();
  3740. } catch (e) { }
  3741. await setEnableVal(!isEnable);
  3742. await GM.setValue('lastCheck_bWsm5', Date.now());
  3743. document.documentElement.setAttribute('forceRefresh032', '');
  3744. location.reload();
  3745. });
  3746. let t;
  3747. let h = 0;
  3748. t = btn.closest('.ytp-panel-menu[style*="height"]');
  3749. if (t) t.style.height = t.scrollHeight + 'px';
  3750. t = btn.closest('.ytp-panel[style*="height"]');
  3751. if (t) t.style.height = (h = t.scrollHeight) + 'px';
  3752. t = btn.closest('.ytp-popup.ytp-contextmenu[style*="height"]');
  3753. if (t && h > 0) t.style.height = h + 'px';
  3754. }
  3755.  
  3756.  
  3757. function mobileMenuItemAppearedFn(target) {
  3758.  
  3759. const btn = target.closest('ytm-menu-item');
  3760. if (!btn) return;
  3761. if (btn.parentNode.querySelector('ytm-menu-item.audio-only-toggle-btn')) return;
  3762. document.documentElement.classList.add('with-audio-only-toggle-btn');
  3763. const newBtn = btn.cloneNode(true);
  3764. newBtn.querySelector('.menu-item-button').textContent = `Turn ${isEnable ? 'OFF' : 'ON'} YouTube Audio Mode`;
  3765. newBtn.classList.add('audio-only-toggle-btn');
  3766. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  3767. newBtn.addEventListener('click', async (evt) => {
  3768. try {
  3769. evt.stopPropagation();
  3770. evt.stopImmediatePropagation();
  3771. } catch (e) { }
  3772. await setEnableVal(!isEnable);
  3773. await GM.setValue('lastCheck_bWsm5', Date.now());
  3774. document.documentElement.setAttribute('forceRefresh032', '');
  3775. location.reload();
  3776. });
  3777. }
  3778.  
  3779. const lastEntry = (arr) => {
  3780. return arr.length > 0 ? arr[arr.length - 1] : null;
  3781. }
  3782.  
  3783. function mobileMenuItemAppearedV2Fn(target) {
  3784.  
  3785. const btn = target.closest('yt-list-item-view-model');
  3786. if (!(btn instanceof HTMLElement)) return;
  3787. if (btn.parentNode.querySelector('yt-list-item-view-model.audio-only-toggle-btn')) return;
  3788. const parentNode = btn.closest('player-settings-menu');
  3789. if (!parentNode) return;
  3790. let qt = 1E9;
  3791. let targetBtnO = lastEntry([...parentNode.getElementsByTagName(btn.nodeName)].filter(e => e.parentElement === btn.parentElement).map((elm) => {
  3792. const count = elm.getElementsByTagName('*').length;
  3793. if (count < qt) qt = count;
  3794. return {
  3795. elm: elm,
  3796. count: count
  3797. }
  3798. }).filter((o) => o.count === qt));
  3799.  
  3800. const targetBtn = targetBtnO && targetBtnO.elm instanceof HTMLElement ? targetBtnO.elm : btn;
  3801.  
  3802.  
  3803. const newBtn = targetBtn.cloneNode(true);
  3804. if (newBtn instanceof HTMLElement) {
  3805. document.documentElement.classList.add('with-audio-only-toggle-btn');
  3806.  
  3807. let newBtnContentElm = newBtn;
  3808. let layerCN = 8;
  3809. while (newBtnContentElm.childElementCount === 1 && layerCN--) {
  3810. newBtnContentElm = newBtnContentElm.firstElementChild;
  3811. }
  3812. if (!(newBtnContentElm instanceof HTMLElement)) newBtnContentElm = newBtn;
  3813. let t;
  3814. if (t = lastEntry(newBtnContentElm.querySelectorAll('span[role="text"]'))) {
  3815. newBtnContentElm = t;
  3816. newBtnContentElm.classList.add('audio-only-toggle-btn-content2');
  3817. } else if (t = lastEntry(newBtnContentElm.querySelectorAll('[role="text"]'))) {
  3818. newBtnContentElm = t;
  3819. newBtnContentElm.classList.add('audio-only-toggle-btn-content2');
  3820. } else if (t = lastEntry(newBtnContentElm.querySelectorAll('span'))) {
  3821. newBtnContentElm = t;
  3822. newBtnContentElm.classList.add('audio-only-toggle-btn-content2');
  3823. } else if (t = lastEntry(newBtnContentElm.querySelector('.yt-core-attributed-string'))) {
  3824. newBtnContentElm = t;
  3825. newBtnContentElm.classList.add('audio-only-toggle-btn-content2');
  3826. }
  3827. newBtnContentElm.textContent = `Turn ${isEnable ? 'OFF' : 'ON'} YouTube Audio Mode`;
  3828. newBtn.classList.add('audio-only-toggle-btn');
  3829. newBtnContentElm.classList.add('audio-only-toggle-btn-content');
  3830. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  3831. newBtn.addEventListener('click', async (evt) => {
  3832. try {
  3833. evt.stopPropagation();
  3834. evt.stopImmediatePropagation();
  3835. } catch (e) { }
  3836. await setEnableVal(!isEnable);
  3837. await GM.setValue('lastCheck_bWsm5', Date.now());
  3838. document.documentElement.setAttribute('forceRefresh032', '');
  3839. location.reload();
  3840. });
  3841. const contentWrapper = newBtn.closest('#content-wrapper');
  3842. if (contentWrapper) {
  3843. contentWrapper.style.height = 'unset';
  3844. contentWrapper.style.maxHeight = 'unset';
  3845. }
  3846. }
  3847. }
  3848.  
  3849. pLoad.then(() => {
  3850.  
  3851. document.addEventListener('animationstart', (evt) => {
  3852. const animationName = evt.animationName;
  3853. if (!animationName) return;
  3854.  
  3855. if (animationName === 'contextmenuInfoItemAppeared') contextmenuInfoItemAppearedFn(evt.target);
  3856. if (animationName === 'mobileMenuItemAppeared') mobileMenuItemAppearedFn(evt.target);
  3857. if (animationName === 'mobileMenuItemAppearedV2') mobileMenuItemAppearedV2Fn(evt.target);
  3858.  
  3859. }, true);
  3860.  
  3861. const cssForEnabled = isEnable ? `
  3862.  
  3863. .html5-video-player {
  3864. background-color: black;
  3865. }
  3866.  
  3867. [style*="--audio-only-thumbnail-image"]{
  3868. background-image: var(--audio-only-thumbnail-image);
  3869. object-fit: contain;
  3870. background-position: center;
  3871. background-size: contain;
  3872. background-repeat: no-repeat;
  3873. }
  3874. .html5-video-player.ended-mode [style*="--audio-only-thumbnail-image"]{
  3875. background-image: none;
  3876. }
  3877.  
  3878. .html5-video-player.ytp-ce-shown .html5-video-container {
  3879. opacity: 0.5;
  3880. transition: opacity 0.5s;
  3881. }
  3882.  
  3883. ytd-video-preview #media-container div#player-container,
  3884. ytd-video-preview #media-container div#thumbnail-container{
  3885. transition: initial !important;
  3886. transition-duration:0ms !important;
  3887. transition-delay:0ms !important;
  3888. }
  3889. ytd-video-preview #media-container div#thumbnail-container{
  3890. /* pointer-events:none !important; */
  3891. opacity:0;
  3892. /* z-index:-1; */
  3893. }
  3894. ytd-video-preview #media-container div#player-container,
  3895. ytd-video-preview #media-container div#inline-preview-player{
  3896. background-color:transparent !important;
  3897. background-image:none !important;
  3898. }
  3899.  
  3900. #movie_player > .html5-video-container:not(:empty) {
  3901. box-sizing: border-box;
  3902. height: 100%;
  3903. }
  3904.  
  3905. #movie_player [style*="--audio-only-thumbnail-image"] ~ .ytp-cued-thumbnail-overlay > .ytp-cued-thumbnail-overlay-image[style*="background-image"] {
  3906. opacity: 0;
  3907. }
  3908.  
  3909. #movie_player [style*="--audio-only-thumbnail-image"]::before {
  3910. content: '';
  3911. display: block;
  3912. position: absolute;
  3913. left: 0;
  3914. top: 0;
  3915. bottom: 0;
  3916. right: 0;
  3917. /* background: transparent; */
  3918.  
  3919.  
  3920. /* We use multiple backgrounds: one gradient per side */
  3921. background:
  3922. /* Left border gradient */
  3923. linear-gradient(to right, rgba(0,0,0,0.4), transparent) left center,
  3924. /* Right border gradient */
  3925. linear-gradient(to left, rgba(0,0,0,0.4), transparent) right center,
  3926. /* Top border gradient */
  3927. linear-gradient(to bottom, rgba(0,0,0,0.4), transparent) center top,
  3928. /* Bottom border gradient */
  3929. linear-gradient(to top, rgba(0,0,0,0.4), transparent) center bottom;
  3930.  
  3931. /* Prevents repetition of gradients */
  3932. background-repeat: no-repeat;
  3933.  
  3934. /* Set the size of each gradient "border" */
  3935. background-size:
  3936. 12% 100%, /* left border width and full height */
  3937. 12% 100%, /* right border width and full height */
  3938. 100% 12%, /* top border full width and small height */
  3939. 100% 12%; /* bottom border full width and small height */
  3940.  
  3941. /* Optional: a base background color inside the element */
  3942. /* background-color: #fff; */
  3943. /* background-color: var(--blinker-fmw83-bgc, transparent); */
  3944.  
  3945. opacity: var(--fmw83-opacity, 1);
  3946.  
  3947. pointer-events: none !important;
  3948. z-index:-1;
  3949.  
  3950. }
  3951.  
  3952. /*
  3953. @keyframes blinker-fmw83 {
  3954. 0%, 60%, 100% {
  3955. opacity: 1;
  3956. }
  3957. 30% {
  3958. opacity: 0.96;
  3959. }
  3960. }
  3961. */
  3962.  
  3963.  
  3964. #movie_player.playing-mode [style*="--audio-only-thumbnail-image"]{
  3965. /* animation: blinker-fmw83 1.74s linear infinite; */
  3966. --fmw83-opacity: 0.6;
  3967.  
  3968. }
  3969.  
  3970. #global-loader ytw-scrim {
  3971. display: none;
  3972. }
  3973.  
  3974. `: "";
  3975.  
  3976. const style = document.createElement('style');
  3977. style.id = 'fm9v0';
  3978. style.textContent = `
  3979.  
  3980. ${cssForEnabled}
  3981.  
  3982. @keyframes mobileMenuItemAppeared {
  3983. 0% {
  3984. background-position-x: 3px;
  3985. }
  3986. 100% {
  3987. background-position-x: 4px;
  3988. }
  3989. }
  3990.  
  3991. @keyframes mobileMenuItemAppearedV2 {
  3992. 0% {
  3993. background-position-x: 3px;
  3994. }
  3995. 100% {
  3996. background-position-x: 4px;
  3997. }
  3998. }
  3999. ytm-select.player-speed-settings ~ ytm-menu-item:last-of-type {
  4000. animation: mobileMenuItemAppeared 1ms linear 0s 1 normal forwards;
  4001. }
  4002.  
  4003. player-settings-menu > yt-list-item-view-model:last-of-type {
  4004. animation: mobileMenuItemAppearedV2 1ms linear 0s 1 normal forwards;
  4005. }
  4006.  
  4007.  
  4008. player-settings-menu .audio-only-toggle-btn-content {
  4009. padding: 14px 24px;
  4010. box-sizing: border-box;
  4011. font-size: 130%;
  4012. }
  4013.  
  4014. player-settings-menu .audio-only-toggle-btn-content2 {
  4015. padding: 0;
  4016. box-sizing: border-box;
  4017. font-size: inherit;
  4018. }
  4019.  
  4020.  
  4021. @keyframes contextmenuInfoItemAppeared {
  4022. 0% {
  4023. background-position-x: 3px;
  4024. }
  4025. 100% {
  4026. background-position-x: 4px;
  4027. }
  4028. }
  4029. .ytp-contextmenu .ytp-menuitem[role="menuitem"] path[d^="M22 34h4V22h-4v12zm2-30C12.95"]{
  4030. animation: contextmenuInfoItemAppeared 1ms linear 0s 1 normal forwards;
  4031. }
  4032. #confirmDialog794 {
  4033. z-index:999999 !important;
  4034. display: none;
  4035. /* Hidden by default */
  4036. position: fixed;
  4037. /* Stay in place */
  4038. z-index: 1;
  4039. /* Sit on top */
  4040. left: 0;
  4041. top: 0;
  4042. width: 100%;
  4043. /* Full width */
  4044. height: 100%;
  4045. /* Full height */
  4046. overflow: auto;
  4047. /* Enable scroll if needed */
  4048. background-color: rgba(0,0,0,0.4);
  4049. /* Black w/ opacity */
  4050. }
  4051. #confirmDialog794 .confirm-box {
  4052. position:relative;
  4053. color: black;
  4054. z-index:999999 !important;
  4055. background-color: #fefefe;
  4056. margin: 15% auto;
  4057. /* 15% from the top and centered */
  4058. padding: 20px;
  4059. border: 1px solid #888;
  4060. width: 30%;
  4061. /* Could be more or less, depending on screen size */
  4062. box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  4063. }
  4064. #confirmDialog794 .confirm-buttons {
  4065. text-align: right;
  4066. }
  4067. #confirmDialog794 button {
  4068. margin-left: 10px;
  4069. }
  4070.  
  4071. `
  4072. document.head.appendChild(style);
  4073.  
  4074. });
  4075.  
  4076.  
  4077. const pNavigateFinished = new Promise(resolve => {
  4078. document.addEventListener('yt-navigate-finish', resolve, true);
  4079. });
  4080.  
  4081. pNavigateFinished.then(() => {
  4082. const inputs = document.querySelectorAll('#masthead input[type="text"][name]');
  4083.  
  4084. let lastInputTextValue = null;
  4085. let busy = false;
  4086. let disableMonitoring = false;
  4087. const setGV = async (val) => {
  4088.  
  4089. const videoId = getVideoIdByURL() || getVideoIdByElement();
  4090. if (videoId) {
  4091. const cgv = await GM.getValue(`isEnable_aWsjF_${videoId}`, null);
  4092. if (cgv !== val || isEnable !== val) {
  4093. disableMonitoring = true;
  4094. await GM.setValue(`isEnable_aWsjF_${videoId}`, val);
  4095. await GM.setValue('lastCheck_bWsm5', Date.now());
  4096. document.documentElement.setAttribute('forceRefresh032', '');
  4097. location.reload();
  4098. }
  4099.  
  4100. }
  4101. }
  4102. const checkTextChangeF = async (evt) => {
  4103. busy = false;
  4104. const inputElem = (evt || 0).target;
  4105. if (inputElem instanceof HTMLInputElement && !disableMonitoring) {
  4106. const cv = inputElem.value;
  4107. if (cv === lastInputTextValue) return;
  4108. lastInputTextValue = cv;
  4109. if (cv === 'vvv') {
  4110.  
  4111. await setGV(false);
  4112.  
  4113. } else if (cv === 'aaa') {
  4114.  
  4115. await setGV(true);
  4116.  
  4117. }
  4118. }
  4119. }
  4120. const checkTextChange = (evt) => {
  4121. if (busy) return;
  4122. busy = true;
  4123. Promise.resolve(evt).then(checkTextChangeF)
  4124. };
  4125. for (const input of inputs) {
  4126. input.addEventListener('input', checkTextChange, false);
  4127. input.addEventListener('keydown', checkTextChange, false);
  4128. input.addEventListener('keyup', checkTextChange, false);
  4129. input.addEventListener('keypress', checkTextChange, false);
  4130. input.addEventListener('change', checkTextChange, false);
  4131. }
  4132. });
  4133.  
  4134. const autoCleanUpKey = async () => {
  4135.  
  4136. const lastCheck = await GM.getValue('lastCheck_bWsm5', null) || 0;
  4137. if (Date.now() - lastCheck < 16000) return; // 16s
  4138. GM.setValue('lastCheck_bWsm5', Date.now());
  4139. pLoad.then(async () => {
  4140. const rArr = [];
  4141. const arr = await GM.listValues();
  4142. const cv = await GM.getValue("isEnable_aWsjF", null);
  4143. const fn = async (entry) => {
  4144. try {
  4145. if (typeof entry === 'string' && entry.length > 15 && entry.startsWith('isEnable_aWsjF_')) {
  4146. const res = await GM.getValue(entry, null);
  4147. if (typeof res === 'boolean' && res === cv) {
  4148. await GM.deleteValue(entry);
  4149. rArr.push(entry);
  4150. }
  4151. }
  4152. } catch (e) {
  4153. console.warn(e);
  4154. }
  4155. }
  4156. arr.length > 1 && (await Promise.all(arr.map(fn)));
  4157. rArr.length > 0 && console.log('[YouTube Audio Only] autoCleanUpKey', rArr);
  4158. });
  4159. };
  4160.  
  4161. autoCleanUpKey();
  4162.  
  4163.  
  4164.  
  4165.  
  4166.  
  4167. })();
  4168.