From 4b34319ced4b75738d15e787331db56b72fd8614 Mon Sep 17 00:00:00 2001 From: 4yman <170770027+4yman-0@users.noreply.github.com> Date: Wed, 1 Jan 2025 08:21:10 +0100 Subject: [PATCH 1/3] Fix Chapters not showing after reload Fix #2754 `ImprovedTube.chapters` tries to call `ImprovedTube.forbidFocus` which does not exists or is not a function. Tested with Chromium on Arch Linuxand random youtube videos. --- js&css/web-accessible/www.youtube.com/appearance.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js&css/web-accessible/www.youtube.com/appearance.js b/js&css/web-accessible/www.youtube.com/appearance.js index 222eb871c..04472e109 100644 --- a/js&css/web-accessible/www.youtube.com/appearance.js +++ b/js&css/web-accessible/www.youtube.com/appearance.js @@ -349,13 +349,14 @@ ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript == CHAPTERS --------------------------------------------------------------*/ ImprovedTube.chapters = function (el) { if (ImprovedTube.storage.chapters === true) { - const available = el.querySelector('[target-id*=chapters][visibility*=HIDDEN]') || el.querySelector('[target-id*=chapters]')?.clientHeight; + const available = el.querySelector('[target-id*=chapters][visibility*=HIDDEN]') + || el.querySelector('[target-id*=chapters]')?.clientHeight; if (available) { - ImprovedTube.forbidFocus(2100); + //ImprovedTube.forbidFocus(2100); const modernChapters = el.querySelector('[modern-chapters] #navigation-button button[aria-label]'); modernChapters ? modernChapters.click() : el.querySelector('[target-id*=chapters]')?.removeAttribute('visibility'); if ( yt.config_.EXPERIMENT_FLAGS.kevlar_watch_grid === true ) { available.setAttribute('z-index', '98765') } - } + } }}; /*------------------------------------------------------------------------------ LIVECHAT From 72dbc131f86256766e5ad13d0976b42ee3cafa7e Mon Sep 17 00:00:00 2001 From: ImprovedTube Date: Tue, 7 Jan 2025 10:13:10 +0100 Subject: [PATCH 2/3] Update appearance.js --- .../www.youtube.com/appearance.js | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/js&css/web-accessible/www.youtube.com/appearance.js b/js&css/web-accessible/www.youtube.com/appearance.js index 99a50ce01..138f9674c 100644 --- a/js&css/web-accessible/www.youtube.com/appearance.js +++ b/js&css/web-accessible/www.youtube.com/appearance.js @@ -333,18 +333,21 @@ ImprovedTube.hideTopProgressBar = function () { /*------------------------------------------------------------------------------ SIDEBAR ------------------------------------------------------------------------------*/ +// if ( document.documentElement.dataset.pageType === 'video' && +// (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.transcript === true || ImprovedTube.storage.chapters === true )) { + ImprovedTube.forbidFocus = function (ms) { + if (!ImprovedTube.originalFocus) {ImprovedTube.originalFocus = HTMLElement.prototype.focus;} // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy) + HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); } + if(document.hidden) ms *= 3; // forbid 3 times longer in inactive tabs + setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()" + } +//} /*---------------------------------------------------------------- TRANSCRIPT --------------------------------------------------------------*/ ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript === true) { const available = el.querySelector('[target-id*=transcript][visibility*=HIDDEN]') || el.querySelector('[target-id*=transcript]')?.clientHeight; if (available) { - if (!ImprovedTube.originalFocus) {ImprovedTube.originalFocus = HTMLElement.prototype.focus;} // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy) - ImprovedTube.forbidFocus = function (ms) { - HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); } - if(document.hidden) ms = 3*ms; - setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()" - } ImprovedTube.forbidFocus(2100); const descriptionTranscript = el.querySelector('ytd-video-description-transcript-section-renderer button[aria-label]'); descriptionTranscript ? descriptionTranscript.click() : el.querySelector('[target-id*=transcript]')?.removeAttribute('visibility'); @@ -354,22 +357,14 @@ ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript == /*---------------------------------------------------------------- CHAPTERS --------------------------------------------------------------*/ -ImprovedTube.forbidFocus = function (ms) { - HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); } - if(document.hidden) ms *= 3; - setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()" -} ImprovedTube.chapters = function (el) { if (ImprovedTube.storage.chapters === true) { - const available = el.querySelector('[target-id*=chapters][visibility*=HIDDEN]') - || el.querySelector('[target-id*=chapters]')?.clientHeight; + const available = el.querySelector('[target-id*=chapters][visibility*=HIDDEN]') || el.querySelector('[target-id*=chapters]')?.clientHeight; if (available) { - // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy) - if (!ImprovedTube.originalFocus) { ImprovedTube.originalFocus = HTMLElement.prototype.focus;} ImprovedTube.forbidFocus(2100); const modernChapters = el.querySelector('[modern-chapters] #navigation-button button[aria-label]'); modernChapters ? modernChapters.click() : el.querySelector('[target-id*=chapters]')?.removeAttribute('visibility'); if ( yt.config_.EXPERIMENT_FLAGS.kevlar_watch_grid === true ) { available.setAttribute('z-index', '98765') } - } + } }}; /*------------------------------------------------------------------------------ LIVECHAT @@ -508,12 +503,6 @@ ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer = function () { ------------------------------------------------------------------------------*/ ImprovedTube.expandDescription = function (el) { if (this.storage.description === "expanded") { - if (!ImprovedTube.originalFocus) { ImprovedTube.originalFocus = HTMLElement.prototype.focus;} // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy) - ImprovedTube.forbidFocus = function (ms) { - HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); } - if(document.hidden) ms = 3*ms; - setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()" - } if (el) { ImprovedTube.forbidFocus(2100); // setTimeout(function () {ImprovedTube.elements.player.focus();}, 2500); el.click(); From 02004ab5e9146e2d587094c2927b18209d16454b Mon Sep 17 00:00:00 2001 From: ImprovedTube Date: Tue, 7 Jan 2025 10:16:00 +0100 Subject: [PATCH 3/3] Update functions.js --- js&css/web-accessible/functions.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js&css/web-accessible/functions.js b/js&css/web-accessible/functions.js index bacd45f97..407c46521 100644 --- a/js&css/web-accessible/functions.js +++ b/js&css/web-accessible/functions.js @@ -405,9 +405,6 @@ ImprovedTube.playerOnPause = function (event) { }; -// if ( document.documentElement.dataset.pageType === 'video' -// && (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.transcript === true || ImprovedTube.storage.chapters === true )) { -// ImprovedTube.forbidFocus = function (ms) /*-------------------------------------------------------------- # HIDE PROGRESS BAR PREVIEW --------------------------------------------------------------*/