From a5abd29617e5a185ee9cdfd1e033a2630342465e Mon Sep 17 00:00:00 2001 From: ImprovedTube Date: Fri, 9 Aug 2024 04:50:31 +0200 Subject: [PATCH] #2251 Youtube's experiment flags, more gracefully (+typo #2520 #2521 #2519 #2517) --- .../www.youtube.com/appearance.js | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/js&css/web-accessible/www.youtube.com/appearance.js b/js&css/web-accessible/www.youtube.com/appearance.js index 29205a9af..0c3f7a3c5 100644 --- a/js&css/web-accessible/www.youtube.com/appearance.js +++ b/js&css/web-accessible/www.youtube.com/appearance.js @@ -1,26 +1,40 @@ /*------------------------------------------------------------------------------ APPEARANCE ------------------------------------------------------------------------------*/ -ImprovedTube.YouTubeExperiments = function { if (document.documentElement.dataset.pageType === 'video' && window.yt?.config_?.EXPERIMENT_FLAGS) { - ImprovedTube.overrideFlags = function (flags, value) { - yt.config_.EXPERIMENT_FLAGS = new Proxy(yt.config_.EXPERIMENT_FLAGS, { - get: (t, p) => flags.includes(prop) ? value : t[p], // target & prop - set: () => true - }); - }; - if (this.storage.undo_the_new_sidebar) { - ImprovedTube.overrideFlags( - ['kevlar_watch_grid', 'small_avatars_for_comments', 'small_avatars_for_comments_ep', 'web_watch_rounded_player_large'], - false - ); - }; - if (this.storage.description === "sidebar") { - ImprovedTube.overrideFlags( - ['kevlar_watch_grid', 'small_avatars_for_comments', 'small_avatars_for_comments_ep'], - true - ); - }; -}} +ImprovedTube.YouTubeExperiments = function () { + if (document.documentElement.dataset.pageType === 'video' && window.yt?.config_?.EXPERIMENT_FLAGS) { + ImprovedTube.overrideFlag = function (F, V) { + // Flag, Value, Handler, Target, Property + const H = { + get: (T, P) => P === F ? V : T[P], + set: (T, P, value) => P === F ? true : Reflect.set(T, P, value) + }; + if (window.yt.config_.EXPERIMENT_FLAGS.hasOwnProperty(F)) { + window.yt.config_.EXPERIMENT_FLAGS[F] = new Proxy(window.yt.config_.EXPERIMENT_FLAGS[F], H); + } else { + window.yt.config_.EXPERIMENT_FLAGS[F] = new Proxy({}, H); + } + }; + 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 && window.yt.config_.EXPERIMENT_FLAGS.kevlar_watch_grid !== false) { + try { + newSidebarFlags.forEach(F => ImprovedTube.overrideFlag(F, false)); + } catch (error) { + console.error("can't undo description on the side", error); + } + } + if (this.storage.description === "sidebar" && window.yt.config_.EXPERIMENT_FLAGS.kevlar_watch_grid !== true) { + try { + newSidebarFlags.forEach(F => ImprovedTube.overrideFlag(F, true)); + } catch (error) { + console.error("tried to move description to the sidebar", error); + } + } + } +} /* if (document.documentElement.dataset.pageType === 'video' && window.yt?.config_?.EXPERIMENT_FLAGS) { ['kevlar_watch_grid', 'small_avatars_for_comments', 'small_avatars_for_comments_ep', 'web_watch_rounded_player_large'].forEach(flag => { Object.defineProperty(yt.config_.EXPERIMENT_FLAGS, flag, { get: () => false });