Created
June 14, 2018 00:28
-
-
Save sharnie/6c18735741eda58301250802eea0a4c2 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
(function() { | |
'use strict'; | |
const container = document.querySelector('.products-thumbnails.product-card-container, .products-grid'); | |
const products = container.querySelectorAll('.product-card, .js-paginated-product.user-product-card'); | |
const sortBySaves = Array.from(products).sort((productA, productB) => { | |
const savesA = productA.querySelector('.save-it.overlay-button .js-saves-count').innerText.replace(/[^\d+]+/gi, ''); | |
const savesB = productB.querySelector('.save-it.overlay-button .js-saves-count').innerText.replace(/[^\d+]+/gi, ''); | |
return savesA - savesB; | |
}).reverse(); | |
container.innerHTML = ''; | |
sortBySaves.forEach(product => container.appendChild(product)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment