Skip to content

Instantly share code, notes, and snippets.

@meoyawn
Last active September 7, 2023 16:09
Show Gist options
  • Save meoyawn/6fbefa52e65d0d861258c45d64f2678e to your computer and use it in GitHub Desktop.
Save meoyawn/6fbefa52e65d0d861258c45d64f2678e to your computer and use it in GitHub Desktop.
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