YouTube Web Tweaks ultimate edition

This script was based on YouTube Web Tweaks lite but converted into ultimate package (which includes both Action Buttons Fix and other stuff from the force rounded corners scripts)

// ==UserScript==
// @name         YouTube Web Tweaks ultimate edition
// @version      2025.08.30
// @description  This script was based on YouTube Web Tweaks lite but converted into ultimate package (which includes both Action Buttons Fix and other stuff from the force rounded corners scripts)
// @author       Joey_JTS
// @license MIT
// @match        *://www.youtube.com/*
// @match        *://www.youtube-nocookie.com/*
// @match        *://www.youtu.be/*
// @namespace    https://greasyfork.org/en/users/761382
// @icon         https://www.youtube.com/favicon.ico
// @unwrap
// @run-at       document-end
// @unwrap
// @grant        none
// ==/UserScript==

// Enable strict mode to catch common coding mistakes
"use strict";

// Define the flags to assign to the EXPERIMENT_FLAGS object
const flagsToAssign = {
  // Standard tweaks (YT config editor + Disable animations)
  IS_TABLET: true,
  DISABLE_YT_IMG_DELAY_LOADING: true,
  polymer_verifiy_app_state: false,
  desktop_delay_player_resizing: false,
  web_animated_actions: false,
  web_animated_like: false,
  web_animated_like_lazy_load: false,
  render_unicode_emojis_as_small_images: true,
  smartimation_background: false,
  kevlar_refresh_on_theme_change: false,
  // Disable cinematics (aka ambient lighting)
  kevlar_measure_ambient_mode_idle: false,
  kevlar_watch_cinematics_invisible: false,
  web_cinematic_theater_mode: false,
  web_cinematic_fullscreen: false,
  enable_cinematic_blur_desktop_loading: false,
  kevlar_watch_cinematics: false,
  web_cinematic_masthead: false,
  web_watch_cinematics_preferred_reduced_motion_default_disabled: false
};

const updateFlags = () => {
  // Check if the EXPERIMENT_FLAGS object exists in the window.yt.config_ property chain
  const expFlags = window?.yt?.config_?.EXPERIMENT_FLAGS;

  // If EXPERIMENT_FLAGS is not found, exit the function
  if (!expFlags) return;

  // Assign the defined flags to the EXPERIMENT_FLAGS object
  Object.assign(expFlags, flagsToAssign);
};

// Create a MutationObserver that calls the updateFlags function when changes occur in the document's subtree
const mutationObserver = new MutationObserver(updateFlags);
mutationObserver.observe(document, { subtree: true, childList: true });

(function() {
let css = `
/* Remove all annoyances (including 'shorts' section) */
ytd-merch-shelf-renderer,
ytd-action-companion-ad-renderer,
ytd-display-ad-renderer,
ytd-video-masthead-ad-advertiser-info-renderer,
ytd-video-masthead-ad-primary-video-renderer,
ytd-in-feed-ad-layout-renderer,
ytd-ad-slot-renderer,
ytd-statement-banner-renderer,
ytd-banner-promo-renderer-background,
ytd-ad-slot-renderer,
ytd-in-feed-ad-layout-renderer,
.ytwPanelAdHeaderImageLockupViewModelHost,
ytd-ads-engagement-panel-content-renderer,
#content.ytd-ads-engagement-panel-content-renderer,
ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-ads"],
ytd-rich-item-renderer:has(> #content > ytd-ad-slot-renderer),
.ytd-video-masthead-ad-v3-renderer,
div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint,
div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer,
div#main-container.style-scope.ytd-promoted-video-renderer,
div#player-ads.style-scope.ytd-watch-flexy,
#clarify-box,
yt-about-this-ad-renderer,
masthead-ad,
ad-slot-renderer,
yt-mealbar-promo-renderer,
statement-banner-style-type-compact,
ytm-promoted-sparkles-web-renderer,
tp-yt-iron-overlay-backdrop,
#masthead-ad,
#expandable-metadata,
.ytGridShelfViewModelHost,
.ytd-search ytd-shelf-renderer,
ytd-reel-shelf-renderer,
ytd-rich-section-renderer {
display: none !important
}

.style-scope[page-subtype='channels'] ytd-shelf-renderer,
.style-scope[page-subtype='channels'] ytm-shelf-renderer {
display: block !important
}

/* Watch page tweaks (including CSS for 'action buttons fix') */
#comment-teaser,
teaser-carousel {
display: none !important
}

ytd-horizontal-card-list-renderer[modern-chapters][card-list-style=HORIZONTAL_CARD_LIST_STYLE_TYPE_ENGAGEMENT_PANEL_SECTION],
ytd-video-description-infocards-section-renderer.style-scope.ytd-structured-description-content-renderer > #header.ytd-video-description-infocards-section-renderer,
ytd-video-description-infocards-section-renderer.style-scope.ytd-structured-description-content-renderer > #action-buttons.ytd-video-description-infocards-section-renderer,
#social-links.ytd-video-description-infocards-section-renderer {
display: none !important
}

ytd-video-description-infocards-section-renderer.style-scope.ytd-structured-description-content-renderer {
border-top: 0 !important
}

#paid-comment-images,
#paid-comment-chip > .yt-pdg-comment-chip-renderer.style-scope,
#paid-comment-background {
display: none !important
}

#actions.ytd-watch-metadata {
min-width: auto !important
}

yt-button-view-model.ytd-menu-renderer .yt-spec-button-shape-next--size-m, ytd-download-button-renderer .yt-spec-button-shape-next--size-m, .yt-spec-button-shape-next--size-m[aria-label="Promote"], #loop-button > .yt-spec-button-shape-next--size-m {
margin-left: 8px !important
}

#flexible-item-buttons .ytd-menu-renderer, #top-level-buttons-computed yt-button-view-model.ytd-menu-renderer, ytd-button-renderer#loop-button {
margin-left: 0 !important
}

.yt-spec-button-shape-next--size-m[aria-label="Promote"],
#flexible-item-buttons [aria-label="Promote"] {
display: none !important
}

.yt-spec-button-shape-next--size-m[aria-label="Ask"],
#flexible-item-buttons [aria-label="Ask"] {
display: none !important
}

ytd-watch-metadata.ytd-watch-flexy {
padding-bottom: 36px !important
}

.html5-endscreen.ytp-player-content.videowall-endscreen.ytp-show-tiles {
display: none !important
}

#related ytd-compact-video-renderer, ytd-compact-movie-renderer, #related ytd-compact-playlist-renderer, #related ytd-compact-radio-renderer, #related yt-lockup-view-model, #related ytd-channel-renderer, ytd-watch-flexy ytd-reel-shelf-renderer, ytd-watch-flexy ytd-rich-section-renderer, #related ytd-continuation-item-renderer, #related #continuations {
display: none !important
}

#related yt-lockup-view-model:nth-of-type(1), #related yt-lockup-view-model:nth-of-type(2), #related yt-lockup-view-model:nth-of-type(3), #related yt-lockup-view-model:nth-of-type(4), #related yt-lockup-view-model:nth-of-type(5), #related yt-lockup-view-model:nth-of-type(6), #secondary #related yt-lockup-view-model:nth-of-type(7), #secondary #related yt-lockup-view-model:nth-of-type(8), #secondary #related yt-lockup-view-model:nth-of-type(9) {
display: flex !important
}

/* More tweaks */
#channel-header-links.style-scope.ytd-c4-tabbed-header-renderer,
.page-header-view-model-wiz__page-header-attribution,
.yt-page-header-view-model__page-header-attribution {
display: none !important
}

#chip-bar.style-scope.ytd-search-header-renderer,
[page-subtype="playlist"] ytd-feed-filter-chip-bar-renderer {
display: none !important
}

ytd-search-header-renderer .yt-spec-button-shape-next--size-m {
flex-direction: row-reverse
}

ytd-search-header-renderer .yt-spec-button-shape-next--size-m.yt-spec-button-shape-next--icon-trailing .yt-spec-button-shape-next__icon {
margin-left: -6px;
margin-right: 6px
}

[is-search] ytd-shelf-renderer.ytd-item-section-renderer:not(ytd-channel-renderer + ytd-shelf-renderer),
[is-search] ytd-horizontal-card-list-renderer.ytd-item-section-renderer:not(:first-child),
[is-search] ytd-exploratory-results-renderer.ytd-item-section-renderer {
display: none !important
}

ytd-guide-entry-renderer > a[href*="/channel/UCtFRv9O2AHqOZjjynzrv-xg"],
ytd-guide-entry-renderer > a[href*="/feed/courses_destination"],
ytd-guide-entry-renderer > a[href*="/channel/UCrpQ4p1Ql_hG8rKXIKM1MOQ"],
ytd-guide-entry-renderer > a[href*="/channel/UCkYQyvc_i9hXEo4xic9Hh2g"],
ytd-guide-entry-renderer > a[href*="/podcasts"],
ytd-guide-entry-renderer > a[href*="/feed/podcasts"] {
display: none !important
}

ytd-download-button-renderer,
ytd-guide-entry-renderer > a[href*="/feed/downloads"],
ytd-mini-guide-entry-renderer > a[href*="/feed/downloads"] {
display: none !important
}

#footer.style-scope.ytd-guide-renderer {
display: none !important
}`;
if (typeof GM_addStyle !== "undefined") {
  GM_addStyle(css);
} else {
  let styleNode = document.createElement("style");
  styleNode.appendChild(document.createTextNode(css));
  (document.querySelector("head") || document.documentElement).appendChild(styleNode);
}
})();

// Force h264-only codec and disables WebGL script codes
var mse = window.MediaSource;
if (mse){
  // Set up replacement for MediaSource type support function
  var nativeITS = mse.isTypeSupported.bind(mse);
  mse.isTypeSupported = ourITS(nativeITS);
}
// Here's the replacement
function ourITS(fallback){
  // type is a string (hopefully!) sent by the page
  return function (type) {
    if (type === undefined) return '';
    // We only reject VP9
    if (type.toLowerCase().indexOf('vp9') > -1) return '';
    if (type.toLowerCase().indexOf('vp09') > -1) return ''; // Added 12/20/2019
    // Let Firefox handle everything else
    return fallback(type);
  };
}
 
//
// What is this userscript trying to address?
// When playing a video, only a small part of the video loads, and the subsequent
// parts do not load afterward.

(function () {
  "use strict";

  const originalGetContext = HTMLCanvasElement.prototype.getContext;
  HTMLCanvasElement.prototype.getContext = function (contextType) {
    if (contextType === "webgl" || contextType === "webgl2") {
      console.log("WebGL is disabled by Tampermonkey");
      return null;
    }
    return originalGetContext.apply(this, arguments);
  };
})();

/* Add action buttons fix code */ 
const abtnconfig = {
    unsegmentLikeButton: false,
    noFlexibleItems: true
};
 
function updateBtns() {
    var watchFlexy = document.querySelector("ytd-watch-flexy");
    var results = watchFlexy.data.contents.twoColumnWatchNextResults.results.results.contents;
 
    for (var i = 0; i < results.length; i++) {
        if (results[i].videoPrimaryInfoRenderer) {
            var actions = results[i].videoPrimaryInfoRenderer.videoActions.menuRenderer;
 
            if (abtnconfig.unsegmentLikeButton) {
                if (actions.topLevelButtons[0].segmentedLikeDislikeButtonRenderer) {
                    var segmented = actions.topLevelButtons[0].segmentedLikeDislikeButtonRenderer;
                    actions.topLevelButtons.splice(0, 1);
                    actions.topLevelButtons.unshift(segmented.dislikeButton);
                    actions.topLevelButtons.unshift(segmented.likeButton);
                }
            }
 
            if (abtnconfig.noFlexibleItems) {
                for (var i = 0; i < actions.flexibleItems.length; i++) {
                    actions.topLevelButtons.push(actions.flexibleItems[i].menuFlexibleItemRenderer.topLevelButton);
                }
 
                delete actions.flexibleItems
            }
        }
    }
 
    var temp = watchFlexy.data;
    watchFlexy.data = {};
    watchFlexy.data = temp;
}
 
document.addEventListener("yt-page-data-updated", (e) => {
    if (e.detail.pageType == "watch") {
        updateBtns();
    }
});