Skip to content

old youtube playersa by ShimmerFromMagix

Details

AuthorShimmerFromMagix

LicenseNo License

Categoryyoutube.com

Created

Updated

Size158 kB

Statistics

Learn how we calculate statistics in the FAQ.

Failed to fetch stats.

Description

ikd

Notes

youtube

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 Mid 2019 - Early 2021 script
// @version      2.6.4
// @description  Modifies things like the old icons and more stuff prior to March 2021. Works best with YT Late '19-Mid '20 and CSS tweaks for NRD userstyle.
// @author       Magma_Craft
// @license MIT                                                                                    
// @-moz-document domain("youtube.com")
// @match        *://www.youtube.com/*
// @namespace    https://greasyfork.org/en/users/933798
// @icon         https://www.youtube.com/favicon.ico
// @run-at       moz-document 
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// ==/UserScript==
// ==/UserScript==
 
// Attributes to remove from <html>
const ATTRS = [
    "refresh",
    "system-icons",
    "darker-dark-theme",
    "darker-dark-theme-deprecate",
    "typography",
    "typography-spacing"
];
 
// Regular config keys.
const CONFIGS = {
    BUTTON_REWORK: true
}
 
// Experiment flags.
const EXPFLAGS = {
    kevlar_system_icons: false,
    enable_channel_page_header_profile_section: false,
    enable_header_channel_handler_ui: false,
    kevlar_unavailable_video_error_ui_client: false,
    kevlar_refresh_on_theme_change: false,
    kevlar_modern_sd_v2: false,
    kevlar_watch_cinematics: false,
    kevlar_watch_comments_panel_button: false,
    kevlar_watch_grid: false,
    kevlar_watch_grid_hide_chips: false,
    kevlar_watch_metadata_refresh_no_old_secondary_data: false,
    kevlar_watch_metadata_refresh_attached_subscribe: false,
    kevlar_watch_metadata_refresh_clickable_description: false,
    kevlar_watch_metadata_refresh_compact_view_count: false,
    kevlar_watch_metadata_refresh_description_info_dedicated_line: false,
    kevlar_watch_metadata_refresh_description_inline_expander: false,
    kevlar_watch_metadata_refresh_description_primary_color: false,
    kevlar_watch_metadata_refresh_for_live_killswitch: false,
    kevlar_watch_metadata_refresh_full_width_description: false,
    kevlar_watch_metadata_refresh_narrower_item_wrap: false,
    kevlar_watch_metadata_refresh_relative_date: false,
    kevlar_watch_modern_panels: false,
    kevlar_watch_panel_height_matches_player: false,
    smartimation_background: false,
    web_amsterdam_playlists: false,
    web_animated_actions: false,
    web_animated_like: false,
    web_button_rework: true,
    web_button_rework_with_live: true,
    web_darker_dark_theme: false,
    web_enable_youtab: false,
    web_guide_ui_refresh: false,
    web_modern_ads: false,
    web_modern_buttons: true,
    web_modern_chips: false,
    web_modern_collections_v2: false,
    web_modern_dialogs: false,
    web_modern_playlists: false,
    web_modern_subscribe: true,
    web_modern_tabs: false,
    web_modern_typography: false,
    web_rounded_containers: false,
    web_rounded_thumbnails: false,
    web_searchbar_style: "default",
    web_segmented_like_dislike_button: false,
    web_sheets_ui_refresh: false,
    web_snackbar_ui_refresh: 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
}
 
// Player flags
// !!! USE STRINGS FOR VALUES !!!
// For example: "true" instead of true
const PLYRFLAGS = {
    web_rounded_containers: "false",
    web_rounded_thumbnails: "false"
}
 
class YTP {
    static observer = new MutationObserver(this.onNewScript);
 
    static _config = {};
 
    static isObject(item) {
        return (item && typeof item === "object" && !Array.isArray(item));
    }
 
    static mergeDeep(target, ...sources) {
        if (!sources.length) return target;
        const source = sources.shift();
 
        if (this.isObject(target) && this.isObject(source)) {
            for (const key in source) {
                if (this.isObject(source[key])) {
                    if (!target[key]) Object.assign(target, { [key]: {} });
                    this.mergeDeep(target[key], source[key]);
                } else {
                    Object.assign(target, { [key]: source[key] });
                }
            }
        }
 
        return this.mergeDeep(target, ...sources);
    }
 
 
    static onNewScript(mutations) {
        for (var mut of mutations) {
            for (var node of mut.addedNodes) {
                YTP.bruteforce();
            }
        }
    }
 
    static start() {
        this.observer.observe(document, {childList: true, subtree: true});
    }
 
    static stop() {
        this.observer.disconnect();
    }
 
    static bruteforce() {
        if (!window.yt) return;
        if (!window.yt.config_) return;
 
        this.mergeDeep(window.yt.config_, this._config);
    }
 
    static setCfg(name, value) {
        this._config[name] = value;
    }
 
    static setCfgMulti(configs) {
        this.mergeDeep(this._config, configs);
    }
 
    static setExp(name, value) {
        if (!("EXPERIMENT_FLAGS" in this._config)) this._config.EXPERIMENT_FLAGS = {};
 
        this._config.EXPERIMENT_FLAGS[name] = value;
    }
 
    static setExpMulti(exps) {
        if (!("EXPERIMENT_FLAGS" in this._config)) this._config.EXPERIMENT_FLAGS = {};
 
        this.mergeDeep(this._config.EXPERIMENT_FLAGS, exps);
    }
 
    static decodePlyrFlags(flags) {
        var obj = {},
            dflags = flags.split("&");
 
        for (var i = 0; i < dflags.length; i++) {
            var dflag = dflags[i].split("=");
            obj[dflag[0]] = dflag[1];
        }
 
        return obj;
    }
 
    static encodePlyrFlags(flags) {
        var keys = Object.keys(flags),
            response = "";
 
        for (var i = 0; i < keys.length; i++) {
            if (i > 0) {
                response += "&";
            }
            response += keys[i] + "=" + flags[keys[i]];
        }
 
        return response;
    }
 
    static setPlyrFlags(flags) {
        if (!window.yt) return;
        if (!window.yt.config_) return;
        if (!window.yt.config_.WEB_PLAYER_CONTEXT_CONFIGS) return;
        var conCfgs = window.yt.config_.WEB_PLAYER_CONTEXT_CONFIGS;
        if (!("WEB_PLAYER_CONTEXT_CONFIGS" in this._config)) this._config.WEB_PLAYER_CONTEXT_CONFIGS = {};
 
        for (var cfg in conCfgs) {
            var dflags = this.decodePlyrFlags(conCfgs[cfg].serializedExperimentFlags);
            this.mergeDeep(dflags, flags);
            this._config.WEB_PLAYER_CONTEXT_CONFIGS[cfg] = {
                serializedExperimentFlags: this.encodePlyrFlags(dflags)
            }
        }
    }
}
 
window.addEventListener("yt-page-data-updated", function tmp() {
    YTP.stop();
    for (i = 0; i < ATTRS.length; i++) {
        document.getElementsByTagName("html")[0].removeAttribute(ATTRS[i]);
    }
    window.removeEventListener("yt-page-date-updated", tmp);
});
 
YTP.start();
 
YTP.setCfgMulti(CONFIGS);
YTP.setExpMulti(EXPFLAGS);
YTP.setPlyrFlags(PLYRFLAGS);
 
function $(q) {
    return document.querySelector(q);
}

// Auto redirect shorts to watch page
var oldHref = document.location.href;
if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
}
window.onload = function() {
    var bodyList = document.querySelector("body")
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (oldHref != document.location.href) {
                oldHref = document.location.href;
                console.log('location changed!');
                if (window.location.href.indexOf('youtube.com/shorts') > -1) {
                    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
                }
            }
        });
    });
    var config = {
        childList: true,
        subtree: true
    };
    observer.observe(bodyList, config);
};
 
// Fully replace shorts links with regular videos
/**
 * Shorts URL redirect.
 *
 * This is called on initial visit only. Successive navigations
 * are managed by modifying the YouTube Desktop application.
 */
(function(){
 
/** @type {string} */
var path = window.location.pathname;
 
if (0 == path.search("/shorts"))
{
    // Extract the video ID from the shorts link and redirect.
 
    /** @type {string} */
    var id = path.replace(/\/|shorts|\?.*/g, "");
 
    window.location.replace("https://www.youtube.com/watch?v=" + id);
}
 
})();
 
/**
 * YouTube Desktop Shorts remover.
 *
 * If the initial URL was not a shorts link, traditional redirection
 * will not work. This instead modifies video elements to replace them with
 * regular links.
 */
(function(){
 
/**
 * @param {string} selector (CSS-style) of the element
 * @return {Promise<Element>}
...

Reviews

No reviews yet.