Last active
September 7, 2023 16:09
-
-
Save meoyawn/6fbefa52e65d0d861258c45d64f2678e to your computer and use it in GitHub Desktop.
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
const productContainer = document.querySelector('div[data-qa-locator="general-products"]'); | |
const sortedEls = Array.from(productContainer.children) | |
.flatMap(product => { | |
const salesInfo = product.querySelector('._1cEkb'); | |
if (!salesInfo) return []; | |
const salesText = salesInfo.innerText; | |
const [soldStr] = salesText.split(' ') | |
const salesCount = parseInt(soldStr.replace(",", "")); | |
return [{ productElement: product, salesCount }]; | |
}) | |
.sort((a, b) => b.salesCount - a.salesCount) | |
.map(x => x.productElement); | |
productContainer.innerHTML = ""; | |
for (const el of sortedEls) { | |
productContainer.appendChild(el); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment