diff --git a/background.js b/background.js index 81506ba59..93473d422 100644 --- a/background.js +++ b/background.js @@ -24,12 +24,17 @@ }); */ /*--------------------------- -# IMPORTING OLD SETTINGS +# IMPORTING OLD (renamed) SETTINGS (Each one is mostly needed once, but fine to stay unlimited. Legacy.) -----------------------------*/ chrome.runtime.onInstalled.addListener(function (installed) { if (installed.reason == 'update') { // var thisVersion = chrome.runtime.getManifest().version; // console.log("Updated from " + installed.previousVersion + " to " + thisVersion + "!"); + chrome.storage.local.get('description', function (result) { + if (result.description === 'classic_expanded') { + chrome.storage.local.set({description: 'expanded'}); + } + }); // Shortcut renames: chrome.storage.local.get(['shortcut_auto', 'shortcut_144p', 'shortcut_240p', 'shortcut_360p', 'shortcut_480p', 'shortcut_720p', 'shortcut_1080p', 'shortcut_1440p', 'shortcut_2160p', 'shortcut_2880p', 'shortcut_4320p'], function (result) { // validate and move to new name diff --git a/js&css/web-accessible/www.youtube.com/appearance.js b/js&css/web-accessible/www.youtube.com/appearance.js index 24e80ee0f..9dce3baec 100644 --- a/js&css/web-accessible/www.youtube.com/appearance.js +++ b/js&css/web-accessible/www.youtube.com/appearance.js @@ -422,14 +422,26 @@ ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer = function () { EXPAND DESCRIPTION ------------------------------------------------------------------------------*/ ImprovedTube.expandDescription = function (el) { - if (this.storage.description === "expanded" || this.storage.description === "classic_expanded") { - if (el) {el.click(); setTimeout(function () {ImprovedTube.elements.player.focus();}, 1200); } - else { var tries = 0; var intervalMs = 210; if (location.href.indexOf('/watch?') !== -1) {var maxTries = 10;} else {var maxTries = 0;} - // ...except when it is an embedded player? + if (this.storage.description === "expanded") { + ImprovedTube.forbidFocus = function (ms) { + const 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"); } + setTimeout(() => { HTMLElement.prototype.focus = originalFocus;}, ms); // Restoring JS's "focus()" + } + if (el) { + try { ImprovedTube.forbidFocus(2000); } catch { setTimeout(function () {ImprovedTube.elements.player.focus();}, 1200); } + el.click(); + } + else { // this rest will be unnecessary with proper timing: + var tries = 0; var intervalMs = 210; if (location.href.indexOf('/watch?') !== -1) {var maxTries = 10;} else {var maxTries = 0;} // ...except when it is an embedded player? var waitForDescription = setInterval(() => { if (++tries >= maxTries) { + if (el) { + try { ImprovedTube.forbidFocus(2000); } catch { setTimeout(function () {ImprovedTube.elements.player.focus();}, 1000); } + el.click(); + } el = document.querySelector('#description-inline-expander') - if ( el) { el.click(); setTimeout(function () {ImprovedTube.elements.player.focus(); }, 1200); clearInterval(waitForDescription); } intervalMs *= 1.11; }}, intervalMs); } }