Greasy Fork is available in English.

Return YouTube Favorites

Returns Favorites to its rightful place on the left menu

// ==UserScript==
// @name         Return YouTube Favorites
// @name:ru      Return YouTube Favorites
// @namespace    https://t.me/johannmosin
// @version      0.3
// @description  Returns Favorites to its rightful place on the left menu
// @description:ru  Возвращает Избранное на своё законное место в левом меню
// @author       Johann Mosin
// @match        *://www.youtube.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var link = '' // <------------------------------------------------- YOUR LINK TO FAVORITES PLAYLIST GOES HERE

    var oldTitle="Your videos" // <------------------------------------ CHANGE THOUSE IF YOUR LANGUAGE
    var newTitle="Favorites" // <-------------------------------------- ISN'T SUPPORTED BY THE LIST BELOW

    var langObj = {
        'en': ["Your videos", "Favorites"],
        'en-GB': ["Your videos", "Favourites"],
        'ru-RU': ["Ваши видео", "Избранное"],
        'de-DE': ["Meine Videos", "Favoriten"],
        'es-ES': ["Mis videos","Favoritos"],
        'es-419': ["Tus videos","Favoritos"],
        'es-US': ["Tus videos","Favoritos"],
        'fr-CA': ["Vos vidéos","Favoris"],
        'fr-FR': ["Vos vidéos", "Favoris"]
    }

    var langMap = new Map(Object.entries(langObj))

    function defineLanguage() {
        var htmlLang = document.querySelector('html').lang;
        var langTitles = langMap.get(htmlLang);
        if (langTitles) {
            oldTitle = langTitles[0];
            newTitle = langTitles[1];
        }
    }

    function changeLinkAndText() {
        var element = document.querySelector('a[title="'+oldTitle+'"]');

        if (element) {
            element.href = link;

            var textElement = element.querySelector('.title.style-scope.ytd-guide-entry-renderer');
            if (textElement) {
                textElement.textContent = newTitle;
            }
            element.addEventListener('click', function(event) {
                event.preventDefault();
                event.stopPropagation();
                window.location.href = link;
            }, true);
        }
    }

    window.addEventListener('load', function() {
        defineLanguage();
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    mutation.addedNodes.forEach(function(node) {
                        if (node.nodeType === Node.ELEMENT_NODE && node.querySelector('a[title="'+oldTitle+'"]')) {
                            changeLinkAndText();
                        }
                    });
                }
            });
        });

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