@@ -339,6 +339,12 @@ ImprovedTube.hideTopProgressBar = function () {
339
339
ImprovedTube . transcript = function ( el ) { if ( ImprovedTube . storage . transcript === true ) {
340
340
const available = el . querySelector ( '[target-id*=transcript][visibility*=HIDDEN]' ) || el . querySelector ( '[target-id*=transcript]' ) ?. clientHeight ;
341
341
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
+ }
342
348
ImprovedTube . forbidFocus ( 2100 ) ;
343
349
const descriptionTranscript = el . querySelector ( 'ytd-video-description-transcript-section-renderer button[aria-label]' ) ;
344
350
descriptionTranscript ? descriptionTranscript . click ( ) : el . querySelector ( '[target-id*=transcript]' ) ?. removeAttribute ( 'visibility' ) ;
@@ -351,6 +357,12 @@ ImprovedTube.transcript = function (el) { if (ImprovedTube.storage.transcript ==
351
357
ImprovedTube . chapters = function ( el ) { if ( ImprovedTube . storage . chapters === true ) {
352
358
const available = el . querySelector ( '[target-id*=chapters][visibility*=HIDDEN]' ) || el . querySelector ( '[target-id*=chapters]' ) ?. clientHeight ;
353
359
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
+ }
354
366
ImprovedTube . forbidFocus ( 2100 ) ;
355
367
const modernChapters = el . querySelector ( '[modern-chapters] #navigation-button button[aria-label]' ) ;
356
368
modernChapters ? modernChapters . click ( ) : el . querySelector ( '[target-id*=chapters]' ) ?. removeAttribute ( 'visibility' ) ;
@@ -494,6 +506,12 @@ ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer = function () {
494
506
------------------------------------------------------------------------------*/
495
507
ImprovedTube . expandDescription = function ( el ) {
496
508
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
+ }
497
515
if ( el ) {
498
516
ImprovedTube . forbidFocus ( 2100 ) ; // setTimeout(function () {ImprovedTube.elements.player.focus();}, 2500);
499
517
el . click ( ) ;
0 commit comments