Skip to content

Instantly share code, notes, and snippets.

@nezort11
Last active April 17, 2024 23:06
Show Gist options
  • Save nezort11/cca9468c4cf5982dafdf603d23e31c07 to your computer and use it in GitHub Desktop.
Save nezort11/cca9468c4cf5982dafdf603d23e31c07 to your computer and use it in GitHub Desktop.
Sort products in Yandex Market search results based on rating count (sales)
var productCardList = document.querySelector('.SerpLayout');
var productCards = Array.from(productCardList.querySelectorAll('[data-apiary-widget-name="@light/Organic"]'));
var gerProductCardRatingCount = (productCard) => {
const productCardRatingCountDigits = productCard.querySelector('[data-baobab-name="rating"] > div:last-of-type > div: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) => {
productCardList.appendChild(productCard);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment