animestars Auto Helper

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

< Feedback on animestars Auto Helper

Question/comment

§
Posted: 24/04/2025

Привет, там встала проблема с тем, что походу изменили пагинацию немного, теперь у всех карт всего лишь 27 владельцев(количество владельцев на одной странице).
Я написал кастомное решение и если тебе понравится, то в принципе можешь заюзать, там некоторые консоль логи для дебага были, их можешь снести.
async function loadCard(cardId) {
const cacheKey = 'cardId: ' + cardId;
let card = await getCard(cacheKey) ?? {};
if (Object.keys(card).length) {
return card;
}

const currentDomain = window.location.origin;
await sleep(DELAY);
let needCount = await getCount(cardId, 'need');
await sleep(DELAY);
let tradeCount = await getCount(cardId, 'trade');
await sleep(DELAY);

const popularityResponse = await fetch(`${currentDomain}/cards/${cardId}/users/`);
if (popularityResponse.status === 502) {
console.error("Ошибка 502: Остановка выполнения скриптов.");
throw new Error("502 Bad Gateway");
}

let likes = 0;
let dislikes = 0;
let popularityCount = 0;
let rankText = '';

if (popularityResponse.ok) {
const popularityHtml = await popularityResponse.text();
const popularityDoc = new DOMParser().parseFromString(popularityHtml, 'text/html');

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

await checkGiftCard(popularityDoc); // ищем небесный камень

const animeUrl = popularityDoc.querySelector('.card-show__placeholder')?.href;
if (animeUrl) {
try {
const response = await fetch(animeUrl);
if (response.ok) {
const htmlText = await response.text();
const doc = new DOMParser().parseFromString(htmlText, 'text/html');
likes = parseInt(doc.querySelector('[data-likes-id]')?.textContent?.trim(), 10) || 0;
dislikes = parseInt(doc.querySelector('[data-dislikes-id]')?.textContent?.trim(), 10) || 0;
await checkGiftCard(doc);
}
} catch (error) {
console.error('Ошибка при загрузке страницы:', error);
}
}

// Считаем владельцев на первой странице
popularityCount = popularityDoc.querySelectorAll('.card-show__owner').length;
console.log('Владельцев на первой странице:', popularityCount);

const pagination = popularityDoc.querySelector('.pagination__pages');
if (pagination) {
const lastPageAnchor = pagination.querySelector('a:last-of-type');
const lastPageText = lastPageAnchor?.innerText.trim();
const totalPages = parseInt(lastPageText, 10);

console.log('Пагинация:', lastPageText, 'Всего страниц:', totalPages);

if (!isNaN(totalPages) && totalPages > 1) {
// Пересчитываем популярность
popularityCount = (totalPages - 1) * 27;

const lastPageUrl = `${currentDomain}/cards/${cardId}/users/page/${totalPages}`;
const lastPageResp = await fetch(lastPageUrl);

if (lastPageResp.status === 502) {
console.error("Ошибка 502 на последней странице.");
throw new Error("502 Bad Gateway");
}

if (lastPageResp.ok) {
const lastPageHtml = await lastPageResp.text();
const lastPageDoc = new DOMParser().parseFromString(lastPageHtml, 'text/html');
await checkGiftCard(lastPageDoc);
const lastOwners = lastPageDoc.querySelectorAll('.card-show__owner').length;
console.log(`Владельцев на последней странице: ${lastOwners}`);
popularityCount += lastOwners;
}
}
}
}

card = {
likes: likes,
dislikes: dislikes,
rankText: rankText,
popularityCount: popularityCount,
needCount: needCount,
tradeCount: tradeCount
};

if (card.likes || card.dislikes) {
await cacheCard(cacheKey, card);
}

return card;
}

§
Posted: 24/04/2025
Edited: 24/04/2025

немного подправил ранг карт
async function loadCard(cardId) {
const cacheKey = 'cardId: ' + cardId;
let card = await getCard(cacheKey) ?? {};
if (Object.keys(card).length) {
return card;
}

const currentDomain = window.location.origin;
await sleep(DELAY);
let needCount = await getCount(cardId, 'need');
await sleep(DELAY);
let tradeCount = await getCount(cardId, 'trade');
await sleep(DELAY);

const popularityResponse = await fetch(`${currentDomain}/cards/${cardId}/users/`);
if (popularityResponse.status === 502) {
console.error("Ошибка 502: Остановка выполнения скриптов.");
throw new Error("502 Bad Gateway");
}

let likes = 0;
let dislikes = 0;
let popularityCount = 0;
let rankText = '';

if (popularityResponse.ok) {
const popularityHtml = await popularityResponse.text();
const popularityDoc = new DOMParser().parseFromString(popularityHtml, 'text/html');

const rankElement = popularityDoc.querySelector('.ncard__rank');
if (rankElement) {
rankText = rankElement.textContent.trim().replace(/^Редкость\s+/i, '');
rankText = rankText.charAt(0).toUpperCase() + rankText.slice(1);
}

await checkGiftCard(popularityDoc); // ищем небесный камень

const animeUrl = popularityDoc.querySelector('.card-show__placeholder')?.href;
if (animeUrl) {
try {
const response = await fetch(animeUrl);
if (response.ok) {
const htmlText = await response.text();
const doc = new DOMParser().parseFromString(htmlText, 'text/html');
likes = parseInt(doc.querySelector('[data-likes-id]')?.textContent?.trim(), 10) || 0;
dislikes = parseInt(doc.querySelector('[data-dislikes-id]')?.textContent?.trim(), 10) || 0;
await checkGiftCard(doc);
}
} catch (error) {
console.error('Ошибка при загрузке страницы:', error);
}
}

// Считаем владельцев на первой странице
popularityCount = popularityDoc.querySelectorAll('.card-show__owner').length;
console.log('Владельцев на первой странице:', popularityCount);

const pagination = popularityDoc.querySelector('.pagination__pages');
if (pagination) {
const lastPageAnchor = pagination.querySelector('a:last-of-type');
const lastPageText = lastPageAnchor?.innerText.trim();
const totalPages = parseInt(lastPageText, 10);

console.log('Пагинация:', lastPageText, 'Всего страниц:', totalPages);

if (!isNaN(totalPages) && totalPages > 1) {
// Пересчитываем популярность
popularityCount = (totalPages - 1) * 27;

const lastPageUrl = `${currentDomain}/cards/${cardId}/users/page/${totalPages}`;
const lastPageResp = await fetch(lastPageUrl);

if (lastPageResp.status === 502) {
console.error("Ошибка 502 на последней странице.");
throw new Error("502 Bad Gateway");
}

if (lastPageResp.ok) {
const lastPageHtml = await lastPageResp.text();
const lastPageDoc = new DOMParser().parseFromString(lastPageHtml, 'text/html');
await checkGiftCard(lastPageDoc);
const lastOwners = lastPageDoc.querySelectorAll('.card-show__owner').length;
console.log(`Владельцев на последней странице: ${lastOwners}`);
popularityCount += lastOwners;
}
}
}
}

card = {
likes: likes,
dislikes: dislikes,
rankText: rankText,
popularityCount: popularityCount,
needCount: needCount,
tradeCount: tradeCount
};

if (card.likes || card.dislikes) {
await cacheCard(cacheKey, card);
}

return card;
}

§
Posted: 24/04/2025

p.s Кеш почему-то не пишется, не могу проблему найти(

Post reply

Sign in to post a reply.

长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元