Skip to content

Instantly share code, notes, and snippets.

@jonasjohansson
Created April 9, 2018 21:20
Show Gist options
  • Save jonasjohansson/6c03617b00eed8a44756649601d07c3e to your computer and use it in GitHub Desktop.
Save jonasjohansson/6c03617b00eed8a44756649601d07c3e to your computer and use it in GitHub Desktop.
var els = document.querySelectorAll('.views-row');
var newEls = [];
for (const el of els){
let productName = el.querySelector('.prd-name').innerHTML;
let normalPrice = el.querySelector('span[data-normal-price]').getAttribute('data-normal-price');
let currentPrice = el.querySelector('span[data-cur-price]').getAttribute('data-cur-price');
newEls.push({
el: el,
item: productName,
normalPrice: normalPrice,
currentPrice: currentPrice,
diff: currentPrice / normalPrice
});
if (currentPrice / normalPrice > 0.6){
el.parentElement.removeChild(el);
}
}
function compare(a,b) {
if (a.diff < b.diff)
return -1;
if (a.diff > b.diff)
return 1;
return 0;
}
newEls.sort(compare);
for (const newEl of newEls){
// newEl.el.querySelector('a').style.backgroundColor = 'rgba(255,0,0,'+newEl.diff+')';
console.log('diff: ',newEl.diff,' item:',newEl.item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment