// ==UserScript== // @name YouTube Web Tweaks // @version 4.0.0 // @description This script optimizes YouTube's performance by modified configs, shorts redirect and much more! // @author Magma_Craft // @license MIT // @match *://www.youtube.com/* // @namespace https://greasyfork.org/en/users/933798 // @icon https://www.youtube.com/favicon.ico // @unwrap // @run-at document-end // @unwrap // @grant none // @downloadURL none // ==/UserScript== // Enable strict mode to catch common coding mistakes "use strict"; // Define the flags to assign to the EXPERIMENT_FLAGS object const flagsToAssign = { 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, kevlar_refresh_on_theme_change: false, kevlar_watch_cinematics: 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 }); // Other adjustments to be tweaked (Re-adding Explore tab, redirecting shorts to watch, wtc...) function waitForElm(selector) { return new Promise(resolve => { if (document.querySelector(selector)) { return resolve(document.querySelector(selector)); } const observer = new MutationObserver(mutations => { if (document.querySelector(selector)) { resolve(document.querySelector(selector)); observer.disconnect(); } }); observer.observe(document.body, { childList: true, subtree: true }); }); } function restoreTrending() { var trendingData = { "navigationEndpoint": { "clickTrackingParams": "CBwQtSwYASITCNqYh-qO_fACFcoRrQYdP44D9Q==", "commandMetadata": { "webCommandMetadata": { "url": "/feed/explore", "webPageType": "WEB_PAGE_TYPE_BROWSE", "rootVe": 6827, "apiUrl": "/youtubei/v1/browse" } }, "browseEndpoint": { "browseId": "FEtrending" } }, "icon": { "iconType": "EXPLORE" }, "trackingParams": "CBwQtSwYASITCNqYh-qO_fACFcoRrQYdP44D9Q==", "formattedTitle": { "simpleText": "Explore" }, "accessibility": { "accessibilityData": { "label": "Explore" } }, "isPrimary": true }; var guidetemplate = `
`; document.querySelector(`#items > ytd-guide-entry-renderer:nth-child(2)`).data = trendingData; var miniguidetemplate = `
`; document.querySelector(`#items > ytd-mini-guide-entry-renderer:nth-child(2)`).data = trendingData; } waitForElm("#items.ytd-guide-section-renderer").then((elm) => { restoreTrending(); }); waitForElm("#items.ytd-mini-guide-section-renderer").then((elm) => { restoreTrending(); }); var styles = document.createElement("style"); styles.innerHTML=` /* Remove Shorts, Trending, Podcasts and Shopping buttons to make the sidebar less almost prior to late 2022 */ #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer.style-scope[title="Shorts"], a.yt-simple-endpoint.style-scope.ytd-mini-guide-entry-renderer[title="Shorts"] { display: none !important; } #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer.style-scope[title="Trending"] { display: none !important; } #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer.style-scope[title="Podcasts"] { display: none !important; } ytd-guide-entry-renderer > a[href*="/channel/UCkYQyvc_i9hXEo4xic9Hh2g"] { display: none !important; } /* Remove filter categories on search results and playlists to make the UI less usable on low-entry machines */ ytd-item-section-renderer.style-scope.ytd-section-list-renderer[page-subtype="playlist"] > #header.ytd-item-section-renderer > ytd-feed-filter-chip-bar-renderer { display: none !important; } div#chip-bar.style-scope.ytd-search-header-renderer > yt-chip-cloud-renderer.style-scope.ytd-search-header-renderer > div#container.style-scope.yt-chip-cloud-renderer { display: none !important; }`; document.head.appendChild(styles); 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); }; Object.defineProperties(document, { /*'hidden': {value: false},*/ 'webkitHidden': {value: false}, 'visibilityState': {value: 'visible'}, 'webkitVisibilityState': {value: 'visible'} }); setInterval(function(){ document.dispatchEvent( new KeyboardEvent( 'keyup', { bubbles: true, cancelable: true, keyCode: 143, which: 143 } ) ); }, 60000);