fix input array index

This commit is contained in:
Alexander Popov 2023-01-04 23:24:03 +03:00
parent bc6e580c3d
commit a498743e45
1 changed files with 7 additions and 7 deletions

14
code.js
View File

@ -14,7 +14,7 @@ function getData(value) {
/*
* Badge Sctruct:
* id: int
* uri: str
* url: str
* name: str
* dropLeft: int
*/
@ -22,15 +22,15 @@ function getData(value) {
// check left cards
// для карточек, у которых нет параметра 'карточек выпадет'
let cardsDropLeft = 0;
if (value[1].getElementsByClassName('progress_info_bold').length > 0) {
cardsDropsNumber = value[1].getElementsByClassName('progress_info_bold')[0].innerText.match(/\d/g);
if (value.getElementsByClassName('progress_info_bold').length > 0) {
cardsDropsNumber = value.getElementsByClassName('progress_info_bold')[0].innerText.match(/\d/g);
if (cardsDropsNumber !== null) { cardsDropLeft = [0]; }
}
let badgeItem = {
id: parseInt(value[1].childNodes[1].href.split('/')[6]),
uri: value[1].childNodes[1].href,
name: value[1].getElementsByClassName('badge_title')[0].innerText.trim().replace(/[\r\n\t]/g, ''),
id: parseInt(value.childNodes[1].href.split('/')[6]),
url: value.childNodes[1].href,
name: value.getElementsByClassName('badge_title')[0].innerText.trim().replace(/[\r\n\t]/g, ''),
dropLeft: parseInt(cardsDropLeft),
};
@ -71,7 +71,7 @@ function getBadges() {
const collection = doc.getElementsByClassName('badge_row');
for (const value of Object.entries(collection)) {
badges.push(getData(value));
badges.push(getData(value[1]));
}
})
.catch((err) => console.warn('Something went wrong.', err));