This commit is contained in:
Alexander Popov 2023-01-04 14:35:18 +03:00
parent 5c3ea3162a
commit 53425032c8

60
code.js
View File

@ -1,19 +1,26 @@
let badges = []; /**
* Скрипт для парсинга значков Steam
/* * @version 0.1.0
* Badge Sctruct: * @license Unlicense
* id: int * @author Alexander Popov <iiiypuk@fastmail.fm>
* uri: str
* name: str
* dropLeft: int
*/ */
let collection = document.getElementsByClassName('badge_row'); /**
// console.log(collection); * Получает данные из элемента `div.badge_row`
// console.log(collection.length); * @param {DOM} value - div.badge_row.
* @returns {Object}
*/
function getData(value) {
/*
* Badge Sctruct:
* id: int
* uri: str
* name: str
* dropLeft: int
*/
for (const [key, value] of Object.entries(collection)) {
// check left cards // check left cards
// для металлических карточек нет параметра 'карточек выпадет'
let cardsDropLeft = 0; let cardsDropLeft = 0;
if (value.getElementsByClassName('progress_info_bold')[0]) { if (value.getElementsByClassName('progress_info_bold')[0]) {
let cardsDropLeft = value.getElementsByClassName('progress_info_bold')[0].match(/\d/g); let cardsDropLeft = value.getElementsByClassName('progress_info_bold')[0].match(/\d/g);
@ -26,10 +33,29 @@ for (const [key, value] of Object.entries(collection)) {
dropLeft: cardsDropLeft, dropLeft: cardsDropLeft,
}; };
badges.push(badgeItem); return badgeItem;
} }
// to base64 /**
// let encoded = btoa(JSON.stringify(badges)); * Преобразовывает массив данных в JSON и возвращает к консоль
let encoded = JSON.stringify(badges); * @param {Array} badgesArray - массив данных о значках.
console.log(encoded); */
function exportJson(badgesArray) {
console.log(JSON.stringify(badgesArray));
}
/**
* Функция main()
*/
function getBadges() {
let badges = [];
const collection = document.getElementsByClassName('badge_row');
for (const [key, value] of Object.entries(collection)) {
badges.push(getData(value));
}
exportJson(badges);
}
getBadges();