Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(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;
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
You can’t perform that action at this time.