Skip to content

Instantly share code, notes, and snippets.

@nezort11
Last active April 26, 2024 21:04
Show Gist options
  • Save nezort11/32eed59e78b34e5896114acac23cd057 to your computer and use it in GitHub Desktop.
Save nezort11/32eed59e78b34e5896114acac23cd057 to your computer and use it in GitHub Desktop.
Sort products in Ozon search results based on rating count (sales)
var productCardListList = document.querySelectorAll('.widget-search-result-container > div');
var productCards = [];
productCardListList.forEach((productCardList) => {
const productCardListCards = Array.from(productCardList.querySelectorAll('.widget-search-result-container > div > div'));
productCards = [...productCards, ...productCardListCards];
});
var gerProductCardRatingCount = (productCard) => {
const productCardRatingCountDigits = productCard.querySelector('.tsBodyMBold > span:last-of-type')?.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) => {
productCardListList[0]?.appendChild(productCard);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment