astars.club Auto Helper

хелпер который помогает определить популярность карты на сайте astars.club

当前为 2025-01-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         astars.club Auto Helper
// @namespace    astars.club
// @version      1.3
// @description  хелпер который помогает определить популярность карты на сайте astars.club
// @author       astars lover
// @match        https://astars.club/* 
// @license MIT
// @grant        none


// ==/UserScript==

async function updateCardInfo(cardId, element) {
    if (!cardId || !element) return;

    try {
        // Получение количества "Желающих"
        const needResponse = await fetch(`https://astars.club/cards/${cardId}/users/need/`);
        let needCount = 0;
        if (needResponse.ok) {
            const needHtml = await needResponse.text();
            const needDoc = new DOMParser().parseFromString(needHtml, 'text/html');
            needCount = needDoc.querySelectorAll('.profile__friends-item').length;

            const pagination = needDoc.querySelector('.pagination__pages');
            if (pagination) {
                const lastPageLink = pagination.querySelector('a:last-of-type');
                const totalPages = lastPageLink ? parseInt(lastPageLink.innerText, 10) : 1;
                if (totalPages > 1) {
                    needCount += (totalPages - 1) * 50;
                }
            }
        }

        await sleep(500); // Задержка 0.5 сек
        // Получение количества "Готовых поменять"
        const tradeResponse = await fetch(`https://astars.club/cards/${cardId}/users/trade/`);
        let tradeCount = 0;
        if (tradeResponse.ok) {
            const tradeHtml = await tradeResponse.text();
            const tradeDoc = new DOMParser().parseFromString(tradeHtml, 'text/html');
            tradeCount = tradeDoc.querySelectorAll('.profile__friends-item').length;

            const pagination = tradeDoc.querySelector('.pagination__pages');
            if (pagination) {
                const lastPageLink = pagination.querySelector('a:last-of-type');
                const totalPages = lastPageLink ? parseInt(lastPageLink.innerText, 10) : 1;
                if (totalPages > 1 && tradeCount >= 50) { // костыль глюка отображения пейджинации
                    tradeCount += (totalPages - 1) * 50;
                }
            }
        }

        await sleep(500); // Задержка 0.5 сек
        // Получение популярности и ранга
        const popularityResponse = await fetch(`https://astars.club/cards/${cardId}/users/`);
        let popularityCount = 0;
        let rankText = '';
        if (popularityResponse.ok) {
            const popularityHtml = await popularityResponse.text();
            const popularityDoc = new DOMParser().parseFromString(popularityHtml, 'text/html');
            popularityCount = popularityDoc.querySelectorAll('.card-show__owner').length;

            const pagination = popularityDoc.querySelector('.pagination__pages');
            if (pagination) {
                const lastPageLink = pagination.querySelector('a:last-of-type');
                const totalPages = lastPageLink ? parseInt(lastPageLink.innerText, 10) : 1;
                if (totalPages > 1) {
                    popularityCount += (totalPages - 1) * 35;
                }
            }

            const rankElement = popularityDoc.querySelector('.anime-cards__rank');
            if (rankElement) {
                rankText = rankElement.textContent.trim();
            }
        }

        // Очистка старой информации
        element.querySelector('.link-icon')?.remove();

        // Добавление новой информации
        const icon = document.createElement('div');
        icon.className = 'link-icon';
        icon.style.position = 'absolute';
        icon.style.top = '5px';
        icon.style.right = '5px';
        icon.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
        icon.style.color = 'white';
        icon.style.padding = '5px';
        icon.style.borderRadius = '5px';
        icon.style.fontSize = '12px';
        icon.innerHTML = `Ранг: ${rankText}<br>Уже имеют: ${popularityCount}<br>Хотят получить: ${needCount}<br>Готовы поменять: ${tradeCount}`;

        element.style.position = 'relative';
        element.appendChild(icon);
    } catch (error) {
        console.error(`Ошибка обработки карты ${cardId}:`, error);
    }
}

function processCards() {
    const cards = document.querySelectorAll('.lootbox__card, .anime-cards__item');
    for (const card of cards) {
    sleep(1000); // Задержка 1 секунда
        const cardId = card.getAttribute('data-id');
        if (cardId) {
            updateCardInfo(cardId, card);
        }
    }
}

function addUpdateButton() {
    if (!document.querySelector('#fetchLinksButton')) {
        const button = document.createElement('button');
        button.id = 'fetchLinksButton';
        button.innerText = 'Обновить инфу';
        button.style.position = 'fixed';
        button.style.top = '10px';
        button.style.right = '10px';
        button.style.zIndex = '1000';
        button.style.backgroundColor = '#007bff';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.padding = '10px 15px';
        button.style.cursor = 'pointer';
        button.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
        button.addEventListener('click', processCards);
        document.body.appendChild(button);
    }
}

function clearIcons() {
    $('.card-notification')?.first()?.click();
    $('.ui-dialog-titlebar-close')?.first()?.click();
}

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

(function() {
    'use strict';

    // Проверяем наличие дива каждые 2 сек
    setInterval(clearIcons, 2000);
    addUpdateButton();

})();