Last active
March 29, 2025 17:05
-
-
Save lesha-co/45c1d5c82fe02edd6f8e4fd3cf81739d to your computer and use it in GitHub Desktop.
Youtube's Auto-translate language filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Youtube's Auto-translate language filter | |
| // @version 2025-03-29 | |
| // @description try to take over the world! | |
| // @author lesha-co | |
| // @match https://www.youtube.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
| // @grant none | |
| // ==/UserScript== | |
| const LANGUAGES = ["English", "Russian"]; | |
| const ITEM_HEIGHT = 40; | |
| (function () { | |
| "use strict"; | |
| const observer = new MutationObserver(() => { | |
| const settings = document.querySelector(".ytp-popup.ytp-settings-menu"); | |
| if (!settings) return; | |
| const panel = settings.querySelector(".ytp-panel"); | |
| if (!panel) return; | |
| const menu = panel.querySelector(".ytp-panel-menu"); | |
| const header = panel.querySelector(".ytp-panel-header"); | |
| if (!menu) return; | |
| if (!header) return; | |
| const panelTitle = panel.querySelector(".ytp-panel-title"); | |
| if (!panelTitle) return; | |
| console.log("in menu", panelTitle.textContent); | |
| if (panelTitle.textContent !== "Auto-translate") return; | |
| const menuItems = panel.querySelectorAll(".ytp-menuitem"); | |
| if (!menuItems) return; | |
| // Remove all menu items except English and Russian | |
| const itemsToSetHeightTo = []; | |
| for (const item of menuItems) { | |
| const language = item.querySelector(".ytp-menuitem-label")?.textContent; | |
| if (!language) continue; | |
| if (LANGUAGES.includes(language)) { | |
| itemsToSetHeightTo.push(item); | |
| continue; | |
| } | |
| item.parentElement?.removeChild(item); | |
| } | |
| for (const item of itemsToSetHeightTo) { | |
| item.style.height = `${ITEM_HEIGHT}px`; | |
| } | |
| menu.style.height = ""; | |
| const totalHeight = header.offsetHeight + menu.offsetHeight; | |
| settings.style.height = `${totalHeight}px`; | |
| panel.style.height = `${totalHeight}px`; | |
| }); | |
| observer.observe(document.querySelector(".ytp-popup.ytp-settings-menu"), { | |
| childList: true, | |
| subtree: true, | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment