Tabview Youtube

Make comments and lists into tabs for YouTube Videos

当前为 2022-05-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Tabview Youtube
  3. // @name:en Tabview Youtube
  4. // @name:jp Tabview Youtube
  5. // @name:zh-tw Tabview Youtube
  6. // @name:zh-cn Tabview Youtube
  7. // @namespace http://tampermonkey.net/
  8. // @version 2.1.3
  9. // @license MIT https://github.com/cyfung1031/Tabview-Youtube/blob/main/LICENSE
  10. // @description Make comments and lists into tabs for YouTube Videos
  11. // @description:en Make comments and lists into tabs for YouTube Videos
  12. // @description:jp YouTube動画のコメントやリストなどをタブに作成します
  13. // @description:zh-tw 把Youtube Videos中的評論及影片清單製作成Tabs
  14. // @description:zh-cn 把Youtube Videos中的评论及视频列表制作成Tabs
  15. // @author CY Fung
  16. // @include https://www.youtube.com/*
  17. // @icon https://github.com/cyfung1031/Tabview-Youtube/raw/main/images/icon128p.png
  18. // @run-at document-start
  19. // @grant GM_getResourceText
  20. // @resource contentCSS https://raw.githubusercontent.com/cyfung1031/Tabview-Youtube/4546739b1eb4224a62a431fe1b23a7b8201d4f17/css/style_content.css
  21. // @resource injectionJS1 https://raw.githubusercontent.com/cyfung1031/Tabview-Youtube/4546739b1eb4224a62a431fe1b23a7b8201d4f17/js/injection_script_1.js
  22. // @resource injectionFixAutoComplete https://raw.githubusercontent.com/cyfung1031/Tabview-Youtube/4546739b1eb4224a62a431fe1b23a7b8201d4f17/js/injectionScript_fixAutoComplete.js
  23. // @require https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.0/cash.min.js
  24. // @noframes
  25. // ==/UserScript==
  26.  
  27. /* jshint esversion:6 */
  28.  
  29. function main($){
  30. // MIT License
  31. // https://github.com/cyfung1031/Tabview-Youtube/raw/main/js/content.js
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. -(function() {
  55.  
  56. function inIframe() {
  57. try {
  58. return window.self !== window.top;
  59. } catch (e) {
  60. return true;
  61. }
  62. }
  63.  
  64. if (inIframe()) return;
  65.  
  66. if (!$) return;
  67.  
  68. /**
  69. * SVG resources:
  70. * <div>Icons made by <a href="https://www.flaticon.com/authors/smashicons" title="Smashicons">Smashicons</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>
  71. */
  72.  
  73. const scriptVersionForExternal = '2022/05/07';
  74.  
  75. //const githubURLBase = "https://raw.githubusercontent.com/cyfung1031/Tabview-Youtube";
  76. //const githubURLCommit = "bdf401045266e5224663f80b276bc7f56d122b8d";
  77.  
  78. const isMyScriptInChromeRuntime = () => typeof((((window || 0).chrome || 0).runtime || 0).getURL) == 'function'
  79.  
  80.  
  81. const svgComments = `
  82. <path d="M40.068,13.465L5.93,13.535c-3.27,0-5.93,2.66-5.93,5.93v21.141c0,3.27,2.66,5.929,5.93,5.929H12v10
  83. c0,0.413,0.254,0.784,0.64,0.933c0.117,0.045,0.239,0.067,0.36,0.067c0.276,0,0.547-0.115,0.74-0.327l9.704-10.675l16.626-0.068
  84. c3.27,0,5.93-2.66,5.93-5.929V19.395C46,16.125,43.34,13.465,40.068,13.465z M10,23.465h13c0.553,0,1,0.448,1,1s-0.447,1-1,1H10
  85. c-0.553,0-1-0.448-1-1S9.447,23.465,10,23.465z M36,37.465H10c-0.553,0-1-0.448-1-1s0.447-1,1-1h26c0.553,0,1,0.448,1,1
  86. S36.553,37.465,36,37.465z M36,31.465H10c-0.553,0-1-0.448-1-1s0.447-1,1-1h26c0.553,0,1,0.448,1,1S36.553,31.465,36,31.465z"/>
  87. <path d="M54.072,2.535L19.93,2.465c-3.27,0-5.93,2.66-5.93,5.93v3.124l26.064-0.054c4.377,0,7.936,3.557,7.936,7.93v21.07v0.071
  88. v2.087l3.26,3.586c0.193,0.212,0.464,0.327,0.74,0.327c0.121,0,0.243-0.022,0.36-0.067c0.386-0.149,0.64-0.52,0.64-0.933v-10h1.07
  89. c3.27,0,5.93-2.66,5.93-5.929V8.465C60,5.195,57.34,2.535,54.072,2.535z"/>
  90. `.trim();
  91.  
  92. const svgVideos = `<path d="M298,33c0-13.255-10.745-24-24-24H24C10.745,9,0,19.745,0,33v232c0,13.255,10.745,24,24,24h250c13.255,0,24-10.745,24-24V33
  93. z M91,39h43v34H91V39z M61,259H30v-34h31V259z M61,73H30V39h31V73z M134,259H91v-34h43V259z M123,176.708v-55.417
  94. c0-8.25,5.868-11.302,12.77-6.783l40.237,26.272c6.902,4.519,6.958,11.914,0.056,16.434l-40.321,26.277
  95. C128.84,188.011,123,184.958,123,176.708z M207,259h-43v-34h43V259z M207,73h-43V39h43V73z M268,259h-31v-34h31V259z M268,73h-31V39
  96. h31V73z"/>`.trim();
  97.  
  98. const svgInfo = `<path d="M11.812,0C5.289,0,0,5.289,0,11.812s5.289,11.813,11.812,11.813s11.813-5.29,11.813-11.813
  99. S18.335,0,11.812,0z M14.271,18.307c-0.608,0.24-1.092,0.422-1.455,0.548c-0.362,0.126-0.783,0.189-1.262,0.189
  100. c-0.736,0-1.309-0.18-1.717-0.539s-0.611-0.814-0.611-1.367c0-0.215,0.015-0.435,0.045-0.659c0.031-0.224,0.08-0.476,0.147-0.759
  101. l0.761-2.688c0.067-0.258,0.125-0.503,0.171-0.731c0.046-0.23,0.068-0.441,0.068-0.633c0-0.342-0.071-0.582-0.212-0.717
  102. c-0.143-0.135-0.412-0.201-0.813-0.201c-0.196,0-0.398,0.029-0.605,0.09c-0.205,0.063-0.383,0.12-0.529,0.176l0.201-0.828
  103. c0.498-0.203,0.975-0.377,1.43-0.521c0.455-0.146,0.885-0.218,1.29-0.218c0.731,0,1.295,0.178,1.692,0.53
  104. c0.395,0.353,0.594,0.812,0.594,1.376c0,0.117-0.014,0.323-0.041,0.617c-0.027,0.295-0.078,0.564-0.152,0.811l-0.757,2.68
  105. c-0.062,0.215-0.117,0.461-0.167,0.736c-0.049,0.275-0.073,0.485-0.073,0.626c0,0.356,0.079,0.599,0.239,0.728
  106. c0.158,0.129,0.435,0.194,0.827,0.194c0.185,0,0.392-0.033,0.626-0.097c0.232-0.064,0.4-0.121,0.506-0.17L14.271,18.307z
  107. M14.137,7.429c-0.353,0.328-0.778,0.492-1.275,0.492c-0.496,0-0.924-0.164-1.28-0.492c-0.354-0.328-0.533-0.727-0.533-1.193
  108. c0-0.465,0.18-0.865,0.533-1.196c0.356-0.332,0.784-0.497,1.28-0.497c0.497,0,0.923,0.165,1.275,0.497
  109. c0.353,0.331,0.53,0.731,0.53,1.196C14.667,6.703,14.49,7.101,14.137,7.429z"/>`.trim();
  110.  
  111. const svgPlayList = `
  112. <rect x="0" y="64" width="256" height="42.667"/>
  113. <rect x="0" y="149.333" width="256" height="42.667"/>
  114. <rect x="0" y="234.667" width="170.667" height="42.667"/>
  115. <polygon points="341.333,234.667 341.333,149.333 298.667,149.333 298.667,234.667 213.333,234.667 213.333,277.333
  116. 298.667,277.333 298.667,362.667 341.333,362.667 341.333,277.333 426.667,277.333 426.667,234.667"/>
  117. `.trim();
  118.  
  119. // --- Youtube Video Testing :
  120. // Square Video: https://www.youtube.com/watch?v=L0RXVnRbFg8
  121. // Square Video: https://www.youtube.com/watch?v=bK_rKhMIotU
  122. // ---
  123.  
  124.  
  125. const LAYOUT_TWO_COLUMNS = 1;
  126. const LAYOUT_THEATER = 2;
  127. const LAYOUT_FULLSCREEN = 4;
  128. const LAYOUT_CHATROOM = 8;
  129. const LAYOUT_CHATROOM_COLLASPED = 16;
  130. const LAYOUT_TAB_EXPANDED = 32;
  131. const LAYOUT_ENGAGEMENT_PANEL_EXPAND = 64;
  132.  
  133. const mtoInterval1 = 40;
  134. const mtoInterval2 = 150;
  135.  
  136. let lastVideoURL = null; // for less attribute set only
  137.  
  138.  
  139. const WeakRef = window.WeakRef;
  140. const mWeakRef = WeakRef ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  141. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  142.  
  143.  
  144.  
  145. const nonCryptoRandStr_base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  146. function nonCryptoRandStr(n){
  147. const result = new Array(n);
  148. const baseStr = nonCryptoRandStr_base;
  149. const bLen = baseStr.length;
  150. for ( let i = 0; i < n; i++ ) {
  151. let t = null
  152. do {
  153. t = baseStr.charAt(Math.floor(Math.random() * bLen));
  154. }while(i===0 && 10-t>0)
  155. result[i]=t;
  156. }
  157. return result.join('');
  158. }
  159.  
  160. class ObserverRegister{
  161. static uidStore = {};
  162. /** @type {string} */
  163. uid;
  164.  
  165. /** @type {Function} */
  166. observerCreator;
  167.  
  168. /** @type {MutationObserver | IntersectionObserver} */
  169. observer;
  170. constructor(/** @type {Function} */ observerCreator){
  171. let uid = null;
  172. const uidStore = ObserverRegister.uidStore;
  173. do{
  174. uid = nonCryptoRandStr(5);
  175. }while(uidStore[uid])
  176. uidStore[uid] = true;
  177. this.uid = uid;
  178. this.observerCreator = observerCreator
  179. this.observer = null;
  180. }
  181. bindElement(/** @type {HTMLElement} */ elm, ...args){
  182. if(elm.hasAttribute(`o3r-${this.uid}`))return false;
  183. elm.setAttribute(`o3r-${this.uid}`,'')
  184. if(this.observer===null){
  185. this.observer=this.observerCreator();
  186. }
  187. this.observer.observe(elm, ...args)
  188. return true
  189. }
  190. clear(/** @type {boolean} */ flag){
  191. if(this.observer !== null){
  192. //const uidStore = ObserverRegister.uidStore;
  193. if(flag === true){
  194. this.observer.takeRecords();
  195. this.observer.disconnect();
  196. }
  197. this.observer = null;
  198. for(const s of document.querySelectorAll(`[o3r-${this.uid}]`)) s.removeAttribute(`o3r-${this.uid}`)
  199. //uidStore[this.uid]=false;
  200. //this.uid = null;
  201. }
  202. }
  203. }
  204.  
  205. const mtoMutation_watchFlexy = new ObserverRegister(()=>{
  206. return new MutationObserver(FP.mtoNavF)
  207. });
  208. const sa_wflexy = mtoMutation_watchFlexy.uid;
  209.  
  210. const mtoMutation_body = new ObserverRegister(()=>{
  211. return new MutationObserver(FP.mtoBodyF)
  212. });
  213. const sa_body = mtoMutation_body.uid;
  214.  
  215. const mtoFlexyAttr = new ObserverRegister(()=>{
  216. return new MutationObserver(mtf_attrFlexy)
  217. });
  218. const sa_flexyAttr = mtoFlexyAttr.uid;
  219.  
  220. const mtoVisibility_EngagementPanel = new ObserverRegister(()=>{
  221. return new MutationObserver(FP.mtf_attrEngagementPanel)
  222. });
  223. const sa_epanel = mtoVisibility_EngagementPanel.uid;
  224.  
  225. const mtoVisibility_Playlist = new ObserverRegister(()=>{
  226. return new AttributeMutationObserver({
  227. "hidden": FP.mtf_attrPlaylist
  228. })
  229. })
  230. const sa_playlist = mtoVisibility_Playlist.uid;
  231.  
  232. const mtoVisibility_Comments = new ObserverRegister(()=>{
  233. return new AttributeMutationObserver({
  234. "hidden": FP.mtf_attrComments
  235. })
  236. })
  237. const sa_comments = mtoVisibility_Comments.uid;
  238.  
  239.  
  240. const mtoVisibility_Chatroom = new ObserverRegister(()=>{
  241. return new AttributeMutationObserver({
  242. "collapsed": FP.mtf_attrChatroom
  243. })
  244. })
  245. const sa_chatroom = mtoVisibility_Chatroom.uid;
  246.  
  247.  
  248.  
  249.  
  250.  
  251. function tracer(key, cmp) {
  252. if (cmp > 0) return tracer[key] === cmp;
  253. return (tracer[key] = Date.now());
  254. }
  255.  
  256. function racer(key, f) {
  257. let now = Date.now();
  258. const kTime = `${key}$$1`
  259. let t = racer[kTime] || 0;
  260.  
  261. if (now < t) {
  262. const kCount = `${key}$$2`;
  263. racer[kCount] = (racer[kCount] || 0) + 1;
  264. if (racer[kCount] === 1) {
  265. let g = f;
  266. requestAnimationFrame(() => {
  267. racer[kCount] = 0;
  268. g();
  269. g = null;
  270. })
  271. }
  272. } else {
  273. racer[kTime] = now + 16;
  274. f();
  275. }
  276. }
  277.  
  278. class ScriptEF {
  279. constructor() {
  280. this._id = scriptEC;
  281. }
  282. isValid() {
  283. return this._id === scriptEC;
  284. }
  285. }
  286.  
  287. class Timeout {
  288.  
  289. set(f, d, repeatCount) {
  290. if (this.cid > 0) return;
  291. let sEF = new ScriptEF();
  292. if (repeatCount > 0) {
  293.  
  294. let rc = repeatCount;
  295. const g = () => {
  296. this.cid = 0;
  297. if (!sEF.isValid()) return;
  298. let res = f();
  299. if (--rc <= 0) return;
  300. if (res === true) this.cid = timeline.setTimeout(g, d);
  301. }
  302. g();
  303.  
  304. } else {
  305.  
  306. const g = () => {
  307. this.cid = 0;
  308. if (!sEF.isValid()) return;
  309. if (f() === true) this.cid = timeline.setTimeout(g, d);
  310. }
  311. this.cid = timeline.setTimeout(g, d);
  312. }
  313. }
  314.  
  315. clear() {
  316. if (this.cid > 0) timeline.clearTimeout(this.cid);
  317. }
  318.  
  319. isEmpty() {
  320. return !this.cid
  321. }
  322.  
  323.  
  324. }
  325.  
  326. class Mutex {
  327.  
  328. constructor() {
  329. this.p = Promise.resolve()
  330. }
  331.  
  332. lockWith(f) {
  333.  
  334. this.p = this.p.then(() => {
  335. return new Promise(f)
  336. }).catch(console.warn)
  337. }
  338.  
  339. }
  340.  
  341.  
  342.  
  343. function prettyElm(elm) {
  344. if (!elm || !elm.nodeName) return null;
  345. const eId = elm.id || null;
  346. const eClsName = elm.className || null;
  347. return [elm.nodeName.toLowerCase(), typeof eId == 'string' ? "#" + eId : '', typeof eClsName == 'string' ? '.' + eClsName.replace(/\s+/g, '.') : ''].join('').trim();
  348. }
  349.  
  350. function extractTextContent(elm) {
  351. return elm.textContent.replace(/\s+/g, '').replace(/[^\da-zA-Z\u4E00-\u9FFF\u00C0-\u00FF\u00C0-\u02AF\u1E00-\u1EFF\u0590-\u05FF\u0400-\u052F\u0E00-\u0E7F\u0600-\u06FF\u0750-\u077F\u1100-\u11FF\u3130-\u318F\uAC00-\uD7AF\u3040-\u30FF\u31F0-\u31FF]/g, '')
  352. }
  353.  
  354. function addScript(scriptText) {
  355. const scriptNode = document.createElement('script');
  356. scriptNode.type = 'text/javascript';
  357. scriptNode.textContent = scriptText;
  358. try {
  359. document.documentElement.appendChild(scriptNode);
  360. } catch (e) {
  361. console.log('addScript Error', e)
  362. }
  363. return scriptNode;
  364. }
  365.  
  366. function addScriptByURL(scriptURL) {
  367. const scriptNode = document.createElement('script');
  368. scriptNode.type = 'text/javascript';
  369. scriptNode.src = scriptURL;
  370. try {
  371. document.documentElement.appendChild(scriptNode);
  372. } catch (e) {
  373. console.log('addScriptByURL Error', e)
  374. }
  375. return scriptNode;
  376. }
  377.  
  378. function addStyle(styleText, container) {
  379. const styleNode = document.createElement('style');
  380. //styleNode.type = 'text/css';
  381. styleNode.textContent = styleText;
  382. (container || document.documentElement).appendChild(styleNode);
  383. return styleNode;
  384. }
  385.  
  386.  
  387. const stopIframePropagation = function(evt){
  388. if(scriptEnable && evt && evt.target && evt.target.nodeName=='IFRAME'){
  389. evt.stopImmediatePropagation();
  390. evt.stopPropagation();
  391. }
  392. }
  393. document.addEventListener('mouseover', stopIframePropagation, true)
  394. document.addEventListener('mouseout', stopIframePropagation, true)
  395. document.addEventListener('mousedown', stopIframePropagation, true)
  396. document.addEventListener('mouseup', stopIframePropagation, true)
  397. document.addEventListener('keydown', stopIframePropagation, true)
  398. document.addEventListener('keyup', stopIframePropagation, true)
  399. document.addEventListener('mouseenter', stopIframePropagation, true)
  400. document.addEventListener('mouseleave', stopIframePropagation, true)
  401.  
  402.  
  403.  
  404. function isDOMVisible(elem) {
  405. // jQuery version : https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/css/hiddenVisibleSelectors.js
  406. return !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
  407. }
  408.  
  409. function isNonEmptyString(s) {
  410. return typeof s == 'string' && s.length > 0;
  411. }
  412.  
  413.  
  414. async function nativeFunc(dom, property, args) {
  415. dom.dispatchEvent(new CustomEvent("userscript-call-dom-func", { detail: { property, args } }))
  416. }
  417.  
  418. /*
  419. async function nativeValue(dom, property, args) {
  420. dom.dispatchEvent(new CustomEvent("userscript-call-dom-value", { detail: { property, args } }))
  421. }
  422. */
  423. async function nativeFuncStacked(selector, property, args){
  424. document.dispatchEvent(new CustomEvent("userscript-call-dom-func-stacked", { detail: { selector, property, args } }))
  425. }
  426. /*
  427. async function nativeValueStacked(selector, property, args){
  428. document.dispatchEvent(new CustomEvent("userscript-call-dom-value-stacked", { detail: { selector, property, args } }))
  429. }
  430. async function nativeConstStacked(selector, property, args){
  431. document.dispatchEvent(new CustomEvent("userscript-call-dom-const-stacked", { detail: { selector, property, args } }))
  432. }
  433. */
  434.  
  435.  
  436. function akAttr(cssElm, attrName, isNegative, flag) {
  437. // isNegative => incomplete loading
  438.  
  439. let u = parseInt(cssElm.getAttribute(attrName) || 0) || 0;
  440. let ak = Math.abs(u);
  441.  
  442. if (ak > 100 && isNegative && u < 0) {
  443.  
  444. } else if (ak > 100 && !isNegative && u > 0) {
  445.  
  446. } else {
  447. if (ak <= 100) {
  448. ak = 101;
  449. } else {
  450. ak++;
  451. if (ak >= 800) ak = 101;
  452. }
  453. // 101, 102, ... 799, 101
  454. }
  455.  
  456. cssElm.setAttribute(attrName, `${ isNegative ? -ak : ak }${ flag || '' }`)
  457. }
  458.  
  459.  
  460.  
  461. let timeout_resize_for_layout_change = new Timeout();
  462.  
  463. function dispatchWindowResize(){
  464. // for youtube to detect layout resize for adjusting Player tools
  465. return window.dispatchEvent(new Event('resize'));
  466. }
  467.  
  468.  
  469.  
  470. function layoutStatusChanged(old_layoutStatus, new_layoutStatus) {
  471.  
  472.  
  473. if (old_layoutStatus === new_layoutStatus) return;
  474.  
  475. const cssElm = kRef(ytdFlexy);
  476.  
  477. if (!cssElm) return;
  478.  
  479.  
  480. const new_isExpandedChat = !(new_layoutStatus & LAYOUT_CHATROOM_COLLASPED) && (new_layoutStatus & LAYOUT_CHATROOM)
  481. const new_isCollaspedChat = (new_layoutStatus & LAYOUT_CHATROOM_COLLASPED) && (new_layoutStatus & LAYOUT_CHATROOM)
  482.  
  483. const new_isTwoColumns = new_layoutStatus & LAYOUT_TWO_COLUMNS;
  484. const new_isTheater = new_layoutStatus & LAYOUT_THEATER;
  485. const new_isTabExpanded = new_layoutStatus & LAYOUT_TAB_EXPANDED;
  486. const new_isFullScreen = new_layoutStatus & LAYOUT_FULLSCREEN;
  487. const new_isExpandEPanel = new_layoutStatus & LAYOUT_ENGAGEMENT_PANEL_EXPAND;
  488.  
  489.  
  490. function showTabOrChat() {
  491.  
  492. layoutStatusMutex.lockWith(unlock => {
  493.  
  494. if (lastShowTab == '#chatroom') {
  495.  
  496. if (new_isTabExpanded) switchTabActivity(null)
  497. if (!new_isExpandedChat) ytBtnExpandChat();
  498.  
  499. } else if (lastShowTab && lastShowTab.indexOf('#engagement-panel-') == 0) {
  500.  
  501. if (new_isTabExpanded) switchTabActivity(null)
  502. if (!new_isExpandEPanel) ytBtnOpenEngagementPanel(lastShowTab);
  503.  
  504. } else {
  505.  
  506. if (new_isExpandedChat) ytBtnCollapseChat()
  507. if (!new_isTabExpanded) {setToActiveTab();}
  508.  
  509. }
  510.  
  511. timeline.setTimeout(unlock, 40);
  512.  
  513. })
  514. }
  515.  
  516. function hideTabAndChat() {
  517.  
  518. layoutStatusMutex.lockWith(unlock => {
  519.  
  520. if (new_isTabExpanded) switchTabActivity(null)
  521. if (new_isExpandedChat) ytBtnCollapseChat()
  522. if (new_isExpandEPanel) ytBtnCloseEngagementPanels();
  523.  
  524.  
  525. timeline.setTimeout(unlock, 40);
  526.  
  527. })
  528.  
  529. }
  530.  
  531.  
  532. if (new_isExpandedChat || new_isTabExpanded || new_isExpandEPanel) {
  533. if (statusCollasped !== 1) statusCollasped = 1;
  534. } else {
  535. if (statusCollasped === 1) statusCollasped = 2;
  536. }
  537.  
  538. let changes = 0;
  539.  
  540. if (old_layoutStatus !== null) changes = old_layoutStatus ^ new_layoutStatus;
  541.  
  542. let chat_collasped_changed = !!(changes & LAYOUT_CHATROOM_COLLASPED)
  543. let tab_expanded_changed = !!(changes & LAYOUT_TAB_EXPANDED)
  544. let theater_mode_changed = !!(changes & LAYOUT_THEATER)
  545. let column_mode_changed = !!(changes & LAYOUT_TWO_COLUMNS)
  546. let fullscreen_mode_changed = !!(changes & LAYOUT_FULLSCREEN)
  547. let epanel_expanded_changed = !!(changes & LAYOUT_ENGAGEMENT_PANEL_EXPAND)
  548.  
  549. let tab_change = (tab_expanded_changed ? 1 : 0) | (chat_collasped_changed ? 2 : 0) | (epanel_expanded_changed ? 4 : 0);
  550.  
  551. let isChatOrTabExpandTriggering = tab_change == 0 ? false : (
  552. (tab_expanded_changed && new_isTabExpanded) ||
  553. (chat_collasped_changed && new_isExpandedChat) ||
  554. (epanel_expanded_changed && new_isExpandEPanel)
  555. );
  556.  
  557. let isChatOrTabCollaspeTriggering = tab_change == 0 ? false : (
  558. (tab_expanded_changed && !new_isTabExpanded) ||
  559. (chat_collasped_changed && new_isCollaspedChat) ||
  560. (epanel_expanded_changed && !new_isExpandEPanel)
  561. );
  562.  
  563.  
  564.  
  565. let moreThanOneShown = (new_isTabExpanded + new_isExpandedChat + new_isExpandEPanel) > 1
  566.  
  567. let requestVideoResize = false;
  568.  
  569. if (fullscreen_mode_changed || new_isFullScreen) {
  570.  
  571. } else if (tab_change == 0 && column_mode_changed && new_isTwoColumns && !new_isTheater && statusCollasped === 1 && moreThanOneShown) {
  572.  
  573. showTabOrChat();
  574. requestVideoResize = true;
  575.  
  576. } else if (tab_change == 2 && new_isExpandedChat && new_isTwoColumns && !new_isTheater && statusCollasped === 1 && new_isTabExpanded && !column_mode_changed) {
  577.  
  578. switchTabActivity(null);
  579. requestVideoResize = true;
  580.  
  581. } else if (isChatOrTabExpandTriggering && new_isTwoColumns && new_isTheater && statusCollasped === 1 && !theater_mode_changed && !column_mode_changed) {
  582.  
  583. ytBtnCancelTheater();
  584. requestVideoResize = true;
  585.  
  586. } else if (new_isTwoColumns && new_isTheater && statusCollasped === 1) {
  587.  
  588. hideTabAndChat();
  589. requestVideoResize = true;
  590.  
  591. } else if (isChatOrTabCollaspeTriggering && new_isTwoColumns && !new_isTheater && statusCollasped === 2 && !column_mode_changed) {
  592.  
  593. ytBtnSetTheater();
  594. requestVideoResize = true;
  595.  
  596. } else if (tab_change == 0 && (column_mode_changed || theater_mode_changed) && new_isTwoColumns && !new_isTheater && statusCollasped !== 1) {
  597.  
  598. showTabOrChat();
  599. requestVideoResize = true;
  600.  
  601. } else if (!new_isFullScreen && new_isTwoColumns && !new_isTheater && !new_isTabExpanded &&
  602. (new_isCollaspedChat || !new_isExpandedChat) &&
  603. !new_isExpandEPanel
  604. ) {
  605. // bug fix for restoring from mini player
  606.  
  607. layoutStatusMutex.lockWith(unlock => {
  608.  
  609. if (new_isExpandedChat) ytBtnCollapseChat()
  610. setToActiveTab();
  611.  
  612. timeline.setTimeout(unlock, 40);
  613.  
  614. })
  615.  
  616. requestVideoResize = true;
  617.  
  618. } else if (tab_expanded_changed) {
  619.  
  620. requestVideoResize = true;
  621.  
  622. }
  623.  
  624.  
  625. if (column_mode_changed && !chat_collasped_changed && new_isExpandedChat) {
  626.  
  627. runAfterExpandChat();
  628.  
  629. }
  630.  
  631.  
  632.  
  633. if (requestVideoResize) {
  634.  
  635. timeout_resize_for_layout_change.clear();
  636. timeout_resize_for_layout_change.set(() => {
  637. dispatchWindowResize();
  638. }, 92)
  639.  
  640. } else if (timeout_resize_for_layout_change.isEmpty() && (Date.now()) - lastResizeAt > 600) {
  641. timeout_resize_for_layout_change.set(() => {
  642. if ((Date.now()) - lastResizeAt > 600) dispatchWindowResize();
  643. }, 62)
  644. }
  645.  
  646.  
  647.  
  648.  
  649. }
  650.  
  651.  
  652. const $ws = {
  653. _layoutStatus: null,
  654. layoutStatus_pending: false
  655. }
  656.  
  657. let wls = new class {
  658. get layoutStatus() {
  659. return this._layoutStatus;
  660. }
  661. set layoutStatus(nv) {
  662.  
  663. if (nv === null) {
  664. this._layoutStatus = null;
  665. statusCollasped = 0;
  666. return;
  667. }
  668. if (nv === this._layoutStatus) return;
  669.  
  670. if (!this.layoutStatus_pending) {
  671. this.layoutStatus_pending = true;
  672. const old_layoutStatus = this._layoutStatus;
  673.  
  674. layoutStatusMutex.lockWith(unlock => {
  675.  
  676. this.layoutStatus_pending = false;
  677. const new_layoutStatus = this._layoutStatus;
  678. layoutStatusChanged(old_layoutStatus, new_layoutStatus);
  679.  
  680. timeline.setTimeout(unlock, 40)
  681.  
  682.  
  683. })
  684. }
  685.  
  686. this._layoutStatus = nv;
  687. }
  688. };
  689.  
  690.  
  691.  
  692.  
  693. const svgElm = (w, h, vw, vh, p) => `<svg width="${w}" height="${h}" viewBox="0 0 ${vw} ${vh}" preserveAspectRatio="xMidYMid meet">${p}</svg>`
  694.  
  695. let settings = {
  696. defaultTab: "#tab-videos"
  697. };
  698.  
  699.  
  700. let mtoInterval = mtoInterval1;
  701.  
  702. function isVideoPlaying(video) {
  703. return video.currentTime > 0 && !video.paused && !video.ended && video.readyState > video.HAVE_CURRENT_DATA;
  704. }
  705.  
  706. function wAttr(elm, attr, kv) {
  707. if (!elm || kv === null) {} else if (kv === true) { elm.setAttribute(attr, '') } else if (kv === false) { elm.removeAttribute(attr) } else if (typeof kv == 'string') { elm.setAttribute(attr, kv) }
  708. }
  709.  
  710. function hideTabBtn(tabBtn) {
  711. let isActiveBefore = tabBtn.classList.contains('active');
  712. tabBtn.classList.add("tab-btn-hidden");
  713. if (isActiveBefore) {
  714. setToActiveTab();
  715. }
  716. }
  717.  
  718. function hasAttribute(obj, key) {
  719. return obj && obj.hasAttribute(key);
  720. }
  721.  
  722. function isTheater() {
  723. const cssElm = kRef(ytdFlexy);
  724. return (cssElm && cssElm.hasAttribute('theater'))
  725. }
  726.  
  727. function isFullScreen() {
  728. const cssElm = kRef(ytdFlexy);
  729. return (cssElm && cssElm.hasAttribute('fullscreen'))
  730. }
  731.  
  732. function isChatExpand() {
  733. const cssElm = kRef(ytdFlexy);
  734. return cssElm && cssElm.hasAttribute('userscript-chatblock') && !cssElm.hasAttribute('userscript-chat-collapsed')
  735. }
  736.  
  737. function isWideScreenWithTwoColumns() {
  738. const cssElm = kRef(ytdFlexy);
  739. return (cssElm && cssElm.hasAttribute('is-two-columns_'))
  740. }
  741.  
  742. function isAnyActiveTab() {
  743. return $('#right-tabs .tab-btn.active').length > 0
  744. }
  745.  
  746. function isEngagementPanelExpanded() { //note: not checking the visual elements
  747. const cssElm = kRef(ytdFlexy);
  748. return (cssElm && +cssElm.getAttribute('userscript-engagement-panel') > 0)
  749. }
  750.  
  751. function engagement_panels_() {
  752.  
  753. let res = [];
  754. let shownRes = [];
  755.  
  756. let v = 0,
  757. k = 1,
  758. count = 0;
  759. for (const ePanel of document.querySelectorAll(
  760. `ytd-watch-flexy ytd-engagement-panel-section-list-renderer[o3r-${sa_epanel}]`
  761. )) {
  762.  
  763. let visibility = ePanel.getAttribute('visibility') //ENGAGEMENT_PANEL_VISIBILITY_EXPANDED //ENGAGEMENT_PANEL_VISIBILITY_HIDDEN
  764.  
  765. switch (visibility) {
  766. case 'ENGAGEMENT_PANEL_VISIBILITY_EXPANDED':
  767. v |= k;
  768. count++;
  769. shownRes.push(ePanel)
  770. res.push({ ePanel, k, visible: true });
  771. break;
  772. case 'ENGAGEMENT_PANEL_VISIBILITY_HIDDEN':
  773. res.push({ ePanel, k, visible: false });
  774. break;
  775. default:
  776. res.push({ ePanel, k, visible: false });
  777. }
  778.  
  779. k = k << 1;
  780.  
  781. }
  782. return { list: res, value: v, count: count, shownRes };
  783. }
  784.  
  785.  
  786. function ytBtnOpenEngagementPanel(panel_id) {
  787.  
  788. if (typeof panel_id == 'string') {
  789. panel_id = panel_id.replace('#engagement-panel-', '');
  790. panel_id = parseInt(panel_id);
  791. }
  792. if (panel_id >= 0) {} else return false;
  793.  
  794. let panels = engagement_panels_();
  795.  
  796. for (const { ePanel, k, visible } of panels.list) {
  797. if ((panel_id & k) === k) {
  798. if (!visible) ePanel.setAttribute('visibility', "ENGAGEMENT_PANEL_VISIBILITY_EXPANDED");
  799. } else {
  800. if (visible) ytBtnCloseEngagementPanel(ePanel);
  801. }
  802. }
  803.  
  804. }
  805.  
  806. function ytBtnCloseEngagementPanel(s) {
  807. //ePanel.setAttribute('visibility',"ENGAGEMENT_PANEL_VISIBILITY_HIDDEN");
  808. let btn = s.querySelector('ytd-watch-flexy ytd-engagement-panel-title-header-renderer #header>#visibility-button>ytd-button-renderer');
  809. if (btn) {
  810. btn.click();
  811. }
  812. }
  813.  
  814. function ytBtnCloseEngagementPanels() {
  815. if (isEngagementPanelExpanded()) {
  816. for (const s of document.querySelectorAll(
  817. `ytd-watch-flexy ytd-engagement-panel-section-list-renderer[o3r-${sa_epanel}]`
  818. )) {
  819. if (s.getAttribute('visibility') == "ENGAGEMENT_PANEL_VISIBILITY_EXPANDED") ytBtnCloseEngagementPanel(s);
  820. }
  821. }
  822. }
  823.  
  824. function ytBtnSetTheater() {
  825. if (!isTheater()) {
  826. const sizeBtn = document.querySelector('ytd-watch-flexy #ytd-player button.ytp-size-button')
  827. if (sizeBtn) sizeBtn.click();
  828. }
  829. }
  830.  
  831. function ytBtnCancelTheater() {
  832. if (isTheater()) {
  833. const sizeBtn = document.querySelector('ytd-watch-flexy #ytd-player button.ytp-size-button')
  834. if (sizeBtn) sizeBtn.click();
  835. }
  836. }
  837.  
  838. function ytBtnExpandChat() {
  839. let button = document.querySelector('ytd-live-chat-frame#chat[collapsed]>.ytd-live-chat-frame#show-hide-button')
  840. if (button) button.querySelector('ytd-toggle-button-renderer').click();
  841. }
  842.  
  843. function ytBtnCollapseChat() {
  844. let button = document.querySelector('ytd-live-chat-frame#chat:not([collapsed])>.ytd-live-chat-frame#show-hide-button')
  845. if (button) button.querySelector('ytd-toggle-button-renderer').click();
  846. }
  847.  
  848. /*
  849. function hackImgShadow(imgShadow) {
  850. // add to #columns and add back after loaded
  851. let img = imgShadow.querySelector('img')
  852. if (!img) return;
  853.  
  854. let p = imgShadow.parentNode
  855. let z = $(imgShadow).clone()[0]; //to occupy the space
  856. p.replaceChild(z, imgShadow)
  857. $(imgShadow).prependTo('#columns'); // refer to css hack
  858.  
  859. function onload(evt) {
  860. if (evt) this.removeEventListener('load', onload, false)
  861. p.replaceChild(imgShadow, z)
  862. p = null;
  863. z = null;
  864. imgShadow = null;
  865. }
  866.  
  867. if (img.complete) onload();
  868. else img.addEventListener('load', onload, false)
  869. }
  870. */
  871.  
  872.  
  873. const Q = {}
  874. const FOnce = {}
  875.  
  876. const $callOnce = function(key) {
  877. if (FOnce[key] && FOnce[key]() === false) FOnce[key] = null
  878. }
  879. const $callOnceAsync = async function(key) {
  880. if (FOnce[key] && FOnce[key]() === false) FOnce[key] = null
  881. }
  882.  
  883.  
  884.  
  885. function chatFrameContentDocument() {
  886. // non-null if iframe exist && contentDocument && readyState = complete
  887.  
  888. let iframe = document.querySelector('ytd-live-chat-frame iframe#chatframe');
  889. if (!iframe) return null; //iframe must be there
  890. let cDoc = null;
  891. try {
  892. cDoc = iframe.contentDocument;
  893. } catch (e) {}
  894. if (!cDoc) return null;
  895. if (cDoc.readyState != 'complete') return null; //we must wait for its completion
  896.  
  897. return cDoc;
  898.  
  899. }
  900.  
  901. function chatFrameElement(cssSelector) {
  902. let cDoc = chatFrameContentDocument();
  903. if (!cDoc) return null;
  904. let elm = null;
  905. try {
  906. elm = cDoc.querySelector(cssSelector)
  907. } catch (e) {
  908. console.log('iframe error', e)
  909. }
  910. return elm;
  911. }
  912.  
  913.  
  914.  
  915.  
  916. function fixTabs() {
  917.  
  918.  
  919. if (!scriptEnable) return;
  920.  
  921.  
  922. let queryElement = document.querySelector('*:not(#tab-videos)>#related:not([non-placeholder-videos]) > ytd-watch-next-secondary-results-renderer')
  923.  
  924. let isRelocated = !!queryElement;
  925.  
  926.  
  927.  
  928. if (isRelocated) {
  929.  
  930. let relocatedRelated = queryElement.parentNode; // NOT NULL
  931.  
  932. let right_tabs = document.querySelector('#right-tabs');
  933. let tab_videos = right_tabs.querySelector("#tab-videos");
  934.  
  935. if (!right_tabs || !tab_videos) return;
  936.  
  937. for (const s of relocatedRelated.querySelectorAll('#related')) {
  938. s.setAttribute('non-placeholder-videos', '')
  939. }
  940.  
  941. let target_container = document.querySelector('ytd-watch-flexy:not([is-two-columns_]) #primary-inner, ytd-watch-flexy[is-two-columns_] #secondary-inner')
  942.  
  943. if (target_container) target_container.append(right_tabs) // last-child
  944.  
  945.  
  946. let videos_related = relocatedRelated; // NOT NULL
  947. $('[placeholder-videos]').removeAttr('placeholder-videos');
  948. $('[placeholder-for-youtube-play-next-queue]').removeAttr('placeholder-for-youtube-play-next-queue');
  949.  
  950. tab_videos.appendChild(videos_related);
  951. let videos_results_renderer = relocatedRelated.querySelector("ytd-watch-next-secondary-results-renderer");
  952. if (videos_results_renderer) videos_results_renderer.setAttribute('data-dom-changed-by-tabview-youtube', scriptVersionForExternal);
  953. videos_related.setAttribute('placeholder-for-youtube-play-next-queue', '')
  954. videos_related.setAttribute('placeholder-videos', '')
  955.  
  956. $('[placeholder-videos]').on("scroll", makeBodyScrollByEvt);
  957.  
  958.  
  959.  
  960.  
  961. }
  962.  
  963.  
  964.  
  965.  
  966. let chatroom = null;
  967. if (chatroom = document.querySelector('*:not([data-positioner="before|#chat"]) + ytd-live-chat-frame#chat, ytd-live-chat-frame#chat:first-child')) {
  968.  
  969. let positioner = document.querySelector('tabview-youtube-positioner[data-positioner="before|#chat"]');
  970. if (positioner) positioner.remove();
  971.  
  972.  
  973. if (document.querySelector('.YouTubeLiveFilledUpView')) {
  974. // no relocation
  975. } else {
  976.  
  977. $(chatroom).insertBefore('#right-tabs')
  978.  
  979. }
  980.  
  981.  
  982. $(positioner ? positioner : document.createElement('tabview-youtube-positioner')).attr('data-positioner', 'before|#chat').insertBefore(chatroom)
  983.  
  984.  
  985.  
  986. }
  987.  
  988.  
  989. }
  990.  
  991. function handlerAutoCompleteExist() {
  992.  
  993.  
  994. let autoComplete = this;
  995.  
  996. autoComplete.removeEventListener('autocomplete-sc-exist', handlerAutoCompleteExist, false)
  997.  
  998. let domId = autoComplete.getAttribute('data-autocomplete-input-id')
  999. let searchBox = autoComplete.ownerDocument.querySelector(`[data-autocomplete-results-id="${domId}"]`)
  1000.  
  1001. if (!domId || !searchBox) return;
  1002.  
  1003. let positioner = searchBox.nextSibling;
  1004. if (positioner && positioner.nodeName.toLowerCase() == "autocomplete-positioner") {} else if (positioner && positioner.nodeName.toLowerCase() != "autocomplete-positioner") {
  1005. $(positioner = document.createElement("autocomplete-positioner")).insertAfter(searchBox);
  1006. } else {
  1007. $(positioner = document.createElement("autocomplete-positioner")).prependTo(searchBox.parentNode);
  1008. }
  1009. $(autoComplete).prependTo(positioner);
  1010.  
  1011. positioner.style.setProperty('--sb-margin-bottom', getComputedStyle(searchBox).marginBottom)
  1012. positioner.style.setProperty('--height', searchBox.offsetHeight + 'px')
  1013.  
  1014. }
  1015.  
  1016. function mtf_fixAutoCompletePosition(elmAutoComplete) {
  1017.  
  1018.  
  1019. elmAutoComplete.setAttribute('autocomplete-disable-updatesc', '')
  1020. elmAutoComplete.addEventListener('autocomplete-sc-exist', handlerAutoCompleteExist, false)
  1021.  
  1022. if(document.querySelector('script#userscript-tabview-injection-facp')) return;
  1023. if (isMyScriptInChromeRuntime()){
  1024. addScriptByURL(window.chrome.runtime.getURL('js/injectionScript_fixAutoComplete.js')).id = 'userscript-tabview-injection-facp';;
  1025. } else {
  1026. let injection_script = GM_getResourceText("injectionFixAutoComplete")
  1027. addScript(`${injection_script}`).id = 'userscript-tabview-injection-facp';;
  1028. }
  1029.  
  1030. }
  1031.  
  1032. function mtf_AfterFixTabs() {
  1033.  
  1034.  
  1035. let ytdFlexyElm = kRef(ytdFlexy);
  1036. if (!scriptEnable || !ytdFlexyElm) return;
  1037.  
  1038. const rootElement = Q.mutationTarget || ytdFlexyElm;
  1039.  
  1040.  
  1041.  
  1042. const autocomplete = rootElement.querySelector('[placeholder-for-youtube-play-next-queue] input#suggestions-search + autocomplete-positioner > .autocomplete-suggestions[data-autocomplete-input-id]:not([position-fixed-by-tabview-youtube])')
  1043.  
  1044. if (autocomplete) {
  1045.  
  1046. const searchBox = document.querySelector('[placeholder-for-youtube-play-next-queue] input#suggestions-search')
  1047.  
  1048.  
  1049. if (searchBox) {
  1050.  
  1051.  
  1052. autocomplete.parentNode.setAttribute('position-fixed-by-tabview-youtube', '');
  1053. autocomplete.setAttribute('position-fixed-by-tabview-youtube', '');
  1054. autocomplete.setAttribute('userscript-scrollbar-render', '')
  1055.  
  1056. if (!searchBox.hasAttribute('is-set-click-to-toggle')) {
  1057. searchBox.setAttribute('is-set-click-to-toggle', '')
  1058. searchBox.addEventListener('click', function() {
  1059.  
  1060.  
  1061. setTimeout(() => {
  1062. const autocomplete = document.querySelector(`.autocomplete-suggestions[data-autocomplete-input-id="${ this.getAttribute('data-autocomplete-results-id') }"]`)
  1063.  
  1064. if (!autocomplete) return;
  1065.  
  1066. const isNotEmpty = (autocomplete.textContent || '').length > 0 && (this.value || '').length > 0;
  1067.  
  1068. if (isNotEmpty) {
  1069.  
  1070. let elmVisible = isDOMVisible(autocomplete)
  1071.  
  1072. if (elmVisible) $(autocomplete).hide();
  1073. else $(autocomplete).show();
  1074.  
  1075. }
  1076.  
  1077. }, 20);
  1078.  
  1079. })
  1080.  
  1081. let timeoutOnce_searchbox_keyup = new Timeout();
  1082. searchBox.addEventListener('keyup', function() {
  1083.  
  1084. timeoutOnce_searchbox_keyup.set(() => {
  1085.  
  1086. const autocomplete = document.querySelector(`.autocomplete-suggestions[data-autocomplete-input-id="${ this.getAttribute('data-autocomplete-results-id') }"]`)
  1087.  
  1088. if (!autocomplete) return;
  1089.  
  1090.  
  1091. const isNotEmpty = (autocomplete.textContent || '').length > 0 && (this.value || '').length > 0
  1092.  
  1093. if (isNotEmpty) {
  1094.  
  1095. let elmVisible = isDOMVisible(autocomplete)
  1096.  
  1097. if (!elmVisible) $(autocomplete).show();
  1098.  
  1099. }
  1100.  
  1101. }, 20);
  1102.  
  1103. })
  1104.  
  1105. }
  1106.  
  1107.  
  1108.  
  1109. }
  1110.  
  1111. }
  1112.  
  1113.  
  1114.  
  1115.  
  1116. let currentLastVideo = rootElement.querySelector('[placeholder-videos] #items ytd-compact-video-renderer:last-of-type')
  1117. let prevLastVideo = kRef(_cachedLastVideo);
  1118.  
  1119. if (prevLastVideo !== currentLastVideo && currentLastVideo) {
  1120. _cachedLastVideo = mWeakRef(currentLastVideo);
  1121. }
  1122.  
  1123. if (prevLastVideo !== currentLastVideo && currentLastVideo && prevLastVideo) {
  1124.  
  1125. let isPrevRemoved = !prevLastVideo.parentNode
  1126.  
  1127.  
  1128. function getVideoListHash() {
  1129.  
  1130. let res = [...document.querySelectorAll('[placeholder-videos] #items ytd-compact-video-renderer')].map(renderer => {
  1131. return renderer.querySelector('a[href*="watch"][href*="v="]').getAttribute('href')
  1132.  
  1133. }).join('|')
  1134. // /watch?v=XXXXX|/watch?v=XXXXXX|/watch?v=XXXXXX
  1135.  
  1136. // alternative - DOM.data.videoId
  1137. // let elms = document.querySelectorAll('[placeholder-videos] #items ytd-compact-video-renderer')
  1138. // let res = [...elms].map(elm=>elm.data.videoId||'').join('|') ;
  1139.  
  1140. if (res.indexOf('||') >= 0) {
  1141. res = '';
  1142. }
  1143.  
  1144. return res ? res : null;
  1145. }
  1146.  
  1147. if (isPrevRemoved) {
  1148.  
  1149. // this is the replacement of videos instead of addition
  1150.  
  1151. const searchBox = document.querySelector('[placeholder-for-youtube-play-next-queue] input#suggestions-search')
  1152.  
  1153. let currentPlayListHash = getVideoListHash() || null;
  1154.  
  1155. if (!currentPlayListHash) {
  1156.  
  1157. } else if (!videoListBeforeSearch && searchBox) {
  1158.  
  1159. videoListBeforeSearch = currentPlayListHash;
  1160. if (videoListBeforeSearch) {
  1161. //console.log('fromSearch', videoListBeforeSearch)
  1162.  
  1163. requestAnimationFrame(function() {
  1164.  
  1165. let renderer = document.querySelector('[placeholder-videos] ytd-watch-next-secondary-results-renderer');
  1166. if (searchBox && searchBox.parentNode) searchBox.blur();
  1167.  
  1168. if (renderer) {
  1169. let scrollParent = renderer.parentNode;
  1170. if (scrollParent.scrollHeight > scrollParent.offsetHeight) {
  1171. let targetTop = renderer.offsetTop;
  1172. if (searchBox && searchBox.parentNode == scrollParent) targetTop -= searchBox.offsetHeight
  1173. scrollParent.scrollTop = targetTop - scrollParent.firstChild.offsetTop;
  1174. }
  1175. }
  1176.  
  1177. });
  1178.  
  1179. }
  1180.  
  1181. } else if (videoListBeforeSearch) {
  1182.  
  1183. if (currentPlayListHash != videoListBeforeSearch) {
  1184.  
  1185. videoListBeforeSearch = null;
  1186. //console.log('fromSearch', videoListBeforeSearch)
  1187.  
  1188.  
  1189. }
  1190.  
  1191. }
  1192.  
  1193.  
  1194. }
  1195.  
  1196.  
  1197. }
  1198.  
  1199.  
  1200.  
  1201.  
  1202. }
  1203.  
  1204. function base_ChatExist() {
  1205.  
  1206. let ytdFlexyElm = kRef(ytdFlexy);
  1207. if (!scriptEnable || !ytdFlexyElm) return null;
  1208.  
  1209. // no mutation triggering if the changes are inside the iframe
  1210.  
  1211. // 1) Detection of #continuations inside iframe
  1212. // iframe ownerDocument is accessible due to same origin
  1213. // if the chatroom is collasped, no determination of live chat or replay (as no #continuations and somehow a blank iframe doc)
  1214.  
  1215. // 2) Detection of meta tag
  1216. // This is fastest but not reliable. It is somehow a bug that the navigation might not update the meta tag content
  1217.  
  1218. // 3) Detection of HTMLElement inside video player for live video
  1219.  
  1220. // (1)+(3) = solution
  1221.  
  1222. let attr_chatblock = null
  1223. let attr_chatcollapsed = null;
  1224.  
  1225. const elmChat = document.querySelector('ytd-live-chat-frame#chat')
  1226. let elmCont = null;
  1227. if (elmChat) {
  1228. elmCont = chatFrameElement('yt-live-chat-renderer #continuations')
  1229.  
  1230.  
  1231. let s = 0;
  1232. if (elmCont) {
  1233. //not found if it is collasped.
  1234. s |= elmCont.querySelector('yt-timed-continuation') ? 1 : 0;
  1235. s |= elmCont.querySelector('yt-live-chat-replay-continuation, yt-player-seek-continuation') ? 2 : 0;
  1236. //s |= elmCont.querySelector('yt-live-chat-restricted-participation-renderer')?4:0;
  1237. if (s == 1) {
  1238. attr_chatblock = 'chat-live';
  1239. }else if (s == 2) attr_chatblock = 'chat-playback';
  1240.  
  1241. if (s == 1) $("span#tab3-txt-loader").text('');
  1242.  
  1243. } else if (!ytdFlexyElm.hasAttribute('userscript-chatblock')) {
  1244. // live chat frame but type not known
  1245. attr_chatblock = '';
  1246.  
  1247. }
  1248. //keep unknown as original
  1249. let isCollapsed = !!elmChat.hasAttribute('collapsed');
  1250. attr_chatcollapsed = isCollapsed;
  1251.  
  1252. } else {
  1253. attr_chatblock = false;
  1254. attr_chatcollapsed = false;
  1255.  
  1256. }
  1257.  
  1258. return { attr_chatblock, attr_chatcollapsed }
  1259.  
  1260. }
  1261.  
  1262.  
  1263. function mtf_ChatExist() {
  1264.  
  1265. let ytdFlexyElm = kRef(ytdFlexy);
  1266. if (!scriptEnable || !ytdFlexyElm) return;
  1267.  
  1268. if (deferredVarYTDHidden) return;
  1269.  
  1270. const elmChat = document.querySelector('ytd-live-chat-frame#chat')
  1271. let elmCont = null;
  1272. if (elmChat) {
  1273. elmCont = chatFrameElement('yt-live-chat-renderer #continuations')
  1274. }
  1275.  
  1276. const chatBlockR = (elmChat ? 1 : 0) + (elmCont ? 2 : 0)
  1277. if (Q.mtf_chatBlockQ !== chatBlockR) {
  1278. Q.mtf_chatBlockQ = chatBlockR
  1279. let rChatExist = base_ChatExist();
  1280. //console.log(2446, rChatExist)
  1281. if (rChatExist) {
  1282. let { attr_chatblock, attr_chatcollapsed } = rChatExist;
  1283. wAttr(ytdFlexyElm, 'userscript-chatblock', attr_chatblock)
  1284. wAttr(ytdFlexyElm, 'userscript-chat-collapsed', attr_chatcollapsed)
  1285. if(attr_chatblock=='chat-live') _disableComments();
  1286. }
  1287. }
  1288.  
  1289. }
  1290.  
  1291.  
  1292.  
  1293.  
  1294. let lastScrollAt1 = 0;
  1295.  
  1296. function makeBodyScrollByEvt() {
  1297. let ct = Date.now();
  1298. if (ct - lastScrollAt1 < 6) return; // avoid duplicate calling
  1299. lastScrollAt1 = ct;
  1300. window.dispatchEvent(new Event("scroll")); // dispatch Scroll Event to Window for content display
  1301. }
  1302.  
  1303. let lastScrollAt2 = 0;
  1304.  
  1305. function makeBodyScroll() {
  1306. let ct = Date.now();
  1307. if (ct - lastScrollAt2 < 30) return; // avoid over triggering
  1308. lastScrollAt2 = ct;
  1309. requestAnimationFrame(() => {
  1310. window.dispatchEvent(new Event("scroll")); // ask youtube to display content
  1311. })
  1312. }
  1313.  
  1314. //let requestingComments = null
  1315. //let scrollForComments_lastStart = 0;
  1316. /*
  1317. function scrollForComments_TF() {
  1318. let comments = requestingComments;
  1319. if (!comments) return;
  1320. if (comments.hasAttribute('hidden')) {
  1321. window.dispatchEvent(new Event("scroll"));
  1322. } else requestingComments = null;
  1323.  
  1324. }
  1325. function scrollForComments() {
  1326. scrollForComments_TF();
  1327. if (!requestingComments) return;
  1328. requestAnimationFrame(scrollForComments_TF);
  1329. let ct = Date.now();
  1330. if (ct - scrollForComments_lastStart < 60) return;
  1331. scrollForComments_lastStart = ct;
  1332. timeline.setTimeout(scrollForComments_TF, 80);
  1333. timeline.setTimeout(scrollForComments_TF, 240);
  1334. timeline.setTimeout(scrollForComments_TF, 870);
  1335. }
  1336. */
  1337.  
  1338.  
  1339.  
  1340. const mtoCs = { mtoNav: null, mtoBody: null };
  1341.  
  1342.  
  1343. const mtoVs = {}
  1344.  
  1345. const mutation_target_id_list = ['ytp-caption-window-container', 'items', 'button', 'movie_player', 'player-ads', 'hover-overlays', 'replies'];
  1346. const mutation_target_class_list = ['ytp-panel-menu', 'ytp-endscreen-content'];
  1347.  
  1348. function isMtoOverallSkip(dTarget) {
  1349.  
  1350. if (!dTarget || dTarget.nodeType !== 1) return true;
  1351.  
  1352. if (mutation_target_id_list.includes(dTarget.id)) return true;
  1353.  
  1354. for (const c of dTarget.classList) {
  1355. if (mutation_target_class_list.includes(c)) return true;
  1356. }
  1357.  
  1358. return false;
  1359. }
  1360.  
  1361.  
  1362. const mutation_div_id_ignorelist = [
  1363. 'metadata-line',
  1364. 'ytp-caption-window-container',
  1365. 'top-level-buttons-computed',
  1366. 'microformat',
  1367. 'visibility-button',
  1368. 'info-strings',
  1369. 'action-menu',
  1370. 'reply-button-end'
  1371. ];
  1372.  
  1373. const mutation_div_class_ignorelist = [
  1374. 'badge', 'tp-yt-paper-tooltip', 'ytp-autonav-endscreen-upnext-header',
  1375. 'ytp-bound-time-left', 'ytp-bound-time-right', 'ytp-share-icon',
  1376. 'ytp-tooltip-title', 'annotation', 'ytp-copylink-icon', 'ytd-thumbnail',
  1377. 'paper-ripple',
  1378. //caption
  1379. 'captions-text', 'caption-visual-line', 'ytp-caption-segment', 'ytp-caption-window-container',
  1380. //menu
  1381. 'ytp-playlist-menu-button-text',
  1382.  
  1383. 'ytp-bezel-icon', 'ytp-bezel-text',
  1384. 'dropdown-content',
  1385. 'tp-yt-paper-menu-button', 'tp-yt-iron-dropdown',
  1386.  
  1387. 'ytd-metadata-row-renderer', // #content.ytd-metadata-row-renderer inside each of ytd-metadata-row-renderer (ytd-expander)
  1388. 'ytd-engagement-panel-section-list-renderer', // {div#content.style-scope.ytd-engagement-panel-section-list-renderer} inside each of ytd-engagement-panel-section-list-renderer
  1389.  
  1390. 'autocomplete-suggestions' // autocomplete-suggestions
  1391. ];
  1392.  
  1393. const mutation_target_tag_ignorelist = [
  1394. 'ytd-channel-name', 'tp-yt-iron-dropdown', 'tp-yt-paper-tooltip',
  1395. 'tp-yt-paper-listbox', 'yt-img-shadow', 'ytd-thumbnail', 'ytd-video-meta-block',
  1396.  
  1397. 'yt-icon-button', 'tp-yt-paper-button', 'yt-formatted-string', 'yt-icon', 'button', 'paper-ripple',
  1398.  
  1399. 'ytd-player-microformat-renderer',
  1400. 'ytd-engagement-panel-section-list-renderer', 'ytd-engagement-panel-title-header-renderer',
  1401. 'ytd-comment-renderer', 'ytd-menu-renderer', 'ytd-badge-supported-renderer',
  1402. 'ytd-subscribe-button-renderer', 'ytd-subscription-notification-toggle-button-renderer',
  1403. 'ytd-button-renderer', 'ytd-toggle-button-renderer',
  1404. 'yt-pdg-comment-chip-renderer', 'ytd-comment-action-buttons-renderer', 'ytd-comment-thread-renderer',
  1405. 'ytd-compact-radio-renderer', 'ytd-compact-video-renderer',
  1406. 'ytd-video-owner-renderer',
  1407. 'ytd-metadata-row-renderer', //ytd-metadata-row-renderer is part of the #collapsible inside ytd-expander
  1408.  
  1409. 'ytd-moving-thumbnail-renderer',
  1410. 'ytd-thumbnail-overlay-toggle-button-renderer',
  1411. 'ytd-thumbnail-overlay-bottom-panel-renderer', 'ytd-thumbnail-overlay-equalizer',
  1412. 'ytd-thumbnail-overlay-now-playing-renderer', 'ytd-thumbnail-overlay-resume-playback-renderer',
  1413. 'ytd-thumbnail-overlay-side-panel-renderer', 'ytd-thumbnail-overlay-time-status-renderer',
  1414. 'ytd-thumbnail-overlay-hover-text-renderer',
  1415.  
  1416. 'yt-interaction',
  1417. 'tp-yt-paper-spinner-lite', 'tp-yt-paper-spinner',
  1418.  
  1419. 'h1', 'h2', 'h3', 'h4', 'h5', 'span', 'a',
  1420.  
  1421. 'meta', 'br', 'script', 'style', 'link', 'dom-module', 'template'
  1422. ];
  1423.  
  1424. function isMtoTargetSkip(mutation) {
  1425. //skip not important mutation tartget
  1426.  
  1427. if (!mutation) return true;
  1428. let { type, target } = mutation
  1429.  
  1430. if (!target || target.nodeType !== 1 || type != 'childList') return true;
  1431.  
  1432. let tagName = target.nodeName.toLowerCase();
  1433.  
  1434. if (mutation_target_tag_ignorelist.includes(tagName)) return true;
  1435.  
  1436. switch (tagName) {
  1437.  
  1438.  
  1439. case 'ytd-expander':
  1440. if (target.id == 'expander' && Q.comments_section_loaded == 1 && target.classList.contains('ytd-comment-renderer')) return true; // load comments
  1441. return false;
  1442.  
  1443. case 'div':
  1444.  
  1445. if (target.id == 'contents') {
  1446. return false;
  1447. }
  1448. if (mutation_div_id_ignorelist.includes(target.id)) return true;
  1449.  
  1450. for (const c of target.classList) {
  1451. if (mutation_div_class_ignorelist.includes(c)) return true;
  1452. }
  1453.  
  1454. return false;
  1455.  
  1456. }
  1457.  
  1458. return false;
  1459.  
  1460. }
  1461.  
  1462.  
  1463. function mtf_forceCheckLiveVideo() {
  1464. // once per $$player-playback-timestamp$$ {#ytd-player .ytp-time-display} && $$chat-frame$$ {ytd-live-chat-frame#chat} detection
  1465. // reset after popstatechange / videochange
  1466.  
  1467. if(mtf_forceCheckLiveVideo_disable) return ;
  1468.  
  1469. let ytdFlexyElm = kRef(ytdFlexy);
  1470. if (!scriptEnable || !ytdFlexyElm) return ;
  1471.  
  1472. const rootElement = Q.mutationTarget || ytdFlexyElm;
  1473. const playerLabel = document.querySelector('ytd-watch-flexy:not([hidden]) #ytd-player .ytp-time-display') && document.querySelector('ytd-watch-flexy:not([hidden]) ytd-live-chat-frame#chat')
  1474. if (!playerLabel) return ;
  1475. mtf_forceCheckLiveVideo_disable = 1;
  1476. timeline.setTimeout(FP.fireOnce_forceCheckLiveVideo_tf, 170)
  1477. return ;
  1478. }
  1479.  
  1480. // continuous check for element relocation
  1481. function mtf_append_comments() {
  1482.  
  1483. let ytdFlexyElm = kRef(ytdFlexy);
  1484. if (!scriptEnable || !ytdFlexyElm) return;
  1485.  
  1486. const rootElement = Q.mutationTarget || ytdFlexyElm;
  1487.  
  1488. let comments = rootElement.querySelector('#primary ytd-watch-metadata ~ ytd-comments#comments');
  1489. if (comments) $(comments).appendTo('#tab-comments').attr('data-dom-changed-by-tabview-youtube', scriptVersionForExternal)
  1490. }
  1491.  
  1492. // continuous check for element relocation
  1493. function mtf_liveChatBtnF() {
  1494. let ytdFlexyElm = kRef(ytdFlexy);
  1495. if (!scriptEnable || !ytdFlexyElm) return;
  1496.  
  1497. const rootElement = Q.mutationTarget || ytdFlexyElm;
  1498.  
  1499. let button = rootElement.querySelector('ytd-live-chat-frame#chat>.ytd-live-chat-frame#show-hide-button:nth-child(n+2)');
  1500. if (button) button.parentNode.insertBefore(button, button.parentNode.firstChild)
  1501. }
  1502.  
  1503.  
  1504.  
  1505. // continuous check for element relocation
  1506. // fired at begining & window resize, etc
  1507. function mtf_append_playlist() {
  1508.  
  1509. let ytdFlexyElm = kRef(ytdFlexy);
  1510. if (!scriptEnable || !ytdFlexyElm) return;
  1511.  
  1512. const rootElement = Q.mutationTarget || ytdFlexyElm;
  1513.  
  1514. let ple1 = rootElement.querySelector("*:not(#ytd-userscript-playlist)>ytd-playlist-panel-renderer#playlist");
  1515. if (ple1) {
  1516. let ct = Date.now();
  1517. let truePlaylist = null;
  1518. let truePlaylist_items = document.querySelector('ytd-playlist-panel-renderer#playlist #items:not(:empty)');
  1519. if (truePlaylist_items) {
  1520.  
  1521. let pElm = truePlaylist_items.parentNode;
  1522. while (pElm && pElm.nodeType === 1) {
  1523. if (pElm.id == 'playlist') {
  1524. pElm.setAttribute('tabview-true-playlist', ct)
  1525. truePlaylist = pElm;
  1526. break;
  1527. }
  1528. pElm = pElm.parentNode;
  1529. }
  1530.  
  1531. }
  1532.  
  1533. if (!truePlaylist) truePlaylist = ple1; // NOT NULL
  1534.  
  1535. for (const s of document.querySelectorAll(`*:not(#ytd-userscript-playlist)>ytd-playlist-panel-renderer#playlist:not([tabview-true-playlist="${ct}"])`))
  1536. s.parentNode.removeChild(s);
  1537.  
  1538. let $wrapper = getWrapper('ytd-userscript-playlist')
  1539. $wrapper.append(truePlaylist).appendTo(document.querySelector("#tab-list"));
  1540. truePlaylist.setAttribute('data-dom-changed-by-tabview-youtube', scriptVersionForExternal)
  1541. setDisplayedPlaylist(); // relocation after re-layout
  1542.  
  1543. requestAnimationFrame(() => {
  1544. let ytdFlexyElm = kRef(ytdFlexy);
  1545. if (!scriptEnable || !ytdFlexyElm) return;
  1546. if (!switchTabActivity_lastTab && (ytdFlexyElm.getAttribute('tabview-selection') + '').indexOf('#tab-') === 0 && /https\:\/\/www\.youtube\.com\/watch.*[\?\&]list=[\w\-\_]+/.test(location.href)) {
  1547. if (setToActiveTab('#tab-list')) switchTabActivity_lastTab = '#tab-list';
  1548. }
  1549. })
  1550.  
  1551. }
  1552. }
  1553.  
  1554.  
  1555. // content fix - info & playlist
  1556. // fired at begining, and keep for in case any change
  1557. function mtf_fix_details() {
  1558.  
  1559. if (!scriptEnable) return;
  1560.  
  1561. if (no_fix_contents_until < Date.now()) {
  1562. const content = document.querySelector('#meta-contents ytd-expander>#content, #tab-info ytd-expander>#content')
  1563. if (content) {
  1564. no_fix_contents_until = Date.now() + 3000;
  1565. timeline.setTimeout(function() {
  1566. const expander = content.parentNode;
  1567.  
  1568. if (expander.hasAttribute('collapsed')) wAttr(expander, 'collapsed', false);
  1569. expander.style.setProperty('--ytd-expander-collapsed-height', '');
  1570.  
  1571. let btn1 = expander.querySelector('tp-yt-paper-button#less:not([hidden])');
  1572. let btn2 = expander.querySelector('tp-yt-paper-button#more:not([hidden])');
  1573.  
  1574. if (btn1) wAttr(btn1, 'hidden', true);
  1575. if (btn2) wAttr(btn2, 'hidden', true);
  1576. }, 40);
  1577.  
  1578. }
  1579. }
  1580.  
  1581. if (no_fix_playlist_until < Date.now()) {
  1582. // just in case the playlist is collapsed
  1583. const playlist = document.querySelector('#tab-list ytd-playlist-panel-renderer#playlist')
  1584. if (playlist) {
  1585. no_fix_playlist_until = Date.now() + 3000;
  1586. timeline.setTimeout(function() {
  1587. if (playlist.hasAttribute('collapsed')) wAttr(playlist, 'collapsed', false);
  1588. if (playlist.hasAttribute('collapsible')) wAttr(playlist, 'collapsible', false);
  1589. }, 40)
  1590. }
  1591. }
  1592.  
  1593.  
  1594. }
  1595.  
  1596.  
  1597.  
  1598. function isNullComments() {
  1599.  
  1600. let comments = document.querySelector('ytd-comments#comments')
  1601. if (!comments || comments.hasAttribute('hidden')) return true;
  1602.  
  1603. }
  1604.  
  1605.  
  1606. function getFMT(ytdFlexyElm) {
  1607.  
  1608.  
  1609. let fmt = ["ytd-comments#comments #count.ytd-comments-header-renderer", 'ytd-item-section-renderer#sections #header ~ #contents>ytd-message-renderer'].map(s => {
  1610.  
  1611. let elm = ytdFlexyElm.querySelector(s)
  1612. if (!elm) return null;
  1613. return elm.querySelector('yt-formatted-string') || elm.closest('yt-formatted-string') || null
  1614.  
  1615.  
  1616. });
  1617.  
  1618. return fmt
  1619. }
  1620.  
  1621. function toFST(elm) {
  1622. if (!elm) return null;
  1623. return elm.querySelector('yt-formatted-string') || elm.closest('yt-formatted-string') || null
  1624. }
  1625.  
  1626. function _innerCommentsLoader(rootElement) {
  1627.  
  1628. let ytdFlexyElm = kRef(ytdFlexy);
  1629. if (!scriptEnable || !ytdFlexyElm) return;
  1630. if (deferredVarYTDHidden) return;
  1631.  
  1632.  
  1633. let messageElm, messageStr, commentRenderer;
  1634. let diffCSS = `[tabview-cache-time="${sect_hTime}"]`
  1635.  
  1636. if (commentRenderer = rootElement.querySelector(`ytd-comments#comments #count.ytd-comments-header-renderer:not(${diffCSS})`)) {
  1637.  
  1638. scheduledCommentRefresh=false;
  1639. let eTime = Date.now();
  1640.  
  1641. sect_holder = mWeakRef(commentRenderer);
  1642. sect_hText = commentRenderer.textContent;
  1643. sect_hTime = eTime;
  1644. commentRenderer.setAttribute('tabview-cache-time', eTime);
  1645.  
  1646. return {
  1647. status: 1,
  1648. f: () => {
  1649.  
  1650. let span = document.querySelector("span#tab3-txt-loader")
  1651. let r = '0';
  1652. let txt = commentRenderer.textContent
  1653. if (typeof txt == 'string') {
  1654. let m = txt.match(/[\d\,\s]+/)
  1655. if (m) {
  1656. r = m[0].trim()
  1657.  
  1658.  
  1659. }
  1660. }
  1661. if (span){
  1662.  
  1663. let tab_btn = span.closest('.tab-btn[userscript-tab-content="#tab-comments"]')
  1664. if(tab_btn)tab_btn.setAttribute('loaded-comment','normal')
  1665. span.textContent = r;
  1666. }
  1667. //console.log(754)
  1668. mtoInterval = mtoInterval2;
  1669. scheduledCommentRefresh=false;
  1670. setCommentSection(1);
  1671. comments_section_loaded_elm = mWeakRef(document.querySelector('ytd-comments#comments div#contents'))
  1672. }
  1673. }
  1674.  
  1675. } else if ((messageElm = rootElement.querySelector(`ytd-item-section-renderer#sections #header ~ #contents > ytd-message-renderer:not(${diffCSS})`)) && (messageStr = (messageElm.textContent || '').trim())) { //ytd-message-renderer
  1676. // it is possible to get the message before the header generation.
  1677. // sample link - https://www.youtube.com/watch?v=PVUZ8Nvr1ic
  1678. // sample link - https://www.youtube.com/watch?v=yz8AiQc1Bk8
  1679.  
  1680. scheduledCommentRefresh=false;
  1681. let eTime = Date.now();
  1682.  
  1683. sect_holder = mWeakRef(messageElm);
  1684. sect_hText = messageElm.textContent;
  1685. sect_hTime = eTime;
  1686. messageElm.setAttribute('tabview-cache-time', eTime);
  1687.  
  1688. return {
  1689. status: 2,
  1690. f: () => {
  1691. timeline.setTimeout(function() {
  1692. let span = document.querySelector("span#tab3-txt-loader")
  1693. const mainMsg = messageElm.querySelector('#message, #submessage')
  1694. if (mainMsg && mainMsg.textContent) {
  1695. for (const msg of mainMsg.querySelectorAll('*:not(:empty)')) {
  1696. if (msg.childElementCount === 0 && msg.textContent) {
  1697. messageStr = msg.textContent.trim()
  1698. break
  1699. }
  1700. }
  1701. }
  1702. if (span){
  1703. let tab_btn = span.closest('.tab-btn[userscript-tab-content="#tab-comments"]')
  1704. if(tab_btn)tab_btn.setAttribute('loaded-comment','message')
  1705. span.textContent ='\u200B';
  1706. }
  1707. mtoInterval = mtoInterval2;
  1708. scheduledCommentRefresh=false;
  1709. setCommentSection(1);
  1710. comments_section_loaded_elm = mWeakRef(document.querySelector('ytd-comments#comments div#contents'))
  1711. }, 40);
  1712. }
  1713. }
  1714.  
  1715. }
  1716.  
  1717. }
  1718.  
  1719. const atChange = async ()=>{
  1720.  
  1721. // call when video change / popstate change / switch back from mini-view
  1722.  
  1723. let ytdFlexyElm = kRef(ytdFlexy);
  1724. if(!ytdFlexyElm) return;
  1725.  
  1726. mtf_forceCheckLiveVideo_disable = 0;
  1727. mtf_forceCheckLiveVideo();
  1728.  
  1729. if(Q.comments_section_loaded===0){
  1730.  
  1731. const tabBtn = document.querySelector('[userscript-tab-content="#tab-comments"].tab-btn-hidden')
  1732. if(tabBtn) {
  1733. tabBtn.classList.remove("tab-btn-hidden") //if contains
  1734. }
  1735.  
  1736. }
  1737. }
  1738.  
  1739.  
  1740.  
  1741. function hookSection(){
  1742.  
  1743.  
  1744. //console.log(3300)
  1745.  
  1746. let ytdFlexyElm = kRef(ytdFlexy);
  1747. if (!scriptEnable || !ytdFlexyElm) return ;
  1748.  
  1749. const comments = ytdFlexyElm.querySelector('ytd-comments#comments')
  1750. if (!comments) return ;
  1751.  
  1752. if(deferredVarYTDHidden) return;
  1753.  
  1754. //console.log(3310)
  1755.  
  1756. //new MutationObserver(function(){console.log(comments.querySelectorAll('*').length)}).observe(comments,{ attributes: true, childList: true, subtree: true })
  1757.  
  1758. function foundSection(sections){
  1759.  
  1760. //console.log(3320)
  1761.  
  1762. function ulfx() {
  1763. //console.log(1220)
  1764.  
  1765.  
  1766. const rootElement = comments.parentNode
  1767.  
  1768.  
  1769. if (pendingOne && comments.querySelectorAll('[tabview-cache-time]').length > 1) return;
  1770. pendingOne = false;
  1771. if(!rootElement) return; //prevent unknown condition
  1772.  
  1773.  
  1774. let innerCommentsLoaderRet = _innerCommentsLoader(rootElement);
  1775.  
  1776. //console.log(1222,_innerCommentsLoader)
  1777.  
  1778. if (!innerCommentsLoaderRet) {
  1779.  
  1780.  
  1781. let holder = kRef(sect_holder);
  1782. if (holder && comments.contains(holder)) {
  1783.  
  1784. if (sect_lastUpdate) return;
  1785. sect_lastUpdate = 1;
  1786.  
  1787. timeline.setTimeout(function() {
  1788. //console.log(2633)
  1789. if (holder.textContent !== sect_hText && sect_hTime > 0) {
  1790.  
  1791. if (comments.querySelectorAll('[tabview-cache-time]').length === 1) {
  1792.  
  1793. sect_hTime--;
  1794.  
  1795. let innerCommentsLoaderRet = _innerCommentsLoader(rootElement);
  1796.  
  1797. if (innerCommentsLoaderRet) {
  1798. //console.log(9442)
  1799. innerCommentsLoaderRet.f();
  1800. fetchCommentsFinished();
  1801. }
  1802.  
  1803. pendingOne = false;
  1804.  
  1805. }
  1806.  
  1807.  
  1808. }
  1809. sect_lastUpdate = 0
  1810. }, 400)
  1811.  
  1812. } else if (sect_holder) {
  1813. sect_holder = null
  1814. sect_hTime = 0;
  1815. sect_lastUpdate = 0;
  1816. pendingOne = false;
  1817. timeline.setTimeout(()=>{
  1818. if(!deferredVarYTDHidden && scheduledCommentRefresh && Q.comments_section_loaded>0 && comments.hasAttribute('hidden')){
  1819.  
  1820. scheduledCommentRefresh=false; // logic tbc
  1821. resetCommentSection();
  1822. }
  1823. },142);
  1824. Q.mutationTarget=null;
  1825. FP.mtf_attrComments(); // in case for popstate
  1826. }
  1827.  
  1828.  
  1829. } else {
  1830.  
  1831. //console.log(9443)
  1832. innerCommentsLoaderRet.f();
  1833. fetchCommentsFinished();
  1834.  
  1835. pendingOne = true;
  1836.  
  1837. }
  1838.  
  1839.  
  1840.  
  1841. }
  1842.  
  1843. function observerHook(mutationsList, observer){
  1844.  
  1845. let valid = false
  1846. for (const mutation of mutationsList) {
  1847.  
  1848. let target = mutation.target;
  1849. if (!target) break;
  1850. if (!target.id) break;
  1851. let classList = target.classList;
  1852.  
  1853.  
  1854. if (
  1855. classList.contains('ytd-item-section-renderer') ||
  1856. classList.contains('ytd-comments-header-renderer') ||
  1857. classList.contains('ytd-message-renderer')) {
  1858. valid = true
  1859. break;
  1860. }
  1861.  
  1862. break; // only outest mutation
  1863.  
  1864.  
  1865. }
  1866. if (valid) ulfx();
  1867. }
  1868.  
  1869. if(sections.hasAttribute('tabview-comment-section-checked')){
  1870.  
  1871. //console.log(3612)
  1872. ulfx();
  1873.  
  1874. }else{
  1875.  
  1876. pendingOne = false;
  1877. //console.log(3611)
  1878. const observer = new MutationObserver(observerHook)
  1879. sections.setAttribute('tabview-comment-section-checked','')
  1880. const config = { childList: true, subtree: true };
  1881. observer.observe(sections, config);
  1882. ulfx();
  1883.  
  1884.  
  1885. }
  1886.  
  1887.  
  1888.  
  1889. }
  1890. //console.log(3241, location.href)
  1891. let cid_render_section = timeline.setInterval(function() {
  1892.  
  1893. // console.log(3244, location.href)
  1894.  
  1895.  
  1896. const rootElement = comments.parentNode
  1897.  
  1898. let sections = rootElement.querySelector('ytd-comments#comments > ytd-item-section-renderer#sections');
  1899.  
  1900.  
  1901. if (sections) {
  1902.  
  1903. timeline.clearInterval(cid_render_section);
  1904. foundSection(sections);
  1905.  
  1906. }
  1907.  
  1908. }, 30)
  1909.  
  1910.  
  1911.  
  1912. }
  1913.  
  1914.  
  1915. let mtc_store=0;
  1916. let mtc_cid = 0;
  1917. const cssOnceFunc = {
  1918. [`ytd-comments#comments:not([o3r-${sa_comments}])`]:(comments)=>{
  1919. // once per {ytd-comments#comments} detection
  1920.  
  1921. let ytdFlexyElm = kRef(ytdFlexy);
  1922. if (!scriptEnable || !ytdFlexyElm) return;
  1923.  
  1924. if (!comments) return;
  1925.  
  1926.  
  1927.  
  1928.  
  1929. if(mtoVisibility_Comments.bindElement(comments)){
  1930. mtoVisibility_Comments.observer.check(9);
  1931. }
  1932. pageInit_attrComments = true
  1933. hookSection();
  1934.  
  1935. //let dComments = comments
  1936. //timeline.setTimeout(() => nativeFunc(dComments, "loadComments"), 20)
  1937. //comments = null;
  1938.  
  1939. },
  1940. [`ytd-playlist-panel-renderer#playlist:not([o3r-${sa_playlist}])`]:(playlist)=>{
  1941.  
  1942. // once per {ytd-playlist-panel-renderer#playlist} detection
  1943.  
  1944. let ytdFlexyElm = kRef(ytdFlexy);
  1945. if (!scriptEnable || !ytdFlexyElm) return;
  1946.  
  1947. if (!playlist) return;
  1948.  
  1949. if(mtoVisibility_Playlist.bindElement(playlist)){
  1950. mtoVisibility_Playlist.observer.check(9) //delay check required for browser bug - hidden changed not triggered
  1951. }
  1952. playlist = null;
  1953.  
  1954. return;
  1955.  
  1956. },
  1957. '#meta-contents ytd-expander:not([tabview-info-expander])':(expander)=>{
  1958.  
  1959. // once per $$native-info-description$$ {#meta-contents ytd-expander} detection
  1960.  
  1961. let ytdFlexyElm = kRef(ytdFlexy);
  1962. if (!scriptEnable || !ytdFlexyElm) return ;
  1963.  
  1964. if (!expander) return ;
  1965. expander.setAttribute('tabview-info-expander','')
  1966. $(expander).appendTo("#tab-info").attr('data-dom-changed-by-tabview-youtube', scriptVersionForExternal)
  1967.  
  1968. },
  1969. }
  1970. const cssOnce = Object.keys(cssOnceFunc).join(', ')
  1971.  
  1972. const regularCheck = (addP, removeP, mutationTarget)=>{
  1973.  
  1974.  
  1975. let isInvalidAdding = mutationTarget && !mutationTarget.parentNode
  1976.  
  1977. let promisesForAddition = !scriptEnable ? [] : addP > 0 && !isInvalidAdding ? [
  1978.  
  1979. (async () => {
  1980.  
  1981. //$callOnce('mtf_checkFlexy');
  1982.  
  1983. const rootElement = Q.mutationTarget || kRef(ytdFlexy);
  1984.  
  1985. if(rootElement){
  1986.  
  1987. let fElms = rootElement.querySelectorAll(cssOnce)
  1988. if(fElms.length>0){
  1989.  
  1990. for(const fElm of fElms){
  1991. for(let cssSelctor in cssOnceFunc){
  1992. if(fElm.matches(cssSelctor)){
  1993. let f= cssOnceFunc[cssSelctor]
  1994. if(typeof f=='function') f(fElm);
  1995. break;
  1996. }
  1997.  
  1998. }
  1999. }
  2000.  
  2001. //$callOnce('mtf_initalAttr_comments');
  2002. //$callOnce('mtf_initalAttr_playlist');
  2003. // $callOnce('mtf_checkDescriptionLoaded');
  2004. }
  2005.  
  2006. }
  2007.  
  2008. })(),
  2009. (async () => {
  2010.  
  2011.  
  2012. FP.mtf_initalAttr_chatroom();
  2013. FP.mtf_initalAttr_engagement_panel();
  2014. //$callOnce('mtf_initalAttr_chatroom');
  2015. // $callOnce('mtf_initalAttr_engagement_panel');
  2016.  
  2017. mtf_forceCheckLiveVideo();
  2018. mtf_append_comments();
  2019. mtf_liveChatBtnF();
  2020. fixTabs();
  2021. mtf_AfterFixTabs();
  2022. mtf_append_playlist();
  2023.  
  2024. })()
  2025.  
  2026. ] : [];
  2027. let promisesForEveryMutation = !scriptEnable ? [] : [
  2028. (async () => {
  2029. mtf_fix_details();
  2030. mtf_ChatExist();
  2031. })()
  2032. ];
  2033.  
  2034. return [...promisesForAddition, ...promisesForEveryMutation]
  2035.  
  2036.  
  2037. }
  2038.  
  2039. function setOnlyOneEPanel(ePanel){
  2040.  
  2041. layoutStatusMutex.lockWith(unlock => {
  2042.  
  2043. let cPanels = engagement_panels_();
  2044. for (const entry of cPanels.list) {
  2045. if (entry.ePanel != ePanel && entry.visible) ytBtnCloseEngagementPanel(entry.ePanel);
  2046. }
  2047. setTimeout(unlock, 30)
  2048.  
  2049. })
  2050.  
  2051. }
  2052.  
  2053. const FP = {
  2054.  
  2055. mtoNav_delayedF: () => {
  2056.  
  2057. let { addP, removeP, mutationTarget } = Q;
  2058.  
  2059. Q.addP = 0;
  2060. Q.removeP = 0;
  2061. mtc_store=Date.now()+1870
  2062.  
  2063.  
  2064. let regularChecks = regularCheck(addP, removeP, mutationTarget);
  2065.  
  2066. Promise.all(regularChecks).then(() => {
  2067. regularChecks = null;
  2068. mtc_store= Date.now() + 3870 // pending Comments start to load
  2069. Q.mutationTarget = null;
  2070.  
  2071. Q.mtoNav_requestNo--;
  2072. //console.log('motnav reduced to', mtoNav_requestNo)
  2073. if (Q.mtoNav_requestNo > 0) {
  2074. Q.mtoNav_requestNo = 1;
  2075. setTimeout(FP.mtoNav_delayedF, mtoInterval);
  2076. }
  2077. })
  2078.  
  2079.  
  2080. },
  2081.  
  2082. mtoNavF: (mutations, observer) => {
  2083. //subtree DOM mutation checker - {ytd-watch-flexy} \single \subtree
  2084.  
  2085. newVideoPageCheck()
  2086.  
  2087. if (!scriptEnable) return;
  2088. if (deferredVarYTDHidden) return;
  2089.  
  2090. let ch = false;
  2091.  
  2092. let reg = [];
  2093. let dTarget = null;
  2094.  
  2095. let wAddP = 0,
  2096. wRemoveP = 0;
  2097.  
  2098. let _last_mto_target = null;
  2099. let _last_mto_target_valid = null;
  2100.  
  2101. for (const mutation of mutations) {
  2102. if (!mutation || !mutation.target || !mutation.target.parentNode) continue;
  2103.  
  2104. let elementalMutation = false;
  2105. let tAddP = 0,
  2106. tRemoveP = 0;
  2107.  
  2108. for (const addedNode of mutation.addedNodes) { //theoretically faster: only reading of states
  2109. if (addedNode.nodeType === 1) {
  2110. tAddP++;
  2111. elementalMutation = true;
  2112. }
  2113. }
  2114.  
  2115. for (const removedNode of mutation.removedNodes) { //theoretically faster: only reading of states
  2116. if (removedNode.nodeType === 1) {
  2117. tRemoveP++;
  2118. elementalMutation = true;
  2119. }
  2120. }
  2121.  
  2122. if (elementalMutation) { //skip all addition and removal operations without elemental changes (e.g. textNode modification)
  2123.  
  2124. if (_last_mto_target === mutation.target) {
  2125. // due to addition and removal operations to the same DOM
  2126. if (_last_mto_target_valid) {
  2127. // AddP & RemoveP is still valid
  2128. wAddP += tAddP;
  2129. wRemoveP += tRemoveP;
  2130. }
  2131. continue;
  2132. }
  2133. _last_mto_target = mutation.target;
  2134.  
  2135. if (isMtoTargetSkip(mutation)) {
  2136. _last_mto_target_valid = false;
  2137. continue; //theoretically slower: creation of string variables
  2138. } else {
  2139. _last_mto_target_valid = true;
  2140. wAddP += tAddP;
  2141. wRemoveP += tRemoveP;
  2142. }
  2143.  
  2144.  
  2145.  
  2146. ch = true;
  2147.  
  2148. reg.push(mutation);
  2149.  
  2150. if (dTarget === null) dTarget = mutation.target; //first
  2151. else if (dTarget === true) {} //ytdFlexy
  2152. else if (dTarget.contains(mutation.target)) {} //first node is the container to all subsequential targets
  2153. else { dTarget = true; } //the target is not the child of first node
  2154.  
  2155. }
  2156.  
  2157. }
  2158.  
  2159. if (!ch) return; // dTarget must be true OR HTMLElement
  2160.  
  2161. if (dTarget === true) dTarget = kRef(ytdFlexy); // major mutation occurance
  2162. else if (dTarget === kRef(comments_section_loaded_elm) && wAddP > wRemoveP) return true; // ignore if comments are loaded (adding comments)
  2163. else if (isMtoOverallSkip(dTarget)) return; // allow for multiple mutations at the same time - determinated after looping
  2164.  
  2165.  
  2166.  
  2167. // 4 ~ 16 times per full page loading
  2168.  
  2169. Q.addP += wAddP;
  2170. Q.removeP += wRemoveP;
  2171.  
  2172. if (Q.mutationTarget === null) Q.mutationTarget = dTarget;
  2173. else if (Q.mutationTarget != dTarget) Q.mutationTarget = kRef(ytdFlexy);
  2174.  
  2175. //console.log(prettyElm(dTarget), wAddP , wRemoveP, mtoInterval)
  2176. //console.log(prettyElm(dTarget), reg.map(m=>prettyElm(m.target)))
  2177. //console.log(7015, performance.now())
  2178.  
  2179.  
  2180.  
  2181. Q.mtoNav_requestNo++;
  2182. if (Q.mtoNav_requestNo == 1) setTimeout(FP.mtoNav_delayedF, mtoInterval);
  2183.  
  2184. },
  2185.  
  2186.  
  2187. mtoBodyF: function(mutations, observer) {
  2188. //subtree DOM mutation checker - {body} \single \subtree
  2189.  
  2190. if (!scriptEnable) return;
  2191. if (deferredVarYTDHidden) return;
  2192.  
  2193. for (const mutation of mutations) {
  2194. for (const addedNode of mutation.addedNodes)
  2195. if (addedNode.nodeType === 1) {
  2196. if (addedNode.nodeName == "DIV" && addedNode.matches('.autocomplete-suggestion:not([autocomplete-disable-updatesc])') ) {
  2197. mtf_fixAutoCompletePosition(addedNode)
  2198. }else if(addedNode.nodeName == "DIV" && (addedNode.id==='lyricscontainer' || addedNode.id==='showlyricsbutton')){
  2199.  
  2200. goYoutubeGeniusLyrics();
  2201.  
  2202. }
  2203. }
  2204. }
  2205.  
  2206. },
  2207.  
  2208. mtf_attrPlaylist: (attrName, newValue) => {
  2209. //attr mutation checker - {ytd-playlist-panel-renderer#playlist} \single
  2210. //::attr ~ hidden
  2211. //console.log(1210)
  2212.  
  2213. if (!scriptEnable) return;
  2214. if (deferredVarYTDHidden) return;
  2215. let cssElm = kRef(ytdFlexy);
  2216. if (!cssElm) return;
  2217.  
  2218. let playlist = document.querySelector('ytd-playlist-panel-renderer#playlist')
  2219. const tabBtn = document.querySelector('[userscript-tab-content="#tab-list"]');
  2220. let isPlaylistHidden = playlist.hasAttribute('hidden')
  2221. //console.log(1212.2, isPlaylistHidden, playlist.getAttribute('hidden'))
  2222. if (tabBtn) {
  2223. //console.log('attr playlist changed')
  2224. if (tabBtn.classList.contains('tab-btn-hidden') && !isPlaylistHidden) {
  2225. //console.log('attr playlist changed - no hide')
  2226. tabBtn.classList.remove("tab-btn-hidden");
  2227. } else if (!tabBtn.classList.contains('tab-btn-hidden') && isPlaylistHidden) {
  2228. //console.log('attr playlist changed - add hide')
  2229. hideTabBtn(tabBtn);
  2230. }
  2231. }
  2232. /* visible layout for triggering hidden removal */
  2233. akAttr(cssElm, 'tabview-youtube-playlist', isPlaylistHidden);
  2234. },
  2235. mtf_attrComments: (attrName, newValue) => {
  2236. //attr mutation checker - {ytd-comments#comments} \single
  2237. //::attr ~ hidden
  2238.  
  2239. let ytdFlexyElm = kRef(ytdFlexy);
  2240. if (!scriptEnable || !ytdFlexyElm) return;
  2241. if (deferredVarYTDHidden) return;
  2242.  
  2243. let comments = document.querySelector('ytd-comments#comments')
  2244. const tabBtn = document.querySelector('[userscript-tab-content="#tab-comments"]');
  2245. if (!comments || !tabBtn) return;
  2246. let isCommentHidden = comments.hasAttribute('hidden')
  2247. //console.log('attr comments changed')
  2248.  
  2249. mtoInterval = mtoInterval1;
  2250. mtc_store=Date.now()+2870
  2251.  
  2252. if( mtf_forceCheckLiveVideo_disable === 2 ){
  2253.  
  2254. }else if (!isCommentHidden) {
  2255.  
  2256. akAttr(ytdFlexyElm, 'tabview-youtube-comments', false, 'K');
  2257.  
  2258.  
  2259.  
  2260. //console.log('attr comments changed - no hide')
  2261. tabBtn.classList.remove("tab-btn-hidden") //if contains
  2262.  
  2263. //console.log(703)
  2264.  
  2265. mtc_cid&&timeline.clearInterval(mtc_cid);
  2266.  
  2267. } else if (isCommentHidden) {
  2268.  
  2269. akAttr(ytdFlexyElm, 'tabview-youtube-comments', true, 'K');
  2270. timeline.setTimeout(function(){
  2271. if(!deferredVarYTDHidden && scheduledCommentRefresh && Q.comments_section_loaded>0 && comments.hasAttribute('hidden')){
  2272. //console.log(3434)
  2273. scheduledCommentRefresh=false; //logic tbc
  2274. resetCommentSection();
  2275. //console.log(8022)
  2276. }
  2277. },142)
  2278.  
  2279. if(!mtc_cid) mtc_cid=timeline.setInterval(()=>{
  2280. if(mtc_store>Date.now()) return;
  2281. timeline.clearInterval(mtc_cid)
  2282. mtc_cid=0;
  2283. if(mtf_forceCheckLiveVideo_disable===2)return;
  2284. if(isNullComments()) _disableComments();
  2285.  
  2286. },80)
  2287.  
  2288. }
  2289.  
  2290.  
  2291. },
  2292.  
  2293.  
  2294. mtf_attrChatroom: (attrName, newValue) => {
  2295. //attr mutation checker - {ytd-live-chat-frame#chat} \single
  2296. //::attr ~ collapsed
  2297.  
  2298. let ytdFlexyElm = kRef(ytdFlexy);
  2299. if (!scriptEnable || !ytdFlexyElm) return;
  2300. if (deferredVarYTDHidden) return;
  2301.  
  2302. layoutStatusMutex.lockWith(unlock => {
  2303.  
  2304. const chatBlock = document.querySelector('ytd-live-chat-frame#chat')
  2305. const cssElm = kRef(ytdFlexy)
  2306.  
  2307. if (!chatBlock || !cssElm) {
  2308. unlock();
  2309. return;
  2310. }
  2311.  
  2312. if (deferredVarYTDHidden) {
  2313. unlock();
  2314. return;
  2315. }
  2316.  
  2317. if (!cssElm.hasAttribute('userscript-chatblock')) wAttr(cssElm, 'userscript-chatblock', true);
  2318. let isCollapsed = !!chatBlock.hasAttribute('collapsed');
  2319. wAttr(cssElm, 'userscript-chat-collapsed', isCollapsed);
  2320.  
  2321. if (cssElm.hasAttribute('userscript-chatblock') && !isCollapsed) lastShowTab = '#chatroom';
  2322.  
  2323. if (!isCollapsed && document.querySelector('#right-tabs .tab-btn.active') && isWideScreenWithTwoColumns() && !isTheater()) {
  2324. switchTabActivity(null);
  2325. timeline.setTimeout(unlock, 40);
  2326. } else {
  2327. unlock();
  2328. }
  2329.  
  2330. if (!isCollapsed) {
  2331. runAfterExpandChat();
  2332. } else {
  2333. chatBlock.removeAttribute('yt-userscript-iframe-loaded');
  2334. }
  2335.  
  2336. })
  2337.  
  2338.  
  2339.  
  2340.  
  2341. },
  2342.  
  2343. mtf_attrEngagementPanel: (mutations, observer) => {
  2344. //attr mutation checker - {ytd-engagement-panel-section-list-renderer} \mutiple
  2345. //::attr ~ visibility
  2346.  
  2347. let ytdFlexyElm = kRef(ytdFlexy);
  2348. if (!scriptEnable || !ytdFlexyElm) return;
  2349.  
  2350. //multiple instance
  2351. if (mutations) {
  2352. for (const mutation of mutations) {
  2353. let ePanel = mutation.target;
  2354. if (ePanel.getAttribute('visibility') == 'ENGAGEMENT_PANEL_VISIBILITY_EXPANDED') {
  2355. setOnlyOneEPanel(ePanel);
  2356. break;
  2357. }
  2358. }
  2359. }
  2360. if (deferredVarYTDHidden) return;
  2361.  
  2362. layoutStatusMutex.lockWith(unlock => {
  2363.  
  2364. const ePanel = document.querySelector('ytd-watch-flexy ytd-engagement-panel-section-list-renderer')
  2365. const cssElm = kRef(ytdFlexy)
  2366.  
  2367. if (!ePanel || !cssElm) {
  2368. unlock();
  2369. return;
  2370. }
  2371. let previousValue = +cssElm.getAttribute('userscript-engagement-panel') || 0;
  2372.  
  2373. let { shownRes, value, count } = engagement_panels_();
  2374. let nextValue = value;
  2375. let nextCount = count;
  2376.  
  2377.  
  2378. if (nextCount == 0 && cssElm.hasAttribute('userscript-engagement-panel')) {
  2379. storeLastPanel=null;
  2380. wAttr(cssElm, 'userscript-engagement-panel', false);
  2381. unlock();
  2382. } else {
  2383.  
  2384. if ((nextCount > 1) || (cssElm.hasAttribute('userscript-engagement-panel') && previousValue === nextValue)) {
  2385. unlock();
  2386. return;
  2387. }
  2388.  
  2389. cssElm.setAttribute('userscript-engagement-panel', nextValue);
  2390.  
  2391. let b = false;
  2392. if (previousValue != nextValue && nextValue > 0) {
  2393. lastShowTab = `#engagement-panel-${nextValue}`;
  2394. b = true;
  2395. storeLastPanel = mWeakRef( shownRes[0])
  2396. //console.log(9999, shownRes[0])
  2397. }
  2398.  
  2399. if (b && document.querySelector('#right-tabs .tab-btn.active') && isWideScreenWithTwoColumns() && !isTheater()) {
  2400. switchTabActivity(null);
  2401. timeline.setTimeout(unlock, 40);
  2402. } else {
  2403. unlock();
  2404. }
  2405. }
  2406.  
  2407. })
  2408.  
  2409.  
  2410.  
  2411.  
  2412. },
  2413.  
  2414. mtf_initalAttr_playlist: () => {
  2415. },
  2416.  
  2417. mtf_initalAttr_comments: () => {
  2418. },
  2419.  
  2420. mtf_initalAttr_chatroom: () => {
  2421. // every per [new] {ytd-live-chat-frame#chat} detection - reset after mini-playview
  2422. let ytdFlexyElm = kRef(ytdFlexy);
  2423. if (!scriptEnable || !ytdFlexyElm) return true;
  2424.  
  2425. const rootElement = Q.mutationTarget || ytdFlexyElm;
  2426.  
  2427.  
  2428. if (!mgChatFrame.inPage()) {
  2429.  
  2430. mtoVisibility_Chatroom.clear(true);
  2431.  
  2432. let chatroom = rootElement.querySelector(`ytd-live-chat-frame#chat:not([${sa_chatroom}]`)
  2433. if (chatroom) {
  2434. mgChatFrame.setVar(chatroom);
  2435.  
  2436. if(mtoVisibility_Chatroom.bindElement(chatroom)){
  2437. mtoVisibility_Chatroom.observer.check(9)
  2438. }
  2439.  
  2440. chatroom = null
  2441. }
  2442. }
  2443. return true;
  2444.  
  2445. },
  2446.  
  2447. mtf_initalAttr_engagement_panel: () => {
  2448. // every per $$non-checked-section-list$$ {ytd-watch-flexy ytd-engagement-panel-section-list-renderer:not([o3r-XXXXX])} detection
  2449. let ytdFlexyElm = kRef(ytdFlexy);
  2450. if (!scriptEnable || !ytdFlexyElm) return true;
  2451.  
  2452. const rootElement = Q.mutationTarget || ytdFlexyElm;
  2453.  
  2454. let toCheck = false;
  2455. for (const engagement_panel of rootElement.querySelectorAll(
  2456. `ytd-watch-flexy ytd-engagement-panel-section-list-renderer:not([o3r-${sa_epanel}])`
  2457. )) {
  2458.  
  2459.  
  2460.  
  2461. let bindRes = mtoVisibility_EngagementPanel.bindElement(engagement_panel, {
  2462. attributes: true,
  2463. attributeFilter: ['visibility'],
  2464. attributeOldValue: true
  2465. })
  2466.  
  2467. if(bindRes) toCheck = true;
  2468. }
  2469.  
  2470. if (toCheck) FP.mtf_attrEngagementPanel()
  2471.  
  2472. return true;
  2473. },
  2474.  
  2475.  
  2476.  
  2477. //live-chat / chat-replay
  2478.  
  2479. fireOnce_forceCheckLiveVideo_tf: () => {
  2480. // once per $$player-playback-timestamp$$ {#ytd-player .ytp-time-display} && $$chat-frame$$ {ytd-live-chat-frame#chat} detection
  2481.  
  2482. let ytdFlexyElm = kRef(ytdFlexy);
  2483. if (!scriptEnable || !ytdFlexyElm) return;
  2484.  
  2485. let elm = document.querySelector('#ytd-player .ytp-time-display');
  2486. if (elm && elm.classList.contains('ytp-live')) {
  2487. //console.log(7006)
  2488. ytdFlexyElm.setAttribute('userscript-chatblock', 'chat-live')
  2489. //console.log(2441)
  2490. mtf_forceCheckLiveVideo_disable = 2;
  2491. _disableComments();
  2492. //console.log(701)
  2493. //disableComments_LiveChat();
  2494. }
  2495. },
  2496.  
  2497.  
  2498. //comments
  2499. /*
  2500. mtf_advancedComments: () => {
  2501. // once per {ytd-comments#comments #continuations} detection
  2502.  
  2503. //let ytdFlexyElm = kRef(ytdFlexy);
  2504. //if (!scriptEnable || !ytdFlexyElm) return true;
  2505.  
  2506. //const rootElement = Q.mutationTarget || ytdFlexyElm;
  2507. //const continuations = document.querySelector("ytd-comments#comments #continuations");
  2508. //if (!continuations) return true;
  2509. //requestingComments = document.querySelector('ytd-comments#comments');
  2510. //scrollForComments();
  2511. return false;
  2512. }
  2513. */
  2514.  
  2515.  
  2516. }
  2517.  
  2518.  
  2519.  
  2520.  
  2521.  
  2522. let displayedPlaylist = null;
  2523. let scrollingVideosList = null;
  2524.  
  2525. let scriptEnable = false;
  2526. let scriptEC = 0;
  2527. let lastShowTab = null;
  2528.  
  2529. let _cachedLastVideo = null;
  2530. let videoListBeforeSearch = null;
  2531. let no_fix_contents_until = 0;
  2532. let no_fix_playlist_until = 0;
  2533. let statusCollasped = 0;
  2534.  
  2535. let ytdFlexy = null;
  2536.  
  2537. function pluginUnhook() {
  2538. _pluginUnhook()
  2539.  
  2540. resetCommentSection();
  2541.  
  2542. }
  2543.  
  2544. function _pluginUnhook() {
  2545.  
  2546. sect_lastUpdate = 0;
  2547. sect_holder = null;
  2548. sect_hTime = 0;
  2549.  
  2550. //console.log(8001)
  2551.  
  2552. videoListBeforeSearch = null;
  2553. statusCollasped = 0;
  2554. _cachedLastVideo = null;
  2555. lastShowTab = null;
  2556. displayedPlaylist = null;
  2557. scrollingVideosList = null;
  2558. scriptEnable = false;
  2559. scriptEC++;
  2560. if (scriptEC > 788888888) scriptEC = 188888888;
  2561. ytdFlexy = null;
  2562. wls.layoutStatus = null;
  2563.  
  2564. //console.log('unc01')
  2565.  
  2566. mtoVisibility_EngagementPanel.clear(true)
  2567. mtoVisibility_Playlist.clear(true)
  2568. mtoVisibility_Comments.clear(true)
  2569.  
  2570. mgChatFrame.kVar = null;
  2571. mtoVisibility_Chatroom.clear(true)
  2572. mtoFlexyAttr.clear(true)
  2573.  
  2574.  
  2575. for (const elem of document.querySelectorAll(
  2576. ['ytd-expander[tabview-info-expander]'].join(', ')
  2577. )) {
  2578. elem.removeAttribute('tabview-info-expander');
  2579. }
  2580.  
  2581. mtoMutation_body.clear(true)
  2582. mtoMutation_watchFlexy.clear(true)
  2583. //FOnce.mtf_checkFlexy = null;
  2584. //FOnce.mtf_initalAttr_comments = null;
  2585. //FOnce.mtf_initalAttr_playlist = null;
  2586. //FOnce.mtf_initalAttr_chatroom = null;
  2587. //FOnce.mtf_initalAttr_engagement_panel = null;
  2588. //FOnce.mtf_advancedComments = null;
  2589. //FOnce.mtf_checkDescriptionLoaded = null;
  2590. //FOnce.mtf_forceCheckLiveVideo = null;
  2591. Q.mtf_chatBlockQ = null;
  2592.  
  2593.  
  2594. mtoInterval = mtoInterval1;
  2595.  
  2596. }
  2597.  
  2598. let comments_section_loaded_elm = null;
  2599.  
  2600.  
  2601.  
  2602. function getTabsHTML() {
  2603.  
  2604. const sTabBtnVideos = `${svgElm(16,16,298,298,svgVideos)}<span>Videos</span>`
  2605. const sTabBtnInfo = `${svgElm(16,16,23.625,23.625,svgInfo)}<span>Info</span>`
  2606. const sTabBtnPlayList = `${svgElm(16,16,426.667,426.667,svgPlayList)}<span>Playlist</span>`
  2607.  
  2608. let str1 = `
  2609. <paper-ripple class="style-scope yt-icon-button">
  2610. <div id="background" class="style-scope paper-ripple" style="opacity:0;"></div>
  2611. <div id="waves" class="style-scope paper-ripple"></div>
  2612. </paper-ripple>
  2613. `;
  2614.  
  2615. const str_tabs = [
  2616. `<a id="tab-btn1" data-name="info" userscript-tab-content="#tab-info" class="tab-btn">${sTabBtnInfo}${str1}</a>`,
  2617. `<a id="tab-btn3" userscript-tab-content="#tab-comments" data-name="comments" class="tab-btn">${svgElm(16,16,60,60,svgComments)}<span id="tab3-txt-loader"></span>${str1}</a>`,
  2618. `<a id="tab-btn4" userscript-tab-content="#tab-videos" data-name="videos" class="tab-btn">${sTabBtnVideos}${str1}</a>`,
  2619. `<a id="tab-btn5" userscript-tab-content="#tab-list" class="tab-btn">${sTabBtnPlayList}${str1}</a>`
  2620. ].join('')
  2621.  
  2622. let addHTML = `
  2623. <div id="right-tabs">
  2624. <header>
  2625. <div id="material-tabs">
  2626. ${str_tabs}
  2627. </div>
  2628. </header>
  2629. <div class="tab-content">
  2630. <div id="tab-info" class="tab-content-cld tab-content-hidden" userscript-scrollbar-render></div>
  2631. <div id="tab-comments" class="tab-content-cld tab-content-hidden" userscript-scrollbar-render></div>
  2632. <div id="tab-videos" class="tab-content-cld tab-content-hidden" userscript-scrollbar-render></div>
  2633. <div id="tab-list" class="tab-content-cld tab-content-hidden" userscript-scrollbar-render></div>
  2634. </div>
  2635. </div>
  2636. `;
  2637.  
  2638. return addHTML
  2639.  
  2640. }
  2641.  
  2642.  
  2643. function onVideoChange() {
  2644. // for popstate & next video
  2645.  
  2646. newVideoPageCheck();
  2647.  
  2648. scheduledCommentRefresh=true;
  2649. let comments = document.querySelector('ytd-comments#comments')
  2650. if(!deferredVarYTDHidden && scheduledCommentRefresh && Q.comments_section_loaded>0 && comments.hasAttribute('hidden')){
  2651.  
  2652. scheduledCommentRefresh=false;
  2653. // comment tab btn - hide by timer in attribute change
  2654. resetCommentSection();
  2655. }
  2656.  
  2657. mtf_forceCheckLiveVideo_disable = 0
  2658. mtc_store= Date.now()+3870
  2659.  
  2660. if (deferredVarYTDHidden) { // reset info when hidden
  2661. resetCommentSection();
  2662. }else{
  2663. checkVisibleEngagementPanel();
  2664. atChange(); // in case no mutation occurance
  2665. }
  2666.  
  2667.  
  2668.  
  2669. }
  2670.  
  2671. function onNavigationEnd(evt) {
  2672. newVideoPageCheck(); // required for init
  2673.  
  2674. let mRet =
  2675. (/^https?\:\/\/(\w+\.)*youtube\.com\/watch\?(\w+\=[^\/\?\&]+\&|\w+\=?\&)*v=[\w\-\_]+/.test(window.location.href) ? 1 : 0) +
  2676. (document.querySelector('ytd-watch-flexy[tabview-selection]') ? 2 : 0);
  2677.  
  2678. if (mRet === 1) {
  2679.  
  2680. document.addEventListener('loadedmetadata', function(evt) {
  2681. if (evt.target.matches('video[tabview-mainvideo]')) {
  2682. setTimeout(onVideoChange, 30)
  2683. }
  2684. }, true)
  2685.  
  2686. pluginUnhook(); // in case not triggered by popstate - say mini playing
  2687.  
  2688. let timeout = 4; // max. 4 animation frames
  2689.  
  2690. let tf = () => {
  2691.  
  2692. if (--timeout > 0 && !document.querySelector('#player video')) return requestAnimationFrame(tf);
  2693.  
  2694. if (!document.querySelector('script#userscript-tabview-injection-1')) {
  2695.  
  2696. if (isMyScriptInChromeRuntime()){
  2697.  
  2698. addScriptByURL(window.chrome.runtime.getURL('js/injection_script_1.js')).id = 'userscript-tabview-injection-1';
  2699. }
  2700. else{
  2701.  
  2702. let injection_script = GM_getResourceText("injectionJS1")
  2703. addScript(`${injection_script}`).id = 'userscript-tabview-injection-1';
  2704. }
  2705. }
  2706.  
  2707. let ytdFlexyElm = document.querySelector('ytd-watch-flexy')
  2708.  
  2709. if(!ytdFlexyElm) return;
  2710.  
  2711.  
  2712. scriptEnable = true;
  2713. scriptEC++;
  2714.  
  2715. no_fix_contents_until = 0;
  2716. no_fix_playlist_until = 0;
  2717.  
  2718. ytdFlexy = mWeakRef(ytdFlexyElm)
  2719.  
  2720. let timeoutR_findRelated = new Timeout();
  2721. timeoutR_findRelated.set(function() {
  2722. let ytdFlexyElm = kRef(ytdFlexy);
  2723. if(!ytdFlexyElm) return true;
  2724. let related = ytdFlexyElm.querySelector("#related");
  2725. if (!related) return true;
  2726. foundRelated(related);
  2727. }, 100, 10)
  2728.  
  2729. function foundRelated(related) {
  2730. let promise = Promise.resolve();
  2731. if (!document.querySelector("#right-tabs")) {
  2732. promise = promise.then(() => {
  2733. $(getTabsHTML()).insertBefore(related).attr('data-dom-created-by-tabview-youtube', scriptVersionForExternal);
  2734. })
  2735. }
  2736. promise.then(runAfterTabAppended)
  2737. }
  2738.  
  2739. /*
  2740. setTimeout(() => {
  2741. for (const s of document.querySelectorAll('#right-tabs [userscript-scrollbar-render]')) {
  2742. Promise.resolve(s).then(s => {
  2743. if (s && s.scrollTop > 0) s.scrollTop = 0;
  2744. let child = s.firstElementChild;
  2745. if (child && child.scrollTop > 0) child.scrollTop = 0;
  2746. });
  2747. }
  2748. }, 90)
  2749. */
  2750.  
  2751.  
  2752. }
  2753.  
  2754. tf();
  2755.  
  2756. } else if (mRet === 3) {
  2757.  
  2758. if(!scriptEnable) return;
  2759.  
  2760. let elmComments = document.querySelector('ytd-comments#comments')
  2761.  
  2762. if (elmComments) {
  2763. nativeFunc(elmComments, "loadComments")
  2764. }
  2765.  
  2766. } else if (mRet === 0) {
  2767.  
  2768. pluginUnhook(); // in case not triggered by popstate - say mini playing
  2769.  
  2770. }
  2771.  
  2772. if(mRet & 1){
  2773. setTimeout(()=>{
  2774. Q.mutationTarget=null;
  2775. atChange(); // in case no mutation occurance
  2776. FP.mtf_attrComments()
  2777. },160);
  2778. }
  2779.  
  2780. }
  2781.  
  2782.  
  2783. function setToActiveTab(defaultTab) {
  2784. if (isTheater() && isWideScreenWithTwoColumns()) return;
  2785. const jElm = document.querySelector(`a[userscript-tab-content="${switchTabActivity_lastTab}"]:not(.tab-btn-hidden)`) ||
  2786. document.querySelector(`a[userscript-tab-content="${(defaultTab||settings.defaultTab)}"]:not(.tab-btn-hidden)`) ||
  2787. document.querySelector("a[userscript-tab-content]:not(.tab-btn-hidden)") ||
  2788. null;
  2789. switchTabActivity(jElm);
  2790. return !!jElm;
  2791. }
  2792.  
  2793. function getWrapper(wrapperId) {
  2794. let $wrapper = $(`#${wrapperId}`);
  2795. if (!$wrapper[0]) $wrapper = $(`<div id="${wrapperId}"></div>`)
  2796. return $wrapper.first();
  2797. }
  2798.  
  2799. function runAfterTabAppended() {
  2800.  
  2801. document.documentElement.setAttribute('plugin-tabview-youtube', '')
  2802.  
  2803. const ytdFlexyElm = kRef(ytdFlexy)
  2804. if(!ytdFlexyElm) return;
  2805. if (!ytdFlexyElm.hasAttribute('tabview-selection')) ytdFlexyElm.setAttribute('tabview-selection', '')
  2806.  
  2807.  
  2808. //console.log('unc02')
  2809.  
  2810. // append the next videos
  2811. // it exists as "related" is already here
  2812. fixTabs();
  2813.  
  2814. // just switch to the default tab
  2815. setToActiveTab();
  2816.  
  2817.  
  2818. prepareTabBtn();
  2819.  
  2820.  
  2821. // append the detailed meta contents to the tab-info
  2822. // ** FOnce.mtf_checkDescriptionLoaded = FP.mtf_checkDescriptionLoaded;
  2823. // ** if (Q.mutationTarget === null) $callOnceAsync('mtf_checkDescriptionLoaded');
  2824.  
  2825. // force window scroll when #continuations is first detected and #comments still [hidden]
  2826. //FOnce.mtf_advancedComments = FP.mtf_advancedComments;
  2827. //if (Q.mutationTarget === null) $callOnceAsync('mtf_advancedComments');
  2828.  
  2829. // use video player's element to detect the live-chat situation (no commenting section)
  2830. // this would be very useful if the live chat is collapsed, i.e. iframe has no indication on the where it is live or replay
  2831. //FOnce.mtf_forceCheckLiveVideo = FP.mtf_forceCheckLiveVideo;
  2832. //if (Q.mutationTarget === null) $callOnceAsync('mtf_forceCheckLiveVideo');
  2833. //mtf_forceCheckLiveVideo();
  2834.  
  2835.  
  2836. // Attr Mutation Observer - #playlist - hidden
  2837. //clearMutationObserver(mtoVs, 'mtoVisibility_Playlist')
  2838. // Attr Mutation Observer callback - #playlist - hidden
  2839.  
  2840. // pending for #playlist and set Attribute Observer
  2841. // ** FOnce.mtf_initalAttr_playlist = FP.mtf_initalAttr_playlist
  2842. // ** if (Q.mutationTarget === null) $callOnceAsync('mtf_initalAttr_playlist');
  2843.  
  2844. // Attr Mutation Observer - ytd-comments#comments - hidden
  2845. //clearMutationObserver(mtoVs, 'mtoVisibility_Comments')
  2846. // Attr Mutation Observer callback - ytd-comments#comments - hidden
  2847.  
  2848. // pending for #comments and set Attribute Observer
  2849. // ** FOnce.mtf_initalAttr_comments = FP.mtf_initalAttr_comments;
  2850. // ** if (Q.mutationTarget === null) $callOnceAsync('mtf_initalAttr_comments');
  2851.  
  2852.  
  2853. //clearMutationObserver(mtoVs, 'mtoVisibility_Chatroom');
  2854. //FOnce.mtf_initalAttr_chatroom = FP.mtf_initalAttr_chatroom
  2855. //if (Q.mutationTarget === null) $callOnceAsync('mtf_initalAttr_chatroom');
  2856.  
  2857. // clearMutationObserver(mtoVs, 'mtoVisibility_EngagementPanel');
  2858. // for (const engagement_panel of document.querySelectorAll('ytd-watch-flexy ytd-engagement-panel-section-list-renderer:not([tabview-attr-checked])')) {
  2859. // engagement_panel.removeAttribute('tabview-attr-checked');
  2860. // }
  2861. //FOnce.mtf_initalAttr_engagement_panel = FP.mtf_initalAttr_engagement_panel
  2862. //if (Q.mutationTarget === null) $callOnceAsync('mtf_initalAttr_engagement_panel');
  2863.  
  2864.  
  2865. mtoFlexyAttr.clear(true)
  2866. mtf_checkFlexy()
  2867.  
  2868.  
  2869. document.querySelector("#right-tabs .tab-content").addEventListener('scroll', makeBodyScrollByEvt, true);
  2870.  
  2871.  
  2872. Q.addP = 0;
  2873. Q.removeP = 0;
  2874. Q.mutationTarget = null;
  2875.  
  2876. Q.mtoNav_requestNo = 0;
  2877.  
  2878.  
  2879. mtoMutation_watchFlexy.bindElement(ytdFlexyElm, {
  2880. childList: true,
  2881. subtree: true,
  2882. attributes: false
  2883. })
  2884.  
  2885. // for automcomplete plugin or other userscript plugins
  2886. // document.body for Firefox >= 60
  2887. mtoMutation_body.bindElement(document.querySelector('body'), {
  2888. childList: true,
  2889. subtree: false,
  2890. attributes: false
  2891. })
  2892.  
  2893.  
  2894. regularCheck(1, 0, null);
  2895.  
  2896.  
  2897.  
  2898.  
  2899. }
  2900.  
  2901.  
  2902. function fetchCommentsFinished() {
  2903. let ytdFlexyElm = kRef(ytdFlexy);
  2904. if (!scriptEnable || !ytdFlexyElm) return;
  2905. if(mtf_forceCheckLiveVideo_disable===2) return;
  2906. akAttr(ytdFlexyElm, 'tabview-youtube-comments', false, 'LS')
  2907. }
  2908.  
  2909. function setCommentSection(value) {
  2910.  
  2911. Q.comments_section_loaded = value;
  2912.  
  2913. if (value === 0) {
  2914. sect_lastUpdate = 0;
  2915. comments_section_loaded_elm = null;
  2916. }
  2917.  
  2918. }
  2919.  
  2920. function resetCommentSection(){
  2921.  
  2922. let tab_btn = document.querySelector('.tab-btn[userscript-tab-content="#tab-comments"]')
  2923.  
  2924.  
  2925. if(tab_btn){
  2926.  
  2927. let span = tab_btn.querySelector('span#tab3-txt-loader');
  2928.  
  2929. tab_btn.removeAttribute('loaded-comment')
  2930. tab_btn.classList.remove('tab-btn-hidden')
  2931. if(span){
  2932. span.textContent='';
  2933. }
  2934. }
  2935.  
  2936.  
  2937. setCommentSection(0);
  2938.  
  2939.  
  2940. }
  2941.  
  2942. function _disableComments() {
  2943. //requestingComments = null;
  2944. mtc_cid && timeline.clearInterval(mtc_cid)
  2945. mtc_cid=0;
  2946.  
  2947. if (!scriptEnable) return;
  2948. let cssElm = kRef(ytdFlexy);
  2949. if (!cssElm) return;
  2950.  
  2951. mtoInterval = mtoInterval2;
  2952.  
  2953. if(Q.comments_section_loaded>0) return; //already displayed / disabled
  2954.  
  2955. scheduledCommentRefresh=false;
  2956. setCommentSection(2);
  2957.  
  2958. comments_section_loaded_elm = mWeakRef(document.querySelector('ytd-comments#comments div#contents') || null)
  2959.  
  2960. let tabBtn = document.querySelector('.tab-btn[userscript-tab-content="#tab-comments"]');
  2961. if(tabBtn) {
  2962. tabBtn.removeAttribute('loaded-comment')
  2963. if (!tabBtn.classList.contains('tab-btn-hidden')) {
  2964. hideTabBtn(tabBtn)
  2965. }
  2966. }
  2967.  
  2968. akAttr(cssElm, 'tabview-youtube-comments', true, 'D');
  2969.  
  2970.  
  2971. }
  2972.  
  2973.  
  2974.  
  2975.  
  2976. let layoutStatusMutex = new Mutex();
  2977.  
  2978. function forceDisplayChatReplay() {
  2979. let items = chatFrameElement('yt-live-chat-item-list-renderer #items');
  2980. if (items && items.childElementCount !== 0) return;
  2981.  
  2982. let ytd_player = document.querySelector('ytd-player#ytd-player');
  2983. if (!ytd_player) return;
  2984. let videoElm = ytd_player.querySelector('video');
  2985. if (!videoElm) return;
  2986.  
  2987. let video = videoElm;
  2988. if (videoElm && video.currentTime > 0 && !video.ended && video.readyState > video.HAVE_CURRENT_DATA) {
  2989. let chat = document.querySelector('ytd-live-chat-frame#chat');
  2990. if (chat) {
  2991. nativeFunc(chat, "postToContentWindow", [{ "yt-player-video-progress": videoElm.currentTime }])
  2992. }
  2993. }
  2994.  
  2995. }
  2996.  
  2997.  
  2998.  
  2999. function runAfterExpandChat() {
  3000.  
  3001.  
  3002. new Promise(resolve => {
  3003.  
  3004. let chatFrame_st = Date.now();
  3005. let cid_chatFrameCheck = 0;
  3006.  
  3007. let sEF = new ScriptEF();
  3008. cid_chatFrameCheck = setInterval(() => {
  3009. if (!sEF.isValid()) return cid_chatFrameCheck = clearInterval(cid_chatFrameCheck);
  3010. let cDoc = chatFrameContentDocument();
  3011. if (cDoc) {
  3012. cid_chatFrameCheck = clearInterval(cid_chatFrameCheck);
  3013. resolve();
  3014. } else if (!scriptEnable || !isChatExpand() || Date.now() - chatFrame_st > 6750) {
  3015. cid_chatFrameCheck = clearInterval(cid_chatFrameCheck);
  3016. }
  3017. }, 60);
  3018.  
  3019.  
  3020. }).then(() => new Promise(resolve => {
  3021.  
  3022. let timeoutR_ChatAppReady = new Timeout();
  3023. timeoutR_ChatAppReady.set(() => {
  3024.  
  3025. if (!scriptEnable || !isChatExpand()) return false;
  3026. let app = chatFrameElement('yt-live-chat-app');
  3027. if (!app) return true;
  3028.  
  3029. timeline.setTimeout(() => resolve(app), 40)
  3030.  
  3031. }, 40, 150); //40*150 = 6000ms = 6s;
  3032.  
  3033. })).then(app => {
  3034.  
  3035.  
  3036. let cDoc = app.ownerDocument;
  3037.  
  3038. if (!scriptEnable || !isChatExpand()) return;
  3039. addStyle(`
  3040. body #input-panel.yt-live-chat-renderer::after {
  3041. background: transparent;
  3042. }
  3043. #items.yt-live-chat-item-list-renderer{
  3044. contain: content;
  3045. }
  3046. yt-live-chat-text-message-renderer{
  3047. contain: content;
  3048. }
  3049. #item-offset.yt-live-chat-item-list-renderer{
  3050. contain: content;
  3051. }
  3052. #item-scroller.yt-live-chat-item-list-renderer{
  3053. contain: strict;
  3054. }
  3055. img[width][height]{
  3056. contain: strict;
  3057. }
  3058. #item-list>yt-live-chat-item-list-renderer, #item-list>yt-live-chat-item-list-renderer>#contents{
  3059. contain: strict;
  3060. }
  3061.  
  3062.  
  3063. #chat.style-scope.yt-live-chat-renderer,
  3064. yt-live-chat-text-message-renderer.style-scope.yt-live-chat-item-list-renderer,
  3065. #item-scroller,
  3066. yt-live-chat-text-message-renderer.style-scope.yt-live-chat-item-list-renderer .style-scope.yt-live-chat-text-message-renderer,
  3067. yt-live-chat-ticker-paid-message-item-renderer
  3068. {
  3069. contain: layout paint style;
  3070. }
  3071. yt-img-shadow#author-photo.style-scope{
  3072. contain: layout paint style;
  3073. content-visibility: auto;
  3074. contain-intrinsic-size: 24px 24px;
  3075. }
  3076. #item-offset.style-scope.yt-live-chat-item-list-renderer,
  3077. #items.style-scope.yt-live-chat-item-list-renderer {
  3078. contain: layout paint;
  3079. }
  3080. .style-scope.yt-live-chat-text-message-renderer {
  3081. cursor: default;
  3082. }
  3083. #author-photo.style-scope.yt-live-chat-text-message-renderer,
  3084. yt-live-chat-author-chip.style-scope.yt-live-chat-text-message-renderer,
  3085. yt-live-chat-author-chip.style-scope.yt-live-chat-text-message-renderer ~ span#message.style-scope.yt-live-chat-text-message-renderer
  3086. {
  3087. pointer-events: none;
  3088. }
  3089. span#message.style-scope.yt-live-chat-text-message-renderer > img.emoji.yt-formatted-string.style-scope.yt-live-chat-text-message-renderer{
  3090. contain: layout paint style;
  3091. cursor: default;
  3092. pointer-events: none;
  3093. }
  3094. body yt-live-chat-app{
  3095. contain: size layout paint style;
  3096. content-visibility: auto;
  3097. transform: translate3d(0,0,0);
  3098. overflow: hidden;
  3099. }
  3100.  
  3101. `, cDoc.documentElement)
  3102.  
  3103. if (cDoc.querySelector('yt-live-chat-renderer #continuations')) {
  3104. timeline.setTimeout(() => mtf_ChatExist(), 40);
  3105. $(document.querySelector('ytd-live-chat-frame#chat')).attr('yt-userscript-iframe-loaded', '')
  3106. }
  3107.  
  3108. forceDisplayChatReplay();
  3109.  
  3110.  
  3111.  
  3112.  
  3113. })
  3114.  
  3115. }
  3116.  
  3117. function flexyAttr_toggleFlag(mFlag, b, flag) {
  3118. if (b) mFlag = mFlag | flag;
  3119. else mFlag = mFlag & ~flag;
  3120. return mFlag;
  3121. }
  3122.  
  3123. function flexAttr_toLayoutStatus(nls, attributeName) {
  3124.  
  3125. let attrElm, b, v;
  3126. switch (attributeName) {
  3127. case 'theater':
  3128. nls = flexyAttr_toggleFlag(nls, isTheater(), LAYOUT_THEATER);
  3129. break;
  3130. case 'userscript-chat-collapsed':
  3131. case 'userscript-chatblock':
  3132. attrElm = kRef(ytdFlexy);
  3133. if (hasAttribute(attrElm, 'userscript-chat-collapsed')) {
  3134. nls = flexyAttr_toggleFlag(nls, true, LAYOUT_CHATROOM | LAYOUT_CHATROOM_COLLASPED);
  3135. } else {
  3136. nls = flexyAttr_toggleFlag(nls, hasAttribute(attrElm, 'userscript-chatblock'), LAYOUT_CHATROOM);
  3137. nls = flexyAttr_toggleFlag(nls, false, LAYOUT_CHATROOM_COLLASPED);
  3138. }
  3139. break;
  3140. case 'is-two-columns_':
  3141. nls = flexyAttr_toggleFlag(nls, isWideScreenWithTwoColumns(), LAYOUT_TWO_COLUMNS);
  3142. break;
  3143.  
  3144. case 'tabview-selection':
  3145. b = isNonEmptyString(kRef(ytdFlexy).getAttribute('tabview-selection'));
  3146. nls = flexyAttr_toggleFlag(nls, b, LAYOUT_TAB_EXPANDED);
  3147. break;
  3148.  
  3149. case 'fullscreen':
  3150. b = isNonEmptyString(kRef(ytdFlexy).getAttribute('fullscreen'));
  3151. nls = flexyAttr_toggleFlag(nls, b, LAYOUT_FULLSCREEN);
  3152. break;
  3153.  
  3154. case 'userscript-engagement-panel':
  3155. v = kRef(ytdFlexy).getAttribute('userscript-engagement-panel');
  3156. b = (+v > 0)
  3157. nls = flexyAttr_toggleFlag(nls, b, LAYOUT_ENGAGEMENT_PANEL_EXPAND);
  3158. break;
  3159.  
  3160. }
  3161.  
  3162. return nls;
  3163.  
  3164.  
  3165. }
  3166.  
  3167. let mtf_attrFlexy = (mutations, observer) => {
  3168.  
  3169. //attr mutation checker - $$ytdFlexyElm$$ {ytd-watch-flexy} \single
  3170. //::attr
  3171. // ~ 'userscript-chat-collapsed', 'userscript-chatblock', 'theater', 'is-two-columns_',
  3172. // ~ 'tabview-selection', 'fullscreen', 'userscript-engagement-panel',
  3173. // ~ 'hidden'
  3174.  
  3175. //console.log(15330, scriptEnable, kRef(ytdFlexy), mutations)
  3176.  
  3177. if (!scriptEnable) return;
  3178.  
  3179. const cssElm = kRef(ytdFlexy)
  3180. if (!cssElm) return;
  3181.  
  3182. if (!mutations) return;
  3183.  
  3184. //console.log(15340)
  3185. ytdFlexyHiddenCheck(mutations);
  3186.  
  3187. const old_layoutStatus = wls.layoutStatus
  3188. if (old_layoutStatus === null) return;
  3189. let new_layoutStatus = old_layoutStatus;
  3190.  
  3191. let checkedChat = false;
  3192.  
  3193. for (const mutation of mutations) {
  3194. new_layoutStatus = flexAttr_toLayoutStatus(new_layoutStatus, mutation.attributeName);
  3195. if (mutation.attributeName == 'userscript-chat-collapsed' || mutation.attributeName == 'userscript-chatblock') {
  3196.  
  3197. if(!checkedChat){
  3198. checkedChat = true; // avoid double call
  3199.  
  3200. if (cssElm.getAttribute('userscript-chatblock') === 'chat-live') {
  3201. // assigned new attribute - "chat-live" => disable comments section
  3202. _disableComments();
  3203. }
  3204.  
  3205. if (!cssElm.hasAttribute('userscript-chatblock')) {
  3206. // might or might not collapsed before
  3207. timeline.setTimeout(() => {
  3208. if (!scriptEnable) return;
  3209. //delayed call => check with the "no active focus" condition with chatroom status
  3210. if (!isAnyActiveTab() && !isChatExpand() && !isTheater() && isWideScreenWithTwoColumns() && !isFullScreen()) {
  3211. setToActiveTab();
  3212. }
  3213. }, 240);
  3214. }
  3215. }
  3216.  
  3217. }else if(mutation.attributeName == 'userscript-engagement-panel'){
  3218. // assume any other active component such as tab content and chatroom
  3219. if (+(cssElm.getAttribute('userscript-engagement-panel')||0)===0 && +mutation.oldValue>0) {
  3220. timeline.setTimeout(() => {
  3221. if (!scriptEnable) return;
  3222. //delayed call => check with the "no active focus" condition with engagement panel status
  3223. if (!isAnyActiveTab() && !isEngagementPanelExpanded() && !isTheater() && isWideScreenWithTwoColumns() && !isFullScreen()) {
  3224. setToActiveTab();
  3225. }
  3226. }, 240);
  3227. }
  3228. }
  3229. }
  3230.  
  3231. if (new_layoutStatus !== old_layoutStatus) wls.layoutStatus = new_layoutStatus
  3232.  
  3233. }
  3234.  
  3235. const mtf_checkFlexy = () => {
  3236. // once per $$native-ytd-watch-flexy$$ {ytd-watch-flexy} detection
  3237.  
  3238. let ytdFlexyElm = kRef(ytdFlexy);
  3239. if (!scriptEnable || !ytdFlexyElm) return true;
  3240.  
  3241.  
  3242. wls.layoutStatus = null;
  3243.  
  3244. let isFlexyHidden = (deferredVarYTDHidden = ytdFlexyElm.hasAttribute('hidden'));
  3245.  
  3246. if (!isFlexyHidden) {
  3247. let rChatExist = base_ChatExist();
  3248. if (rChatExist) {
  3249. let { attr_chatblock, attr_chatcollapsed } = rChatExist;
  3250. if (attr_chatblock === null) {
  3251. //remove attribute if it is unknown
  3252. attr_chatblock = false;
  3253. attr_chatcollapsed = false;
  3254. }
  3255. wAttr(ytdFlexyElm, 'userscript-chatblock', attr_chatblock)
  3256. wAttr(ytdFlexyElm, 'userscript-chat-collapsed', attr_chatcollapsed)
  3257. }
  3258. }
  3259.  
  3260. let rTabSelection = [...ytdFlexyElm.querySelectorAll('.tab-btn[userscript-tab-content]')]
  3261. .map(elm => ({ elm, hidden: elm.classList.contains('tab-btn-hidden') }));
  3262.  
  3263. if(rTabSelection.length === 0){
  3264. wAttr(ytdFlexyElm, 'tabview-selection', false);
  3265. }else{
  3266. rTabSelection=rTabSelection.filter(entry => entry.hidden !== true); // all available tabs
  3267. if (rTabSelection.length === 0) wAttr(ytdFlexyElm, 'tabview-selection', '');
  3268. }
  3269. rTabSelection = null;
  3270. let rEP = engagement_panels_();
  3271. if (rEP && rEP.count > 0) wAttr(ytdFlexyElm, 'userscript-engagement-panel', false);
  3272. //else wAttr(ytdFlexyElm, 'userscript-engagement-panel', rEP.value + ""); // can be 0
  3273. else if(rEP.value>0) wAttr(ytdFlexyElm, 'userscript-engagement-panel', rEP.value + ""); // can be 0
  3274.  
  3275. let ls = 0;
  3276. ls = flexAttr_toLayoutStatus(ls, 'theater')
  3277. ls = flexAttr_toLayoutStatus(ls, 'userscript-chat-collapsed')
  3278. ls = flexAttr_toLayoutStatus(ls, 'userscript-chatblock')
  3279. ls = flexAttr_toLayoutStatus(ls, 'is-two-columns_')
  3280. ls = flexAttr_toLayoutStatus(ls, 'tabview-selection')
  3281. ls = flexAttr_toLayoutStatus(ls, 'fullscreen')
  3282. ls = flexAttr_toLayoutStatus(ls, 'userscript-engagement-panel')
  3283.  
  3284. wls.layoutStatus = ls
  3285.  
  3286. mtoFlexyAttr.bindElement(ytdFlexyElm,{
  3287. attributes: true,
  3288. attributeFilter: ['userscript-chat-collapsed', 'userscript-chatblock', 'theater', 'is-two-columns_', 'tabview-selection', 'fullscreen', 'userscript-engagement-panel', 'hidden'],
  3289. attributeOldValue: true
  3290. })
  3291.  
  3292. ytdFlexyHiddenCheckBasic(ytdFlexyElm);
  3293.  
  3294.  
  3295. let columns = document.querySelector('ytd-page-manager#page-manager #columns')
  3296. if (columns) {
  3297. wAttr(columns, 'userscript-scrollbar-render', true);
  3298. }
  3299.  
  3300. return false;
  3301. }
  3302.  
  3303. function ytdFlexyHiddenCheckBasic(ytdFlexyElm){
  3304. // for both hidden and non-hidden ytd-watch-flexy
  3305.  
  3306. deferredVarYTDHidden = ytdFlexyElm.hasAttribute('hidden');
  3307.  
  3308. // console.log(15403)
  3309. document.documentElement.classList.toggle('tabview-normal-player',!deferredVarYTDHidden)
  3310.  
  3311. }
  3312.  
  3313. function checkVisibleEngagementPanel(){
  3314. if(storeLastPanel){
  3315.  
  3316. let elm_storeLastPanel = kRef(storeLastPanel);
  3317.  
  3318. if(elm_storeLastPanel && !isDOMVisible(elm_storeLastPanel) ){
  3319. storeLastPanel=null;
  3320. ytBtnCloseEngagementPanels();
  3321. }
  3322.  
  3323. }
  3324.  
  3325. }
  3326.  
  3327. function ytdFlexyHiddenCheck(mutations) {
  3328.  
  3329. //console.log(15350)
  3330.  
  3331. const ytdFlexyElm = kRef(ytdFlexy)
  3332. if (!ytdFlexyElm) return;
  3333. let muHidden = false
  3334.  
  3335. for (const mutation of mutations) {
  3336. if (mutation.attributeName === 'hidden') {
  3337. //console.log(343)
  3338. muHidden = true;
  3339. break;
  3340. }
  3341. }
  3342.  
  3343. if (!muHidden) return;
  3344.  
  3345. mtc_store= Date.now()+2870
  3346. //console.log(7004)
  3347. deferredVarYTDHidden = ytdFlexyElm.hasAttribute('hidden');
  3348.  
  3349. if(deferredVarYTDHidden && scheduledCommentRefresh && Q.comments_section_loaded>0){
  3350. scheduledCommentRefresh=false;
  3351. }
  3352.  
  3353. //console.log(15400)
  3354. if(!deferredVarYTDHidden){
  3355. mtf_forceCheckLiveVideo_disable = 0
  3356. timeline.setTimeout(function() {
  3357. mtf_ChatExist();
  3358. layoutStatusMutex.lockWith(unlock=>{
  3359. atChange(); // in case no mutation occurance
  3360. ytdFlexyHiddenCheckBasic(ytdFlexyElm);
  3361. dispatchWindowResize(); // player control positioning
  3362. timeline.setTimeout(unlock, 40);
  3363. })
  3364. }, 40);
  3365. }else{
  3366. //console.log(15401)
  3367. timeline.setTimeout(function() {
  3368. //console.log(15402)
  3369. ytdFlexyHiddenCheckBasic(ytdFlexyElm);
  3370. }, 40);
  3371. }
  3372.  
  3373. }
  3374.  
  3375.  
  3376.  
  3377.  
  3378. let switchTabActivity_lastTab = null
  3379.  
  3380. function setDisplayedPlaylist() {
  3381. //override the default youtube coding event prevention
  3382. let cssElm = kRef(ytdFlexy);
  3383. if (!scriptEnable || !cssElm) return;
  3384. displayedPlaylist = mWeakRef(document.querySelector('ytd-watch-flexy #tab-list:not(.tab-content-hidden) ytd-playlist-panel-renderer') || null);
  3385. }
  3386.  
  3387. function fixLineClampFn1() {
  3388. // use IntersectionObserver for new browser
  3389. if(!isIntersectionObserverAvailable)
  3390. timeline.setTimeout(() => requestAnimationFrame(() => new Promise(fixLineClampFn2)), 1)
  3391. }
  3392.  
  3393. //let lastFixLineClamp = 0
  3394. //let mConstructor = null
  3395. const isIntersectionObserverAvailable= !!window.IntersectionObserver;
  3396. function fixLineClampFn2() {
  3397. //let currentTime= Date.now();
  3398. //if(currentTime)
  3399. let contentElements = document.querySelectorAll('ytd-comments#comments ytd-expander[max-number-of-lines] > #content.ytd-expander:not(.tabview-fix-line-clamp)');
  3400. // backward compatible with Waterfox Classic
  3401. // let contentElements = document.querySelectorAll('ytd-comments#comments ytd-expander[should-use-number-of-lines] > #content')
  3402. for (const elm of contentElements){
  3403. //nativeValue(elm.parentNode,'recomputeOnResize',true)
  3404.  
  3405. // loading -> fetched -> loaded in non-visual mode
  3406. // require to trigger the update using mutation observer for line clamp
  3407. elm.classList.toggle('tabview-fix-line-clamp'); // this is to trigger mutation observer in dekstop_polymer.js
  3408. }
  3409. nativeFuncStacked('ytd-comments#comments ytd-expander[max-number-of-lines]', 'calculateCanCollapse');
  3410. //nativeConstStacked('ytd-comments#comments ytd-expander[max-number-of-lines]', 'recomputeOnResize',true);
  3411. contentElements = null;
  3412. }
  3413.  
  3414. function switchTabActivity(activeLink) {
  3415. if (!scriptEnable) return;
  3416.  
  3417. const ytdFlexyElm = kRef(ytdFlexy);
  3418.  
  3419. if (!ytdFlexyElm) return;
  3420.  
  3421. if (activeLink && activeLink.classList.contains('tab-btn-hidden')) return; // not allow to switch to hide tab
  3422.  
  3423. if (isTheater() && isWideScreenWithTwoColumns()) activeLink = null;
  3424.  
  3425.  
  3426. function runAtEnd() {
  3427.  
  3428. //console.log(12312)
  3429.  
  3430. if (activeLink) lastShowTab = activeLink.getAttribute('userscript-tab-content')
  3431.  
  3432. displayedPlaylist = null;
  3433. scrollingVideosList = null;
  3434.  
  3435. if (activeLink && lastShowTab == '#tab-list') {
  3436. setDisplayedPlaylist();
  3437. } else if (activeLink && lastShowTab == '#tab-videos') {
  3438. scrollingVideosList = mWeakRef(document.querySelector('ytd-watch-flexy #tab-videos:not(.tab-content-hidden) [placeholder-videos]'));
  3439. }
  3440.  
  3441.  
  3442. ytdFlexyElm.setAttribute('tabview-selection', activeLink ? lastShowTab : '')
  3443.  
  3444. if (lastShowTab == '#tab-comments' && (ytdFlexyElm.getAttribute('tabview-youtube-comments') || '').lastIndexOf('S') >= 0) {
  3445.  
  3446. if(mtf_forceCheckLiveVideo_disable===2) {}
  3447. else{
  3448. akAttr(ytdFlexyElm, 'tabview-youtube-comments', false, 'L');
  3449.  
  3450. requestAnimationFrame(() => {
  3451. let comments_tab = document.querySelector('#tab-comments');
  3452. if (comments_tab && comments_tab.scrollTop > 0) comments_tab.scrollTop = 0;
  3453. });
  3454. }
  3455.  
  3456. }
  3457.  
  3458. if (lastShowTab == '#tab-comments') {
  3459. fixLineClampFn1();
  3460. }
  3461.  
  3462. }
  3463.  
  3464. const links = document.querySelectorAll('#material-tabs a[userscript-tab-content]');
  3465.  
  3466.  
  3467.  
  3468. for (const link of links) {
  3469. let content = document.querySelector(link.getAttribute('userscript-tab-content'));
  3470. if (link && content) {
  3471. if (link !== activeLink) {
  3472. link.classList.remove("active");
  3473. content.classList.add("tab-content-hidden");
  3474. } else {
  3475. link.classList.add("active");
  3476. content.classList.remove("tab-content-hidden");
  3477. //timeline.setTimeout(()=>content.focus(),400);
  3478.  
  3479. }
  3480. }
  3481. }
  3482.  
  3483. runAtEnd();
  3484.  
  3485.  
  3486. }
  3487.  
  3488. let tabsUiScript_setclick = false;
  3489.  
  3490. function prepareTabBtn() {
  3491.  
  3492. const materialTab = document.querySelector("#material-tabs")
  3493. if (!materialTab) return;
  3494.  
  3495. let noActiveTab = !!document.querySelector('ytd-watch-flexy[userscript-chatblock]:not([userscript-chat-collapsed])')
  3496.  
  3497. const activeLink = materialTab.querySelector('a[userscript-tab-content].active:not(.tab-btn-hidden)')
  3498. if (activeLink) switchTabActivity(noActiveTab ? null : activeLink)
  3499.  
  3500. if (!tabsUiScript_setclick) {
  3501. tabsUiScript_setclick = true;
  3502. $(materialTab).on("click", "a", function(evt) {
  3503.  
  3504. //console.log(8510)
  3505. let ytdFlexyElm = kRef(ytdFlexy);
  3506. if (!scriptEnable || !ytdFlexyElm) return null;
  3507.  
  3508. if (!this.hasAttribute('userscript-tab-content')) return;
  3509.  
  3510.  
  3511. evt.preventDefault();
  3512.  
  3513. //console.log(8511)
  3514.  
  3515. /*
  3516. if (this.getAttribute('userscript-tab-content') == '#tab-comments' && parseInt(ytdFlexyElm.getAttribute('tabview-youtube-comments') || '') < 0) {
  3517. console.log(8512)
  3518. return;
  3519. }*/
  3520.  
  3521. //console.log(8513)
  3522. new Promise(requestAnimationFrame).then(() => {
  3523.  
  3524.  
  3525. //console.log(8514)
  3526. layoutStatusMutex.lockWith(unlock => {
  3527.  
  3528. //console.log(8515)
  3529. switchTabActivity_lastTab = this.getAttribute('userscript-tab-content');
  3530.  
  3531. let isActiveAndVisible = this.classList.contains('tab-btn') && this.classList.contains('active') && !this.classList.contains('tab-btn-hidden')
  3532.  
  3533. if (isWideScreenWithTwoColumns() && !isTheater() && isActiveAndVisible) {
  3534. //optional
  3535. timeline.setTimeout(unlock, 80);
  3536. switchTabActivity(null);
  3537. ytBtnSetTheater();
  3538. } else if (isActiveAndVisible) {
  3539. timeline.setTimeout(unlock, 80);
  3540. switchTabActivity(null);
  3541. } else {
  3542. let pInterval = 60;
  3543. if (isChatExpand() && isWideScreenWithTwoColumns()) {
  3544. ytBtnCollapseChat();
  3545. } else if (isEngagementPanelExpanded() && isWideScreenWithTwoColumns()) {
  3546. ytBtnCloseEngagementPanels();
  3547. } else if (isWideScreenWithTwoColumns() && isTheater() && !isFullScreen()) {
  3548. ytBtnCancelTheater();
  3549. } else {
  3550. pInterval = 20;
  3551. }
  3552. //console.log(8518)
  3553. timeline.setTimeout(() => {
  3554. timeline.setTimeout(makeBodyScroll, 20); // this is to make the image render
  3555.  
  3556. timeline.setTimeout(() => {
  3557. let rightTabs = document.querySelector('#right-tabs');
  3558. if (!isWideScreenWithTwoColumns() && rightTabs && rightTabs.offsetTop > 0 && this.classList.contains('active')) {
  3559. let tabButtonBar = document.querySelector('#material-tabs');
  3560. let tabButtonBarHeight = tabButtonBar ? tabButtonBar.offsetHeight : 0;
  3561. window.scrollTo(0, rightTabs.offsetTop - tabButtonBarHeight);
  3562. }
  3563. }, 60)
  3564. // console.log(8519)
  3565.  
  3566. timeline.setTimeout(unlock, 80)
  3567. switchTabActivity(this)
  3568.  
  3569. }, pInterval);
  3570. }
  3571.  
  3572.  
  3573. })
  3574.  
  3575. })
  3576.  
  3577.  
  3578.  
  3579.  
  3580. });
  3581.  
  3582. }
  3583.  
  3584. }
  3585.  
  3586.  
  3587. // ---------------------------------------------------------------------------------------------
  3588. window.addEventListener("yt-navigate-finish", onNavigationEnd)
  3589.  
  3590. document.addEventListener("loadstart", (evt) => {
  3591. if (!evt || !evt.target || evt.target.nodeName !== "VIDEO") return;
  3592. let elm = evt.target;
  3593. if (!elm.matches('#player video, #movie_player video, video[tabview-mainvideo]')) return;
  3594.  
  3595. mtc_store= Date.now()+2870
  3596.  
  3597. let src = elm.src;
  3598. if (src !== lastVideoURL) {
  3599. lastVideoURL = elm.src;
  3600. elm.setAttribute('tabview-mainvideo', ''); // mainly for mini playing
  3601. }
  3602.  
  3603. }, true)
  3604.  
  3605. // ---------------------------------------------------------------------------------------------
  3606.  
  3607. let scrolling_lastD = 0;
  3608.  
  3609. const singleColumnScrolling = function(scrolling_lastF) {
  3610. if (!scriptEnable || deferredVarYTDHidden) return;
  3611.  
  3612. let pageY = scrollY;
  3613. if (pageY < 10 && scrolling_lastD === 0 && !scrolling_lastF) return;
  3614.  
  3615. let targetElm, header, navElm;
  3616.  
  3617. Promise.resolve().then(() => {
  3618.  
  3619. targetElm = document.querySelector("#right-tabs");
  3620. if (!targetElm) return;
  3621. header = targetElm.querySelector("header");
  3622. if (!header) return;
  3623. navElm = document.querySelector('#masthead-container, #masthead')
  3624. if (!navElm) return;
  3625. let navHeight = navElm ? navElm.offsetHeight : 0
  3626.  
  3627. let elmY = targetElm.offsetTop
  3628.  
  3629. let xyz = [elmY + navHeight, pageY, elmY - navHeight]
  3630.  
  3631. let xyStatus = 0
  3632. if (xyz[1] < xyz[2] && xyz[2] < xyz[0]) {
  3633. // 1
  3634. xyStatus = 1
  3635. }
  3636.  
  3637. if (xyz[0] > xyz[1] && xyz[1] > xyz[2]) {
  3638.  
  3639. //2
  3640. xyStatus = 2
  3641.  
  3642. }
  3643.  
  3644. if (xyz[2] < xyz[0] && xyz[0] < xyz[1]) {
  3645. // 3
  3646.  
  3647. xyStatus = 3
  3648.  
  3649.  
  3650. }
  3651.  
  3652. return xyStatus;
  3653.  
  3654. }).then((xyStatus) => {
  3655.  
  3656. if ((xyStatus == 2 || xyStatus == 3) && (scrolling_lastD === 0 || scrolling_lastF)) {
  3657. scrolling_lastD = 1;
  3658. let {
  3659. offsetHeight
  3660. } = header
  3661. let {
  3662. offsetWidth
  3663. } = targetElm
  3664.  
  3665. targetElm.style.setProperty("--userscript-sticky-width", offsetWidth + 'px')
  3666. targetElm.style.setProperty("--userscript-sticky", offsetHeight + 'px')
  3667.  
  3668. wAttr(targetElm, 'userscript-sticky', true);
  3669.  
  3670. } else if ((xyStatus == 1) && (scrolling_lastD === 1 || scrolling_lastF)) {
  3671. scrolling_lastD = 0;
  3672.  
  3673. wAttr(targetElm, 'userscript-sticky', false);
  3674. }
  3675.  
  3676.  
  3677. targetElm = null;
  3678. header = null;
  3679. navElm = null;
  3680.  
  3681. });
  3682.  
  3683. };
  3684.  
  3685. window.addEventListener("scroll", function() {
  3686. singleColumnScrolling(false)
  3687. }, {
  3688. capture: false,
  3689. passive: true
  3690. })
  3691.  
  3692. let lastResizeAt = 0;
  3693. window.addEventListener('resize', function() {
  3694.  
  3695. if (!scriptEnable) return;
  3696. if (deferredVarYTDHidden) return;
  3697. lastResizeAt = Date.now();
  3698.  
  3699. requestAnimationFrame(() => {
  3700. singleColumnScrolling(true)
  3701. })
  3702.  
  3703. if(lastShowTab == '#tab-comments') fixLineClampFn1() // in case window resized leading the change of number of lines.
  3704.  
  3705. }, {
  3706. capture: false,
  3707. passive: true
  3708. })
  3709.  
  3710.  
  3711.  
  3712. let hist = null
  3713. const getHistState = (history)=>`${history.length}|${history.state?history.state.entryTime:null}`;
  3714. function newVideoPageCheck(){
  3715. let hState = getHistState(history)
  3716. if(hist!==hState) {
  3717. hist=hState;
  3718. if(scriptEnable){
  3719. //scriptEnable = false;
  3720. let callTimeout = !newVideoPage.entryTime
  3721. newVideoPage.entryTime = 1
  3722. if(callTimeout) setTimeout(newVideoPage,0)
  3723. }
  3724. return true;
  3725. }
  3726. }
  3727. function newVideoPage(){
  3728. newVideoPage.entryTime = 0;
  3729.  
  3730. console.log('newVideoPage')
  3731. //console.log('newVideoPage-', 150, location.href)
  3732.  
  3733. let ytdFlexyElm = kRef(ytdFlexy);
  3734. if(!ytdFlexyElm) return;
  3735.  
  3736. timeline.reset();
  3737. layoutStatusMutex = new Mutex();
  3738.  
  3739. //console.log('newVideoPage-', 350, location.href)
  3740. let flag1= /^https?\:\/\/(\w+\.)*youtube\.com\/watch\?(\w+\=[^\/\?\&]+\&|\w+\=?\&)*v=[\w\-\_]+/.test(location.href)
  3741. let tf = ()=>{
  3742.  
  3743. let isFlexyHidden = (deferredVarYTDHidden = ytdFlexyElm.hasAttribute('hidden'));
  3744.  
  3745. let flag2 = !isFlexyHidden;
  3746.  
  3747. if(flag1^flag2) return timeline.setTimeout(tf,7); else funcVisibleWatch();
  3748.  
  3749. tf= null;
  3750. funcVisibleWatch = null;
  3751. ytdFlexyElm=null
  3752.  
  3753. }
  3754.  
  3755. let funcVisibleWatch = ()=>{
  3756. //scriptEnable = true;
  3757.  
  3758. let isFlexyHidden = (deferredVarYTDHidden = ytdFlexyElm.hasAttribute('hidden'));
  3759. ytdFlexyHiddenCheckBasic(ytdFlexyElm)
  3760.  
  3761. if(!isFlexyHidden) {
  3762.  
  3763. mtf_forceCheckLiveVideo_disable = 0;
  3764. mtc_store= Date.now()+2870
  3765.  
  3766. sect_lastUpdate = 0;
  3767. if(pendingOne){
  3768. // reset pendingOne = false if the element is already removed.
  3769. pendingOne = document.querySelectorAll(`ytd-watch-flexy ytd-comments#comments [tabview-cache-time]`).length>1;
  3770. }
  3771.  
  3772. timeline.setTimeout(()=>{
  3773. Q.mutationTarget=null;
  3774. FP.mtf_attrComments()
  3775. },2870)
  3776. if(pageInit_attrComments) hookSection();
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782. let new_layoutStatus = wls.layoutStatus
  3783.  
  3784. const new_isExpandedChat = !(new_layoutStatus & LAYOUT_CHATROOM_COLLASPED) && (new_layoutStatus & LAYOUT_CHATROOM)
  3785. const new_isCollaspedChat = (new_layoutStatus & LAYOUT_CHATROOM_COLLASPED) && (new_layoutStatus & LAYOUT_CHATROOM)
  3786. const new_isTwoColumns = new_layoutStatus & LAYOUT_TWO_COLUMNS;
  3787. const new_isTheater = new_layoutStatus & LAYOUT_THEATER;
  3788. const new_isTabExpanded = new_layoutStatus & LAYOUT_TAB_EXPANDED;
  3789. const new_isFullScreen = new_layoutStatus & LAYOUT_FULLSCREEN;
  3790. const new_isExpandEPanel = new_layoutStatus & LAYOUT_ENGAGEMENT_PANEL_EXPAND;
  3791.  
  3792. /*
  3793. console.log('d67',
  3794. ytdFlexyElm.getAttribute('tabview-selection')==='' ,
  3795. new_isTwoColumns , !new_isTheater, !new_isTabExpanded, !new_isFullScreen , !new_isExpandEPanel , !new_isExpandedChat
  3796.  
  3797. )
  3798. */
  3799.  
  3800. if( ytdFlexyElm.getAttribute('tabview-selection')==='' && new_isTwoColumns && !new_isTheater && !new_isTabExpanded && !new_isFullScreen && !new_isExpandEPanel && !new_isExpandedChat ){
  3801. // e.g. engage panel removed after miniview and change video
  3802. setToActiveTab();
  3803. }else if(new_isExpandEPanel && ytdFlexyElm.querySelectorAll('ytd-engagement-panel-section-list-renderer[visibility="ENGAGEMENT_PANEL_VISIBILITY_EXPANDED"]').length===0){
  3804. wls.layoutStatus = new_layoutStatus & (~LAYOUT_ENGAGEMENT_PANEL_EXPAND)
  3805. }
  3806.  
  3807. //mtf_attrFlexy();
  3808.  
  3809. FP.mtf_attrEngagementPanel();
  3810. FP.mtf_attrPlaylist();
  3811. FP.mtf_attrComments();
  3812. FP.mtf_attrChatroom();
  3813.  
  3814.  
  3815. }
  3816.  
  3817. regularCheck(1,0,null); // mutation happens when the page is not ready; call again as the page is ready.
  3818.  
  3819.  
  3820.  
  3821.  
  3822. }
  3823.  
  3824. tf();
  3825.  
  3826.  
  3827. }
  3828.  
  3829.  
  3830.  
  3831. function browserHistoryState(){
  3832. let maxCount = 5
  3833.  
  3834. if (!scriptEnable) return;
  3835. let ytdFlexyElm = kRef(ytdFlexy);
  3836. if(!ytdFlexyElm) return;
  3837.  
  3838. let cid = timeline.setInterval(function(){
  3839. if(newVideoPageCheck()){
  3840. timeline.clearInterval(cid);
  3841. }
  3842. if(--maxCount===0) timeline.clearInterval(cid);
  3843. },7)
  3844.  
  3845. }
  3846.  
  3847.  
  3848. window.addEventListener('hashchange', function() {
  3849. if (!scriptEnable) return;
  3850. console.log('hashchange');
  3851. browserHistoryState();
  3852. }, { capture: true })
  3853.  
  3854. window.addEventListener('popstate', function() {
  3855. if (!scriptEnable) return;
  3856. console.log('popstate');
  3857. browserHistoryState();
  3858. }, { capture: true })
  3859.  
  3860.  
  3861. // function clearMutationObserver(o, key) {
  3862. // if (o[key]) {
  3863. // o[key].takeRecords();
  3864. // o[key].disconnect();
  3865. // o[key] = null;
  3866. // return true;
  3867. // }
  3868. // }
  3869.  
  3870. // function initMutationObserver(o, key, callback) {
  3871. // clearMutationObserver(o, key);
  3872. // const mto = new MutationObserver(callback);
  3873. // o[key] = mto;
  3874. // return mto;
  3875. // }
  3876. // function initMutationObserver2(o, key, mtoFunc) {
  3877. // clearMutationObserver(o, key);
  3878. // const mto = mtoFunc();
  3879. // o[key] = mto;
  3880. // return mto;
  3881. // }
  3882.  
  3883. document.addEventListener('wheel', function(evt) {
  3884.  
  3885. if (!scriptEnable) return;
  3886. const displayedPlaylist_element = kRef(displayedPlaylist);
  3887. if (displayedPlaylist_element && displayedPlaylist_element.contains(evt.target)) {
  3888. evt.stopPropagation();
  3889. evt.stopImmediatePropagation();
  3890. }
  3891. }, { capture: true, passive: true });
  3892.  
  3893.  
  3894. function setVideosTwoColumns(flag, bool) {
  3895.  
  3896. //two columns to one column
  3897.  
  3898. /*
  3899. [placeholder-videos] ytd-watch-next-secondary-results-renderer.style-scope.ytd-watch-flexy
  3900.  
  3901. is-two-columns ="" => no is-two-columns
  3902. [placeholder-videos] tp-yt-paper-spinner#spinner.style-scope.ytd-continuation-item-renderer
  3903. no hidden => hidden =""
  3904. [placeholder-videos] div#button.style-scope.ytd-continuation-item-renderer
  3905. hidden ="" => no hidden
  3906.  
  3907. */
  3908.  
  3909. let cssSelector1 = '[placeholder-videos] ytd-watch-next-secondary-results-renderer.style-scope.ytd-watch-flexy'
  3910.  
  3911. let cssSelector2 = '[placeholder-videos] tp-yt-paper-spinner#spinner.style-scope.ytd-continuation-item-renderer'
  3912.  
  3913. let cssSelector3 = '[placeholder-videos] div#button.style-scope.ytd-continuation-item-renderer'
  3914.  
  3915. let res = {}
  3916. if (flag & 1) {
  3917. res.m1 = document.querySelector(cssSelector1)
  3918. if (res.m1) wAttr(res.m1, 'is-two-columns', bool ? '' : false);
  3919. }
  3920.  
  3921. if (flag & 2) {
  3922. res.m2 = document.querySelector(cssSelector2)
  3923. if (res.m2) wAttr(res.m2, 'hidden', bool ? false : '');
  3924. }
  3925.  
  3926. if (flag & 4) {
  3927. res.m3 = document.querySelector(cssSelector3)
  3928. if (res.m3) wAttr(res.m3, 'hidden', bool ? '' : false);
  3929. }
  3930.  
  3931.  
  3932. return res
  3933.  
  3934.  
  3935.  
  3936.  
  3937. }
  3938.  
  3939. let lastScrollFetch = 0;
  3940. // function isScrolledToEnd(){
  3941. // return (window.innerHeight + window.pageYOffset) >= document.scrollingElement.scrollHeight - 2;
  3942. // }
  3943. let lastOffsetTop = 0;
  3944. window.addEventListener('scroll', function(evt) {
  3945.  
  3946. //console.log(evt.target)
  3947.  
  3948. if (!scriptEnable) return;
  3949.  
  3950.  
  3951. if (!kRef(scrollingVideosList)) return;
  3952. if (videoListBeforeSearch) return;
  3953.  
  3954.  
  3955.  
  3956. let visibleHeight = document.scrollingElement.clientHeight;
  3957. let totalHeight = document.scrollingElement.scrollHeight;
  3958.  
  3959. if (totalHeight < visibleHeight * 1.5) return; // filter out two column view;
  3960.  
  3961. let z = window.pageYOffset + visibleHeight;
  3962. let h_advanced = totalHeight - (visibleHeight > 5 * 40 ? visibleHeight * 0.5 : 40);
  3963.  
  3964.  
  3965.  
  3966. if (z > h_advanced && !isWideScreenWithTwoColumns()) {
  3967.  
  3968. let ct = Date.now();
  3969. if (ct - lastScrollFetch < 500) return; //prevent continuous calling
  3970.  
  3971. lastScrollFetch = ct;
  3972.  
  3973. let res = setVideosTwoColumns(2 | 4, true)
  3974. if (res.m3 && res.m2) {
  3975.  
  3976. //wait for DOM change, just in case
  3977. requestAnimationFrame(() => {
  3978. let { offsetTop } = res.m2 // as visibility of m2 & m3 switched.
  3979.  
  3980. if (offsetTop - lastOffsetTop < 40) return; // in case bug, or repeating calling. // the next button shall below the this button
  3981. lastOffsetTop = offsetTop
  3982.  
  3983. res.m2.parentNode.dispatchEvent(new Event('yt-service-request-sent-button-renderer'))
  3984.  
  3985. res = null
  3986. })
  3987.  
  3988. } else {
  3989.  
  3990. res = null
  3991. }
  3992.  
  3993.  
  3994. }
  3995.  
  3996.  
  3997.  
  3998.  
  3999. }, { passive: true })
  4000.  
  4001. let sect_lastUpdate = 0;
  4002.  
  4003. let sect_holder = null;
  4004. let sect_hText = null;
  4005. let sect_hTime = 0;
  4006.  
  4007. let pendingOne = false;
  4008. let mtf_forceCheckLiveVideo_disable = 0;
  4009.  
  4010. let storeLastPanel = null;
  4011.  
  4012. let deferredVarYTDHidden = null;
  4013. let scheduledCommentRefresh = false;
  4014.  
  4015. let pageInit_attrComments = false;
  4016.  
  4017.  
  4018.  
  4019. let mgChatFrame = {
  4020. setVar(elm) {
  4021. mgChatFrame.kVar = mWeakRef(elm)
  4022. },
  4023. getVar() {
  4024. return kRef(mgChatFrame.kVar)
  4025. },
  4026. inPage() {
  4027. let elm = mgChatFrame.getVar();
  4028. if (!elm) return false;
  4029. let ytdFlexyElm = kRef(ytdFlexy);
  4030. if(!ytdFlexyElm) return false;
  4031. return ytdFlexyElm.contains(elm)
  4032. }
  4033. };
  4034.  
  4035. const timeline = {
  4036. // after initialized (initObserver)
  4037. cn1:{},
  4038. cn2:{},
  4039. setTimeout(f,d){
  4040. return timeline.cn1[setTimeout(f,d)]=true
  4041. },
  4042. clearTimeout(cid){
  4043. timeline.cn1[cid]=false; return clearTimeout(cid)
  4044. },
  4045. setInterval(f,d){
  4046. return timeline.cn2[setInterval(f,d)]=true
  4047. },
  4048. clearInterval(cid){
  4049. timeline.cn2[cid]=false; return clearInterval(cid)
  4050. },
  4051. reset(){
  4052. for(let cid in timeline.cn1) timeline.cn1[cid] && clearTimeout(cid)
  4053. for(let cid in timeline.cn2) timeline.cn2[cid] && clearInterval(cid)
  4054. timeline.cn1={}
  4055. timeline.cn2={}
  4056. }
  4057. }
  4058.  
  4059. class AttributeMutationObserver extends MutationObserver {
  4060. constructor(flist){
  4061. super((mutations, observer)=>{
  4062. for(const mutation of mutations){
  4063. if (mutation.type === 'attributes') {
  4064. this.checker(mutation.target, mutation.attributeName)
  4065. }
  4066. }
  4067. })
  4068. this.flist=flist;
  4069. this.res={}
  4070. }
  4071. takeRecords(){
  4072. super.takeRecords();
  4073. }
  4074. disconnect(){
  4075. this._target = null;
  4076. super.disconnect();
  4077. }
  4078. observe(target){
  4079. if(this._target) return;
  4080. this._target = mWeakRef(target);
  4081. const options = {
  4082. attributes: true,
  4083. attributeFilter: Object.keys(this.flist),
  4084. //attributeFilter: [ "status", "username" ],
  4085. attributeOldValue: true
  4086. }
  4087. super.observe(target, options)
  4088. }
  4089. checker(target, attributeName){
  4090. let nv = target.getAttribute(attributeName);
  4091. if(this.res[attributeName]!==nv){
  4092. this.res[attributeName] = nv
  4093. let f = this.flist[attributeName];
  4094. if(f) f(attributeName, nv);
  4095.  
  4096. }
  4097. }
  4098. check(delay = 0){
  4099. setTimeout(()=>{
  4100. let target = kRef(this._target)
  4101. for(const key of Object.keys(this.flist)){
  4102. this.checker(target,key)
  4103. }
  4104. target = null;
  4105. },delay)
  4106. }
  4107. }
  4108.  
  4109. function goYoutubeGeniusLyrics(){
  4110.  
  4111. setTimeout(function $f(){
  4112.  
  4113. if(!document.documentElement.hasAttribute('w-engagement-panel-genius-lyrics')) return setTimeout($f,100)
  4114.  
  4115. document.documentElement.dispatchEvent(new CustomEvent('engagement-panel-genius-lyrics'))
  4116.  
  4117.  
  4118. },100)
  4119.  
  4120.  
  4121.  
  4122. }
  4123.  
  4124.  
  4125. /*
  4126.  
  4127. To be implement: timeline
  4128.  
  4129. timeline.setTimeout
  4130. timeline.clearTimeout
  4131. timeline.setInterval
  4132. timeline.clearInterval
  4133.  
  4134. */
  4135.  
  4136.  
  4137.  
  4138. //Object.keys($0).filter(key=>!(key in $0.constructor.prototype))
  4139.  
  4140. //Object.getOwnPropertyNames(window).filter(k=>k.startsWith('HTML'))
  4141. //Object.getOwnPropertyNames(window).filter(k=>k.startsWith('HTML')).filter(k=>$0 instanceof window[k])
  4142.  
  4143.  
  4144. /* --------------------------- browser's bug in -webkit-box ----------------------------------------- */
  4145.  
  4146. /*
  4147. fix bug for comment section - version 1.8.7
  4148. This issue is the bug in browser's rendering
  4149. I guess, this is due to the lines clamp with display:-webkit-box
  4150. use stupid coding to let it re-render when its content become visible
  4151. /*
  4152.  
  4153. ytd-expander[should-use-number-of-lines][collapsed] > #content.ytd-expander {
  4154. color: var(--yt-spec-text-primary);
  4155. display: -webkit-box;
  4156. overflow: hidden;
  4157. max-height: none;
  4158. -webkit-box-orient: vertical;
  4159. -webkit-line-clamp: var(--ytd-expander-max-lines, 4);
  4160. }
  4161.  
  4162. // v1.8.36 imposed a effective solution for fixing this bug
  4163.  
  4164. */
  4165.  
  4166. /* --------------------------- browser's bug in -webkit-box ----------------------------------------- */
  4167.  
  4168.  
  4169. /**
  4170. *
  4171.  
  4172.  
  4173. f.initChildrenObserver=function(){var a=this;this.observer=new MutationObserver(function(){return a.childrenChanged()});
  4174. this.observer.observe(this.$.content,{subtree:!0,childList:!0,attributes:!0});this.childrenChanged()};
  4175. f.childrenChanged=function(){var a=this;this.alwaysToggleable?this.canToggle=this.alwaysToggleable:this.canToggleJobId||(this.canToggleJobId=window.requestAnimationFrame(function(){$h(function(){a.canToggleJobId=0;a.calculateCanCollapse()})}))};
  4176.  
  4177.  
  4178. f.onIronResize=function(){this.recomputeOnResize&&this.childrenChanged()};
  4179.  
  4180.  
  4181. onButtonClick_:function(){this.fire("yt-close-upsell-dialog")},
  4182. computeHasHeader_:function(a){return!!a.headerBackgroundImage}});var geb;var heb;var ieb;var jeb;var xI=function(){var a=L.apply(this,arguments)||this;a.alignAuto=!1;a.collapsed=!0;a.isToggled=!1;a.alwaysCollapsed=!1;a.canToggle=!0;a.collapsedHeight=80;a.disableToggle=!1;a.alwaysToggleable=!1;a.reversed=!1;a.shouldUseNumberOfLines=!1;a.recomputeOnResize=!1;a.canToggleJobId=0;return a};
  4183. n(xI,L);f=xI.prototype;f.alwaysToggleableChanged=function(){this.alwaysToggleable&&(this.canToggle=!0)};
  4184.  
  4185.  
  4186. f.calculateCanCollapse=function(){this.canToggle=this.shouldUseNumberOfLines?this.alwaysToggleable||this.$.content.offsetHeight<this.$.content.scrollHeight:this.alwaysToggleable||this.$.content.scrollHeight>this.collapsedHeight};
  4187. f.detachObserver=function(){this.observer&&this.observer.disconnect()};
  4188.  
  4189. *
  4190. *
  4191. *
  4192. */
  4193.  
  4194.  
  4195.  
  4196.  
  4197. })();
  4198.  
  4199.  
  4200.  
  4201.  
  4202.  
  4203.  
  4204.  
  4205.  
  4206.  
  4207.  
  4208.  
  4209.  
  4210.  
  4211.  
  4212.  
  4213.  
  4214.  
  4215.  
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  
  4234.  
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240. // https://github.com/cyfung1031/Tabview-Youtube/raw/main/js/content.js
  4241.  
  4242. }
  4243.  
  4244.  
  4245. ;!(function $$() {
  4246. 'use strict';
  4247.  
  4248. if(document.documentElement==null) return window.requestAnimationFrame($$)
  4249.  
  4250. const cssTxt = GM_getResourceText("contentCSS");
  4251.  
  4252. function addStyle (styleText) {
  4253. const styleNode = document.createElement('style');
  4254. styleNode.type = 'text/css';
  4255. styleNode.textContent = styleText;
  4256. document.documentElement.appendChild(styleNode);
  4257. return styleNode;
  4258. }
  4259.  
  4260. addStyle (cssTxt);
  4261.  
  4262. main(window.$);
  4263.  
  4264.  
  4265. // Your code here...
  4266. })();