astars.club Auto Helper

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

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

  1. // ==UserScript==
  2. // @name astars.club Auto Helper
  3. // @namespace astars.club animestars.org
  4. // @version 1.4
  5. // @description хелпер который помогает определить популярность карты на сайте astars.club
  6. // @author astars lover
  7. // @match https://astars.club/* https://animestars.org/*
  8. // @license MIT
  9. // @grant none
  10.  
  11.  
  12. // ==/UserScript==
  13.  
  14. async function updateCardInfo(cardId, element) {
  15. if (!cardId || !element) return;
  16.  
  17. try {
  18. // Получение количества "Желающих"
  19. const needResponse = await fetch(`https://astars.club/cards/${cardId}/users/need/`);
  20. let needCount = 0;
  21. if (needResponse.ok) {
  22. const needHtml = await needResponse.text();
  23. const needDoc = new DOMParser().parseFromString(needHtml, 'text/html');
  24. needCount = needDoc.querySelectorAll('.profile__friends-item').length;
  25.  
  26. const pagination = needDoc.querySelector('.pagination__pages');
  27. if (pagination) {
  28. const lastPageLink = pagination.querySelector('a:last-of-type');
  29. const totalPages = lastPageLink ? parseInt(lastPageLink.innerText, 10) : 1;
  30. if (totalPages > 1) {
  31. needCount += (totalPages - 1) * 50;
  32. }
  33. }
  34. }
  35.  
  36. sleepSync(500); // Задержка 0.5 сек
  37. // Получение количества "Готовых поменять"
  38. const tradeResponse = await fetch(`https://astars.club/cards/${cardId}/users/trade/`);
  39. let tradeCount = 0;
  40. if (tradeResponse.ok) {
  41. const tradeHtml = await tradeResponse.text();
  42. const tradeDoc = new DOMParser().parseFromString(tradeHtml, 'text/html');
  43. tradeCount = tradeDoc.querySelectorAll('.profile__friends-item').length;
  44.  
  45. const pagination = tradeDoc.querySelector('.pagination__pages');
  46. if (pagination) {
  47. const lastPageLink = pagination.querySelector('a:last-of-type');
  48. const totalPages = lastPageLink ? parseInt(lastPageLink.innerText, 10) : 1;
  49. if (totalPages > 1 && tradeCount >= 50) { // костыль глюка отображения пейджинации
  50. tradeCount += (totalPages - 1) * 50;
  51. }
  52. }
  53. }
  54.  
  55. sleepSync(500); // Задержка 0.5 сек
  56. // Получение популярности и ранга
  57. const popularityResponse = await fetch(`https://astars.club/cards/${cardId}/users/`);
  58. let popularityCount = 0;
  59. let rankText = '';
  60. if (popularityResponse.ok) {
  61. const popularityHtml = await popularityResponse.text();
  62. const popularityDoc = new DOMParser().parseFromString(popularityHtml, 'text/html');
  63. popularityCount = popularityDoc.querySelectorAll('.card-show__owner').length;
  64.  
  65. const pagination = popularityDoc.querySelector('.pagination__pages');
  66. if (pagination) {
  67. const lastPageLink = pagination.querySelector('a:last-of-type');
  68. const totalPages = lastPageLink ? parseInt(lastPageLink.innerText, 10) : 1;
  69. if (totalPages > 1) {
  70. popularityCount += (totalPages - 1) * 35;
  71. }
  72. }
  73.  
  74. const rankElement = popularityDoc.querySelector('.anime-cards__rank');
  75. if (rankElement) {
  76. rankText = rankElement.textContent.trim();
  77. }
  78. }
  79.  
  80. // Очистка старой информации
  81. element.querySelector('.link-icon')?.remove();
  82.  
  83. // Добавление новой информации
  84. const icon = document.createElement('div');
  85. icon.className = 'link-icon';
  86. icon.style.position = 'absolute';
  87. icon.style.top = '5px';
  88. icon.style.right = '5px';
  89. icon.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  90. icon.style.color = 'white';
  91. icon.style.padding = '5px';
  92. icon.style.borderRadius = '5px';
  93. icon.style.fontSize = '12px';
  94. icon.innerHTML = `Ранг: ${rankText}<br>Уже имеют: ${popularityCount}<br>Хотят получить: ${needCount}<br>Готовы поменять: ${tradeCount}`;
  95.  
  96. element.style.position = 'relative';
  97. element.appendChild(icon);
  98. } catch (error) {
  99. console.error(`Ошибка обработки карты ${cardId}:`, error);
  100. }
  101. }
  102.  
  103. function processCards() {
  104. const cards = document.querySelectorAll('.lootbox__card, .anime-cards__item');
  105. for (const card of cards) {
  106. sleepSync(1000); // Задержка 1 секунда
  107. const cardId = card.getAttribute('data-id');
  108. if (cardId) {
  109. updateCardInfo(cardId, card);
  110. }
  111. }
  112. }
  113.  
  114. function addUpdateButton() {
  115. if (!document.querySelector('#fetchLinksButton')) {
  116. const button = document.createElement('button');
  117. button.id = 'fetchLinksButton';
  118. button.innerText = 'Обновить инфу';
  119. button.style.position = 'fixed';
  120. button.style.top = '10px';
  121. button.style.right = '10px';
  122. button.style.zIndex = '1000';
  123. button.style.backgroundColor = '#007bff';
  124. button.style.color = '#fff';
  125. button.style.border = 'none';
  126. button.style.borderRadius = '5px';
  127. button.style.padding = '10px 15px';
  128. button.style.cursor = 'pointer';
  129. button.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  130. button.addEventListener('click', processCards);
  131. document.body.appendChild(button);
  132. }
  133. }
  134.  
  135. function clearIcons() {
  136. $('.card-notification')?.first()?.click();
  137. $('.ui-dialog-titlebar-close')?.first()?.click();
  138. }
  139.  
  140. function sleepSync(ms) {
  141. const end = Date.now() + ms;
  142. while (Date.now() < end);
  143. }
  144.  
  145. (function() {
  146. 'use strict';
  147.  
  148. // Проверяем наличие дива каждые 2 сек
  149. setInterval(clearIcons, 2000);
  150. addUpdateButton();
  151.  
  152. })();