Skip to content

YT Polymer 2016 - Early 2019 script by mason20121981

Details

Authormason20121981

LicenseNo License

CategoryYoutube

Created

Updated

Size119 kB

Statistics

Learn how we calculate statistics in the FAQ.

Failed to fetch stats.

Description

Disables all features from YouTube after early 2019.

Notes

Userstyle doesn't have notes.

Source code

Source code has over 10K characters, so we truncated it. You can inspect the full source code on install link.
// ==UserScript==
// @name         YT Polymer 2016 - Early 2019 script
// @version      3.7.0
// @description  Disables all features from YouTube after early 2019.
// @author       Magma_Craft
// @license MIT
// @match        *://www.youtube.com/*
// @namespace    https://greasyfork.org/en/users/933798
// @icon         https://www.youtube.com/favicon.ico
// @run-at       document-start
// @require      https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// @grant        none
// ==/UserScript==

@-moz-document domain("youtube.com")
// Enable strict mode to catch common coding mistakes
"use strict";

// Define the flags to assign to the EXPERIMENT_FLAGS object
const flagsToAssign = {
  kevlar_system_icons: false,
  kevlar_refresh_on_theme_change: false,
  kevlar_watch_cinematics: false,
  kevlar_watch_grid: false,
  kevlar_watch_grid_hide_chips: false,
  kevlar_watch_metadata_refresh_no_old_secondary_data: false,
  enable_channel_page_header_profile_section: false,
  kevlar_modern_sd_v2: false,
  kevlar_watch_comments_panel_button: false,
  smartimation_background: false,
  web_animated_like: false,
  web_animated_like_lazy_load: false,
  web_modern_collections_v2: false,
  web_modern_tabs: false,
  web_modern_typography: false,
  web_enable_youtab: false,
  web_snackbar_ui_refresh: false,
  web_rounded_containers: false,
  web_rounded_thumbnails: false,
  web_watch_rounded_player_large: false,
  // Extra additions to remove the watch grid UI
  web_player_enable_featured_product_banner_exclusives_on_desktop: false,
  kevlar_watch_comments_panel_button: false,
  fill_view_models_on_web_vod: true,
  kevlar_watch_flexy_metadata_height: 136,
  kevlar_watch_max_player_width: 1280,
  live_chat_over_engagement_panels: false,
  live_chat_scaled_height: false,
  live_chat_smaller_min_height: false,
  main_app_controller_extraction_batch_18: false,
  main_app_controller_extraction_batch_19: false,
  no_iframe_for_web_stickiness: false,
  optimal_reading_width_comments_ep: false,
  remove_masthead_channel_banner_on_refresh: false,
  small_avatars_for_comments: false,
  small_avatars_for_comments_ep: false,
  web_watch_compact_comments: false,
  web_watch_compact_comments_header: false,
  web_watch_log_theater_mode: false,
  web_watch_theater_chat: false,
  web_watch_theater_fixed_chat: false,
  wn_grid_max_item_width: 0,
  wn_grid_min_item_width: 0
};

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 });

document.getElementsByTagName("html")[0].removeAttribute("system-icons");
document.getElementsByTagName("html")[0].removeAttribute("typography");
document.getElementsByTagName("html")[0].removeAttribute("typography-spacing");
document.getElementsByTagName("html")[0].removeAttribute("darker-dark-theme");
document.getElementsByTagName("html")[0].removeAttribute("darker-dark-theme-deprecate");



// Guide adjustments
// Regex to isolate UCID from your videos item
const VIDEOS_URL_REGEX = /(https:\/\/studio.youtube.com\/channel\/)|(\/videos)/g;

const gfconfig = {
    addTrending: true,
    libraryAsGuideSectionTitle: true,
    libraryFolderIcon: true,
    historyItemSignedOut: true,
    exploreSectionToBestOfYT: true,
    expandSubscriptionsSection: true,
    remove: {
        shorts: true,
        yourVideos: true,
        yourClips: true,
        exploreSectionSignedIn: true,
        librarySignedOut: true,
    }
};

const gfi18n = {
    en: {
        whatToWatch: "What to Watch",
        myChannel: "My channel"
    }
};

/**
 * Get a string from the localization strings.
 *
 * @param {string}   string  Name of string to get
 * @param {string}   hl      Language to use.
 * @param {...array} args    Strings.
 * @returns {string}
 */
function getString(string, hl = "en", ...args) {
    if (!string) return;
    var str;
    if (gfi18n[hl]) {
        if (gfi18n[hl][string]) {
            str = gfi18n[hl][string];
        } else if (gfi18n.en[string]) {
            str = gfi18n.en[string];
        } else {
            return;
        }
    } else {
        if (gfi18n.en[string]) str = gfi18n.en[string];
    }

    for (var i = 0; i < args.length; i++) {
        str = str.replace(/%s/, args[i]);
    }

    return str;
}

/**
 * Is the user signed in?
 *
 * @returns bool
 */
function isSignedIn() {
    return yt.config_.LOGGED_IN ?? false;
}

/**
 *
 * @param {object} sections  Guide sections array.
 * @param {string} icon      Icon type to look for
 */
function getItemByIcon(sections, icon) {
    for (var i = 0; i < sections.length; i++) {
        if (sections[i].guideSectionRenderer?.items) {
            var section = sections[i].guideSectionRenderer.items;
            for (var j = 0; j < section.length; j++) {
                if (section[j].guideEntryRenderer) {
                    if (section[j].guideEntryRenderer?.icon?.iconType == icon) {
                        return section[j];
                    }
                } else if (section[j]?.guideCollapsibleSectionEntryRenderer?.sectionItems) {
                    var colsection = section[j].guideCollapsibleSectionEntryRenderer.sectionItems;
                    for (var k = 0; k < colsection.length; k++) {
                        if (colsection[k].guideEntryRenderer) {
                            if (colsection[k].guideEntryRenderer?.icon?.iconType == icon) {
                                return colsection[k];
                            }
                        }
                    }
                }
            }
        }
    }
    return "Could not find item";
}

/**
 * Force Polymer to refresh data of an element.
 *
 * @param {Node} element  Element to refresh data of.
 */
function refreshData(element) {
    var clone = element.cloneNode();
    clone.data = element.data;
    // Let the script know we left our mark
    // in a way that doesn't rely on classes
    // because Polymer likes to cast comments
    // into the void for later reuse
    clone.data.fixedByGF = true;
    for (var i in element.properties) {
        clone[i] = element[i];
    }
    element.insertAdjacentElement("afterend", clone);
    element.remove();
}

/**
 * Modify the guide.
 *
 * @param {Node} guide  ytd-guide-renderer
 * @returns object
 */
function modifyGuide(guide) {
    if (gfconfig.remove.guideFooter) {
        waitForElm("#footer.ytd-guide-renderer").then((elm) => {
            elm.remove();
        });
    }

    var sections = guide.data.items;

    var mainSection = sections[0].guideSectionRenderer.items;
    for (var i = 0; i < mainSection.length; i++) {
        if (mainSection[i].guideEntryRenderer) {
            var item = mainSection[i].guideEntryRenderer;

            if (item.icon.iconType == "WHAT_TO_WATCH" && gfconfig.homeToWhatToWatch) {
                item.formattedTitle = {
                    simpleText: getString("whatToWatch", yt.config_.HL)
                };
            }

            if (item.icon.iconType == "TAB_SHORTS" && gfconfig.remove.shorts) {
                mainSection.splice(i, 1);
                i--;
            }

            if (item.icon.iconType == "SUBSCRIPTIONS") {
                if (gfconfig.addMyChannel && isSignedIn()) {
                    var yourVideos = getItemByIcon(sections, "MY_VIDEOS");
                    var ucid = yourVideos.guideEntryRenderer.navigationEndpoint.urlEndpoint.url.replace(VIDEOS_URL_REGEX, "");

                    mainSection.splice(i, 0, {
                        guideEntryRenderer: {
                            navigationEndpoint: {
                                clickTrackingParams: "CBwQtSwYASITCNqYh-qO_fACFcoRrQYdP44D9Q==",
                                commandMetadata: {
                                    webCommandMetadata: {
                                        url: "/channel/" + ucid,
                                        webPageType: "WEB_PAGE_TYPE_CHANNEL",
                                        rootVe: 6827,
                                        apiUrl: "/youtubei/v1/browse"
                                    }
                                },
                                browseEndpoint: {
                                    browseId: ucid
                                }
                            },
                            icon: {
                                iconType: "ACCOUNT_CIRCLE"
                            },
                            trackingParams: "CBwQtSwYASITCNqYh-qO_fACFcoRrQYdP44D9Q==",
                            formattedTitle: {
                                simpleText: getString("myChannel", yt.config_.HL)
                            },
                            accessibility: {
                                accessibilityData: {
                                    label: getString("myChannel", yt.config_.HL)
                                }
                            }
                        }
                    });
                    i++;
                }

                if (gfconfig.addTrending) {
                    mainSection.splice(i, 0, getItemByIcon(sections, "TRENDING"));
                    i++;
                }

                if (gfconfig.historyItemSignedOut && !isSignedIn()) {
                 ...

Reviews

No reviews yet.