astars.club Auto Helper

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

目前為 2025-01-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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


// ==/UserScript==

// Функция для проверки наличия дива и добавления кнопки
function checkAndAddButton() {
    const lootboxTitleDiv = document.querySelector('.lootbox__title');

    if (lootboxTitleDiv && !document.querySelector('#fetchLinksButton')) {
        const button = document.createElement('button');
        button.id = 'fetchLinksButton';
        button.innerText = 'Обновить количество ссылок';
        button.style.marginTop = '10px';
        button.addEventListener('click', fetchAndAddIcons);
        lootboxTitleDiv.appendChild(button);
    }
}

// Функция для получения данных и добавления иконок
async function fetchAndAddIcons() {
    const cards = document.querySelectorAll('.lootbox__card');

    for (const card of cards) {
        const cardId = card.getAttribute('data-id');
        if (!cardId) continue;

        //card.addEventListener('click', clearIcons());

        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 = needCount + ((totalPages - 1) * 50);
                    }
                }
            }

            // Получение количества "Готовых поменять"
            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 = tradeCount + ((totalPages - 1) * 50);
                    }
                }
            }

            // Получение популярности и ранга
            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 = popularityCount + ((totalPages - 1) * 35);
                    }
                }

                // Получение ранга
                const rankElement = popularityDoc.querySelector('.anime-cards__rank');
                if (rankElement) {
                    rankText = rankElement.textContent.trim();
                }
            }

            // Удаляем предыдущую иконку, если она есть
            let existingIcon = card.querySelector('.link-icon');
            if (existingIcon) {
                existingIcon.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}`;

            card.style.position = 'relative'; // Для позиционирования иконки
            card.appendChild(icon);
        } catch (error) {
            console.error(`Ошибка обработки карточки ${cardId}:`, error);
        }
    }
}

function clearIcons() {
    const icons = document.querySelectorAll('.link-icon');
    icons.forEach(icon => icon.remove());
}

(function() {
    'use strict';

    // Проверяем наличие дива каждые 5 секунд
    setInterval(checkAndAddButton, 5000);
})();