Last active
April 20, 2024 07:02
-
-
Save nezort11/7cc0658c0fceb70247ee6a48e5e23186 to your computer and use it in GitHub Desktop.
Wildberries sort by product rating count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var productCardList = document.querySelector('.product-card-list'); | |
var productCards = Array.from(productCardList.querySelectorAll('.product-card')); | |
var gerProductCardRatingCount = (productCard) => { | |
const productCardRatingCountDigits = productCard.querySelector('.product-card__count')?.innerText.match(/\d/g) || ['0']; | |
return Number(productCardRatingCountDigits.join('')); | |
} | |
productCards.sort((productCard1, productCard2) => { | |
const productCardRatingCount1 = gerProductCardRatingCount(productCard1); | |
const productCardRatingCount2 = gerProductCardRatingCount(productCard2); | |
return productCardRatingCount2 - productCardRatingCount1; | |
}); | |
productCards.forEach((productCard) => { | |
productCardList.appendChild(productCard); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment