Last active
April 26, 2024 21:04
-
-
Save nezort11/32eed59e78b34e5896114acac23cd057 to your computer and use it in GitHub Desktop.
Sort products in Ozon search results based on rating count (sales)
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 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