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 --------------------------------------------------------------*/ diff --git a/js&css/web-accessible/www.youtube.com/appearance.js b/js&css/web-accessible/www.youtube.com/appearance.js index f1de8ba93..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'); @@ -357,12 +360,6 @@ ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript == ImprovedTube.chapters = function (el) { if (ImprovedTube.storage.chapters === true) { const available = el.querySelector('[target-id*=chapters][visibility*=HIDDEN]') || el.querySelector('[target-id*=chapters]')?.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 modernChapters = el.querySelector('[modern-chapters] #navigation-button button[aria-label]'); modernChapters ? modernChapters.click() : el.querySelector('[target-id*=chapters]')?.removeAttribute('visibility'); @@ -506,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();