Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube authored Dec 27, 2024
1 parent 7b01d82 commit 9d74f4c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
14 changes: 3 additions & 11 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,9 @@ 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) {
originalFocus = HTMLElement.prototype.focus; // Backing up default method - other methods: Element.prototype.scrollIntoView window.scrollTo window.scrollBy
// Override YouTube's scroll method:
HTMLElement.prototype.focus = function() {console.log("Preventing YouTube's scripted scrolling, when expanding the video description for you"); }
if(document.hidden) ms = 3*ms;
setTimeout(function() { HTMLElement.prototype.focus = originalFocus; }, ms); // Restoring JS's "focus()"
}
}

// if ( document.documentElement.dataset.pageType === 'video'
// && (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.transcript === true || ImprovedTube.storage.chapters === true )) {

Check warning on line 409 in js&css/web-accessible/functions.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
// ImprovedTube.forbidFocus = function (ms)
/*--------------------------------------------------------------
# HIDE PROGRESS BAR PREVIEW
--------------------------------------------------------------*/
Expand Down
18 changes: 18 additions & 0 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ ImprovedTube.hideTopProgressBar = function () {
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 @@ -351,6 +357,12 @@ 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 @@ -494,6 +506,12 @@ 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
5 changes: 3 additions & 2 deletions js&css/web-accessible/www.youtube.com/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ ImprovedTube.shortcutResetPlaybackSpeed = function () {
4.7.19 GO TO SEARCH BOX
------------------------------------------------------------------------------*/
ImprovedTube.shortcutGoToSearchBox = function () {
if (originalFocus) { HTMLElement.prototype.focus = originalFocus }
document.querySelector('input#search')?.focus(); //alternatively .click()
document.querySelector('input#search')?.click();
if (ImprovedTube.originalFocus) { HTMLElement.prototype.focus = originalFocus }
document.querySelector('input#search')?.focus();
};
/*------------------------------------------------------------------------------
4.7.20 ACTIVATE FULLSCREEN
Expand Down

0 comments on commit 9d74f4c

Please sign in to comment.