// Замена изображений
function replaceLogo() {
    const logos = document.querySelectorAll('img[alt*="Яндекс" i], img[alt*="Yandex" i], img[src*="yandex" i]');
    logos.forEach(img => {
        if (img.alt && (img.alt.includes('Логотип Яндекс Учебника') || img.alt.includes('Яндекс'))) {
            img.src = chrome.runtime.getURL('logos/logo1.png');
        }
    });
}

function replaceSpecialImage() {
    const specialImg = document.querySelector('img.promo-lesson-banner__image[alt="special"]');
    if (specialImg) specialImg.src = chrome.runtime.getURL('logos/IshakImg.png');
}

function replaceHeaderLogo() {
    const headerLink = document.querySelector('a.header__logo');
    if (!headerLink) return;
    const svg = headerLink.querySelector('svg');
    if (svg) {
        const img = document.createElement('img');
        img.src = chrome.runtime.getURL('logos/Logo2.png');
        img.width = 40; img.height = 40;
        img.alt = 'Логотип Ишак';
        img.style.display = 'block';
        svg.parentNode.replaceChild(img, svg);
    }
}

function replaceFavicon() {
    const favicons = document.querySelectorAll('link[rel*="icon"]');
    const faviconUrl = chrome.runtime.getURL('logos/logo3.png');
    favicons.forEach(link => link.href = faviconUrl);
    if (favicons.length === 0) {
        const newFavicon = document.createElement('link');
        newFavicon.rel = 'icon';
        newFavicon.href = faviconUrl;
        document.head.appendChild(newFavicon);
    }
}

function replaceStartScreenLogos() {
    const container = document.querySelector('._2bBacs5wfNmCaTw93iyxVU--LogoFull._3ybd9D7Vx6ty15nAwy-vl1--LogoFull_light.start-screen__logo');
    if (!container) return;
    const svgs = container.querySelectorAll('svg');
    const imageUrls = [
        chrome.runtime.getURL('logos/loginlogo1.png'),
        chrome.runtime.getURL('logos/loginlogo2.png'),
        chrome.runtime.getURL('logos/loginlogo3.png')
    ];
    svgs.forEach((svg, index) => {
        if (index >= imageUrls.length) return;
        const img = document.createElement('img');
        img.src = imageUrls[index];
        img.alt = 'Логотип Ишак';
        const width = svg.getAttribute('width');
        const height = svg.getAttribute('height');
        if (width && height) {
            img.width = parseInt(width, 10);
            img.height = parseInt(height, 10);
        } else {
            img.width = 40; img.height = 40;
        }
        img.style.display = 'block';
        svg.parentNode.replaceChild(img, svg);
    });
}