Skip to content

Commit 9d74f4c

Browse files
authored
1 parent 7b01d82 commit 9d74f4c

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

js&css/web-accessible/functions.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,9 @@ ImprovedTube.playerOnPause = function (event) {
405405

406406
};
407407

408-
if (document.documentElement.dataset.pageType === 'video'
409-
&& (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.transcript === true || ImprovedTube.storage.chapters === true )) {
410-
ImprovedTube.forbidFocus = function (ms) {
411-
originalFocus = HTMLElement.prototype.focus; // Backing up default method - other methods: Element.prototype.scrollIntoView window.scrollTo window.scrollBy
412-
// Override YouTube's scroll method:
413-
HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling, when expanding the video description for you"); }
414-
if(document.hidden) ms = 3*ms;
415-
setTimeout(function() { HTMLElement.prototype.focus = originalFocus; }, ms); // Restoring JS's "focus()"
416-
}
417-
}
418-
408+
// if ( document.documentElement.dataset.pageType === 'video'
409+
// && (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.transcript === true || ImprovedTube.storage.chapters === true )) {
410+
// ImprovedTube.forbidFocus = function (ms)
419411
/*--------------------------------------------------------------
420412
# HIDE PROGRESS BAR PREVIEW
421413
--------------------------------------------------------------*/

js&css/web-accessible/www.youtube.com/appearance.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ ImprovedTube.hideTopProgressBar = function () {
339339
ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript === true) {
340340
const available = el.querySelector('[target-id*=transcript][visibility*=HIDDEN]') || el.querySelector('[target-id*=transcript]')?.clientHeight;
341341
if (available) {
342+
if (!ImprovedTube.originalFocus) {ImprovedTube.originalFocus = HTMLElement.prototype.focus;} // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy)
343+
ImprovedTube.forbidFocus = function (ms) {
344+
HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); }
345+
if(document.hidden) ms = 3*ms;
346+
setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()"
347+
}
342348
ImprovedTube.forbidFocus(2100);
343349
const descriptionTranscript = el.querySelector('ytd-video-description-transcript-section-renderer button[aria-label]');
344350
descriptionTranscript ? descriptionTranscript.click() : el.querySelector('[target-id*=transcript]')?.removeAttribute('visibility');
@@ -351,6 +357,12 @@ ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript ==
351357
ImprovedTube.chapters = function (el) { if (ImprovedTube.storage.chapters === true) {
352358
const available = el.querySelector('[target-id*=chapters][visibility*=HIDDEN]') || el.querySelector('[target-id*=chapters]')?.clientHeight;
353359
if (available) {
360+
if (!ImprovedTube.originalFocus) { ImprovedTube.originalFocus = HTMLElement.prototype.focus;} // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy)
361+
ImprovedTube.forbidFocus = function (ms) {
362+
HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); }
363+
if(document.hidden) ms = 3*ms;
364+
setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()"
365+
}
354366
ImprovedTube.forbidFocus(2100);
355367
const modernChapters = el.querySelector('[modern-chapters] #navigation-button button[aria-label]');
356368
modernChapters ? modernChapters.click() : el.querySelector('[target-id*=chapters]')?.removeAttribute('visibility');
@@ -494,6 +506,12 @@ ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer = function () {
494506
------------------------------------------------------------------------------*/
495507
ImprovedTube.expandDescription = function (el) {
496508
if (this.storage.description === "expanded") {
509+
if (!ImprovedTube.originalFocus) { ImprovedTube.originalFocus = HTMLElement.prototype.focus;} // Backing up default method. Youtube doesn't use alternatives Element.prototype.scrollIntoView window.scrollTo window.scrollBy)
510+
ImprovedTube.forbidFocus = function (ms) {
511+
HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling for a moment."); }
512+
if(document.hidden) ms = 3*ms;
513+
setTimeout(function() { HTMLElement.prototype.focus = ImprovedTube.originalFocus; }, ms); // Restoring JS's "focus()"
514+
}
497515
if (el) {
498516
ImprovedTube.forbidFocus(2100); // setTimeout(function () {ImprovedTube.elements.player.focus();}, 2500);
499517
el.click();

js&css/web-accessible/www.youtube.com/shortcuts.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ ImprovedTube.shortcutResetPlaybackSpeed = function () {
374374
4.7.19 GO TO SEARCH BOX
375375
------------------------------------------------------------------------------*/
376376
ImprovedTube.shortcutGoToSearchBox = function () {
377-
if (originalFocus) { HTMLElement.prototype.focus = originalFocus }
378-
document.querySelector('input#search')?.focus(); //alternatively .click()
377+
document.querySelector('input#search')?.click();
378+
if (ImprovedTube.originalFocus) { HTMLElement.prototype.focus = originalFocus }
379+
document.querySelector('input#search')?.focus();
379380
};
380381
/*------------------------------------------------------------------------------
381382
4.7.20 ACTIVATE FULLSCREEN

0 commit comments

Comments
 (0)