Skip to content

Commit

Permalink
#2251 Youtube's experiment flags, more gracefully (+typo #2520 #2521 #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube authored Aug 9, 2024
1 parent 053505e commit a5abd29
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
@@ -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) {

Check warning on line 6 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
// Flag, Value, Handler, Target, Property
const H = {

Check warning on line 8 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
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 });
Expand Down

0 comments on commit a5abd29

Please sign in to comment.