YouTube Web Tweaks lite edition

This is the version of YouTube Web Tweaks but without patch collection integrated into it. Also includes VP9/AV1 disabler script that optimizes video playback on very-low end computers.

// ==UserScript==
// @name         YouTube Web Tweaks lite edition
// @version      1.6.8
// @description  This is the version of YouTube Web Tweaks but without patch collection integrated into it. Also includes VP9/AV1 disabler script that optimizes video playback on very-low end computers.
// @author       Magma_Craft
// @license MIT
// @match        *://www.youtube.com/*
// @match        *://www.youtube-nocookie.com/*
// @match        *://www.youtu.be/*
// @namespace    https://greasyfork.org/en/users/933798
// @icon         https://www.youtube.com/favicon.ico
// @unwrap
// @run-at       document-start
// @unwrap
// @grant        none
// ==/UserScript==

(function() {
let css = `
/* Remove minimal annoyances */
ytd-ad-slot-renderer, div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer, ytm-promoted-sparkles-web-renderer, ytd-video-quality-promo-renderer, ytd-merch-shelf-renderer, ytd-enforcement-message-view-model, div[is-shared-heimdall], tp-yt-iron-overlay-backdrop.opened, ytd-promoted-sparkles-web-renderer, ytd-text-image-no-button-layout-renderer {
display: none !important
}

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

/* Remove every unwanted compact renderer in related section and limit the number of yt-lockup-view-model to 9 */
#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
}`;
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);
  };
})();