Really sympathies

Добавляет отображение симпатий без розыгрышей через /, + ворк в профиле + отслеживание новых сообщений в темах

Від 31.10.2024. Дивіться остання версія.

// ==UserScript==
// @name         Really sympathies
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  Добавляет отображение симпатий без розыгрышей через /, + ворк в профиле + отслеживание новых сообщений в темах
// @author       Lotti, Punsh, eretly
// @match        https://lolz.live/*
// @match        https://lolz.guru/*
// @match        https://zelenka.guru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=lolz.live
// @grant        none
// @license MIT
// ==/UserScript==


(function() {
    const html = document.createElement("div");

    function updateUserSympathies(user) {
        const link = user.querySelector("span a.username");
        if (!link) return;

        fetch(`https://lolz.live/${link.getAttribute("href")}`).then(resul => resul.text().then(htmlText => {
            let noReaction = 0;
            html.innerHTML = htmlText;

            const reaction = Number(html.querySelector(".count").textContent.replace(" ", ""));

            fetch(`https://lolz.live/${link.getAttribute("href")}likes?type=gotten&content_type=post&stats=1`).then(resul => {
                resul.text().then(htmlText => {
                    html.innerHTML = htmlText;

                    const allReaction = html.querySelectorAll(".node");
                    allReaction.forEach(el => {
                        if (el.querySelector(".muted").textContent.toLowerCase().includes("розыгрыш")) {
                            noReaction += Number(el.querySelector(".counter").textContent.replace(" ", ""));
                        }
                    });

                    const adjustedCount = reaction - noReaction;
                    const element = `<i class="userCounterIcon fas fa-heart"></i>${reaction} / ${adjustedCount}`;
                    const counterContainer = user.querySelector(".userCounters span") || document.createElement("span");

                    counterContainer.classList.add("userCounter", "item", "muted");
                    counterContainer.innerHTML = element;
                    if (!user.querySelector(".userCounters span")) {
                        user.appendChild(counterContainer);
                    }
                });
            });
        }));
    }

    const observer = new MutationObserver(mutations => {
        const windowDiv = `<div style="position: absolute; left: -999999px; top: -999999px; width: 100px; height: 100px; overflow: scroll;"><div style="height: 200px; width: 100%;"></div></div>`;
        const reactionElements = document.querySelectorAll(".memberCardInner");

        mutations.forEach(mutation => {
            if (mutation.addedNodes.length > 0 && mutation.addedNodes[0].outerHTML === windowDiv) {
                const latestReaction = reactionElements[reactionElements.length - 1];
                const link = latestReaction.querySelector(".username.NoOverlay").getAttribute("href");
                let noReaction = 0;

                fetch(`https://lolz.live/${link}likes?type=gotten&content_type=post&stats=1`).then(resul => {
                    resul.text().then(htmlText => {
                        html.innerHTML = htmlText;

                        const allReaction = html.querySelectorAll(".node");
                        allReaction.forEach(el => {
                            if (el.querySelector(".muted").textContent.toLowerCase().includes("розыгрыш")) {
                                noReaction += Number(el.querySelector(".counter").textContent.replace(" ", ""));
                            }
                        });

                        const totalReactions = Number(latestReaction.querySelector("a.counter").textContent.replace(" ", ""));
                        const adjustedCount = totalReactions - noReaction;
                        const element = `<i class="counterIcon likeCounterIcon"></i>${totalReactions} / ${adjustedCount}`;
                        latestReaction.querySelector("a.counter").innerHTML = element;
                    });
                });
            }

            mutation.addedNodes.forEach(node => {
                if (node.classList && node.classList.contains("message")) {
                    const user = node.querySelector(".userText");
                    if (user) updateUserSympathies(user);
                }
            });
        });
    });

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

    document.querySelectorAll(".userText").forEach(updateUserSympathies);

    function updateProfileSympathies() {
        const profileCounter = document.querySelector('a.page_counter[href$="likes"] .count');
        if (profileCounter) {
            const profileSympathies = Number(profileCounter.textContent.replace(" ", ""));
            let noReaction = 0;

            fetch(window.location.href + 'likes?type=gotten&content_type=post&stats=1').then(resul => {
                resul.text().then(htmlText => {
                    html.innerHTML = htmlText;

                    const allReaction = html.querySelectorAll(".node");
                    allReaction.forEach(el => {
                        if (el.querySelector(".muted").textContent.toLowerCase().includes("розыгрыш")) {
                            noReaction += Number(el.querySelector(".counter").textContent.replace(" ", ""));
                        }
                    });

                    const adjustedCount = profileSympathies - noReaction;
                    profileCounter.innerHTML = `<i class="counterIcon likeCounterIcon"></i>${profileSympathies} / ${adjustedCount}`;
                });
            });
        }
    }

    updateProfileSympathies();

})();