Skip to content
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

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

Open
wants to merge 4 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 @@ -227,14 +227,14 @@
setTimeout(function () {ImprovedTube.expandDescription(node);}, 300);
} else if (id === 'meta') {setTimeout(function () {ImprovedTube.expandDescription(node.querySelector('#more'));}, 200);
// } else if (id === 'below') { setTimeout(function () {}, 0);
} else if (id === 'panels') { setTimeout(function () { ImprovedTube.transcript(node); ImprovedTube.chapters(node);ImprovedTube.elements.panels = node;}, 200);

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

View workflow job for this annotation

GitHub Actions / lint-and-test

Missing whitespace after semicolon
} /* else if (name === 'TP-YT-PAPER-BUTTON') {
if ( (id === 'expand-sizer' || id === 'expand') && node.parentNode.id === 'description-inline-expander') {
setTimeout(function () {
ImprovedTube.expandDescription(node); console.log("EXPAND DESCRIPTION, OLD WAY")
}, 750);
}} */
} else if (id === 'panels') {

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

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
ImprovedTube.elements.panels = node;
}
};
Expand Down Expand Up @@ -405,19 +405,16 @@

};

// 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
--------------------------------------------------------------*/

ImprovedTube.playerHideProgressPreview = function () {
const shouldHide = this.storage.player_hide_progress_preview === true;

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

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
if (shouldHide) {
document.documentElement.setAttribute('it-hide-progress-preview', 'true');

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

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
// Force refresh the player UI
if (this.elements.player) {
this.elements.player.dispatchEvent(new Event('mousemove'));
Expand Down Expand Up @@ -450,13 +447,13 @@
ImprovedTube.onkeydown = function () {
ImprovedTube.pauseWhileTypingOnYoutube()
window.addEventListener('keydown', function () {
ImprovedTube.user_interacted = true; // = event.key

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

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
}, true);
};

ImprovedTube.onmousedown = function (event) {
window.addEventListener('mousedown', function (event) {
ImprovedTube.user_interacted = true; // = mousedown

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

View workflow job for this annotation

GitHub Actions / lint-and-test

Multiple spaces found before '// = mousedown'
}, true);
};

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 @@ -2,16 +2,16 @@
APPEARANCE
------------------------------------------------------------------------------*/
ImprovedTube.YouTubeExperiments = function () {
if ((this.storage.undo_the_new_sidebar === "true" || this.storage.description === "sidebar")

Check warning on line 5 in js&css/web-accessible/www.youtube.com/appearance.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
&& document.documentElement.dataset.pageType === 'video') {
if (window.yt?.config_?.EXPERIMENT_FLAGS) {

Check warning on line 7 in js&css/web-accessible/www.youtube.com/appearance.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
const newSidebarFlags = [
'kevlar_watch_grid',
'small_avatars_for_comments',
'small_avatars_for_comments_ep',
'web_watch_rounded_player_large'
];
if (this.storage.undo_the_new_sidebar === "true") {

Check warning on line 14 in js&css/web-accessible/www.youtube.com/appearance.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
if (window.yt.config_.EXPERIMENT_FLAGS.kevlar_watch_grid !== false) {
try {
newSidebarFlags.forEach(F => {
Expand Down Expand Up @@ -333,18 +333,21 @@
/*------------------------------------------------------------------------------
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 @@ -357,12 +360,6 @@
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 @@ -506,12 +503,6 @@
------------------------------------------------------------------------------*/
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