From 53425032c8335d300e1eb8c04fedbe6d489503b3 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 4 Jan 2023 14:35:18 +0300 Subject: [PATCH] jsDoc --- code.js | 60 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/code.js b/code.js index 9495fcb..ed4e87f 100644 --- a/code.js +++ b/code.js @@ -1,19 +1,26 @@ -let badges = []; - -/* - * Badge Sctruct: - * id: int - * uri: str - * name: str - * dropLeft: int +/** + * Скрипт для парсинга значков Steam + * @version 0.1.0 + * @license Unlicense + * @author Alexander Popov */ -let collection = document.getElementsByClassName('badge_row'); -// console.log(collection); -// console.log(collection.length); +/** + * Получает данные из элемента `div.badge_row` + * @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 + // для металлических карточек нет параметра 'карточек выпадет' let cardsDropLeft = 0; if (value.getElementsByClassName('progress_info_bold')[0]) { 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, }; - badges.push(badgeItem); + return badgeItem; } -// to base64 -// let encoded = btoa(JSON.stringify(badges)); -let encoded = JSON.stringify(badges); -console.log(encoded); +/** + * Преобразовывает массив данных в JSON и возвращает к консоль + * @param {Array} badgesArray - массив данных о значках. + */ +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();