Reparador universal del botón de ajustes de YouTube ("Null")

Repara el nombre del botón de ajustes si cambia a "null", usando el valor original detectado automáticamente (soporta todos los idiomas)

目前為 2025-06-10 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Reparador universal del botón de ajustes de YouTube ("Null")
// @name:en     Universal repairer of the YouTube Settings button ("Null")
// @namespace    https://youtube.com/
// @version      1.0
// @description  Repara el nombre del botón de ajustes si cambia a "null", usando el valor original detectado automáticamente (soporta todos los idiomas)
// @description:en  Repair the name of the Settings button if you change to "NULL", using the original value automatically detected (it supports all languages)
// @author       Eterve Nallo
// @license      MIT
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let nombreOriginal = null;

    function detectarYGuardarNombre(boton) {
        const aria = boton.getAttribute("aria-label");
        const titulo = boton.getAttribute("title");

        if (aria && aria !== "null") {
            nombreOriginal = aria;
        } else if (titulo && titulo !== "null") {
            nombreOriginal = titulo;
        }
    }

    function repararSiEsNecesario(boton) {
        const aria = boton.getAttribute("aria-label");
        const titulo = boton.getAttribute("title");

        if ((aria === "null" || titulo === "null") && nombreOriginal) {
            if (aria === "null") {
                boton.setAttribute("aria-label", nombreOriginal);
            }
            if (titulo === "null") {
                boton.setAttribute("title", nombreOriginal);
            }
            console.log("🛠️ Se reparó el botón de ajustes exitosamente con el nombre original: " + nombreOriginal);
        }
    }

    function iniciarMonitoreo() {
        const boton = document.querySelector(".ytp-settings-button");

        if (!boton) {
            setTimeout(iniciarMonitoreo, 500); // Reintenta si aún no está disponible
            return;
        }

        detectarYGuardarNombre(boton); // Guarda nombre válido antes del bug

        const observer = new MutationObserver(() => {
            detectarYGuardarNombre(boton); // Por si se vuelve a cargar con valor válido
            repararSiEsNecesario(boton);
        });

        observer.observe(boton, {
            attributes: true,
            attributeFilter: ["aria-label", "title"]
        });
    }

    // Detecta cambios globales por navegación entre videos
    const bodyObserver = new MutationObserver(() => {
        iniciarMonitoreo();
    });

    bodyObserver.observe(document.body, { childList: true, subtree: true });

    iniciarMonitoreo(); // Arranca al principio
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址