YouTube: Audio Only

No Video Streaming

当前为 2025-01-06 提交的版本,查看 最新版本

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