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

50
code.js
View File

@ -1,6 +1,17 @@
let badges = []; /**
* Скрипт для парсинга значков Steam
* @version 0.1.0
* @license Unlicense
* @author Alexander Popov <iiiypuk@fastmail.fm>
*/
/* /**
* Получает данные из элемента `div.badge_row`
* @param {DOM} value - div.badge_row.
* @returns {Object}
*/
function getData(value) {
/*
* Badge Sctruct: * Badge Sctruct:
* id: int * id: int
* uri: str * uri: str
@ -8,12 +19,8 @@ let badges = [];
* dropLeft: int * dropLeft: int
*/ */
let collection = document.getElementsByClassName('badge_row');
// console.log(collection);
// console.log(collection.length);
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();