Skip to content

Edit: Defining forbidFocus() once in advance, instead of inside features #2761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,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
--------------------------------------------------------------*/
Expand Down
27 changes: 9 additions & 18 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,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');
Expand All @@ -365,12 +368,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');
Expand Down Expand Up @@ -544,12 +541,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();
Expand Down
Loading