kseuoeu / Chat and repository for Strada Fix

// ==UserScript==
// @name         Chat and repository for Strada Fix
// @namespace    http://tampermonkey.net/
// @version      2025-02-26
// @description  try to take over the world!
// @author       Liteqt
// @match        https://strada.one/progress
// @icon         https://www.google.com/s2/favicons?sz=64&domain=strada.one
// @grant        none
// @copyright 2025, kseuoeu (https://openuserjs.org/users/kseuoeu)
// @updateURL https://openuserjs.org/meta/kseuoeu/Chat_and_repository_for_Strada_Fix.meta.js
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    let isCardModified = false;
    let timer;
    const delay = 250;

    function editElement(element) {
        if (isCardModified) {
            console.log('Карточка ссылок уже была изменена');
            return;
        }
        let parentElement = element;
        while (parentElement && !parentElement.classList.contains('MuiGrid-root')) {
            parentElement = parentElement.parentElement;
        }

        if (parentElement && parentElement.classList.contains('MuiGrid-root')) {
            console.log('Найден родительский элемент:', parentElement);
            parentElement.innerHTML = `
                    <div class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1 MuiCard-root css-1v2oarz" style="height: 100%;">
                        <div class="MuiCardHeader-root css-1g4hjz4">
                            <div class="MuiCardHeader-content css-11qjisw">
                                <span class="MuiTypography-root MuiTypography-h5 MuiCardHeader-title css-1g3izzu">
                                    <div class="MuiBox-root css-70qvj9">
                                        <h5 class="MuiTypography-root MuiTypography-h5 css-1jp3ios">Полезные ссылки</h5>
                                        <svg class="MuiSvgIcon-root MuiSvgIcon-colorSecondary MuiSvgIcon-fontSizeMedium css-1tblpw8" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="InsertLinkIcon">
                                            <path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path>
                                        </svg>
                                    </div>
                                </span>
                            </div>
                        </div>
                        <div class="MuiCardContent-root css-zugfr9">
                            <div class="MuiBox-root css-j7qwjs">
                                <div class="MuiBox-root css-0">
                                    <p class="MuiTypography-root MuiTypography-body1 css-17vjrw7">Репозиторий</p>
                                    <div class="MuiBox-root css-19idom"style="margin-bottom: 8px;">
                                        <a class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-1sirjv0" href="https://github.com/StradaOne/FR9" target="_blank">GitHub</a>
                                    </div>
                                    <div class="MuiBox-root css-19idom"style="margin-bottom: 8px;">
                                        <a class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-1sirjv0" href="https://github.com/StradaOne/FR9/issues?q=is%3Aopen+is%3Apr+author%3A%40me" target="_blank">Мои пуллы</a>
                                    </div>
                                    <div class="MuiBox-root css-19idom"style="margin-bottom: 8px;">
                                        <a class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways css-1sirjv0" href="https://github.com/StradaOne/FR9/issues?q=is%3Aopen+is%3Apr+-author%3A%40me" target="_blank">Последние пуллы (исключая мои)</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                `;
            isCardModified = true;
        } else {
            console.log('Родительский элемент с классом "MuiGrid-root" не найден!');
        }
    }

    function handleMutation() {
        clearTimeout(timer);

        const element = Array.from(document.querySelectorAll('h5')).find(el => el.textContent.trim() === 'Полезные ссылки');
        if (!element) {
            isCardModified = false;
            console.log('Элемент "Полезные ссылки" пропал, флаг сброшен.');
        }

        timer = setTimeout(() => {
            if (element) {
                console.log('Элемент "Полезные ссылки" найден!');
                editElement(element);
            }
        }, delay);
    }

    const containers = document.querySelectorAll('.MuiContainer-root');
    const secondContainer = containers[1];

    const observer = new MutationObserver((mutationsList, observer) => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList' || mutation.type === 'subtree') {
                handleMutation();
            }
        }
    });

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

})();