Skip to content

Instantly share code, notes, and snippets.

@nezort11
Last active April 20, 2024 07:02
Show Gist options
  • Save nezort11/7cc0658c0fceb70247ee6a48e5e23186 to your computer and use it in GitHub Desktop.
Save nezort11/7cc0658c0fceb70247ee6a48e5e23186 to your computer and use it in GitHub Desktop.
Wildberries sort by product rating count
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