Skip to content

Instantly share code, notes, and snippets.

@matiassingers
Forked from srn/just-eat-sum.js
Last active January 4, 2016 08:19
Show Gist options
  • Save matiassingers/8594681 to your computer and use it in GitHub Desktop.
Save matiassingers/8594681 to your computer and use it in GitHub Desktop.
// visit: https://just-eat.dk/member/prevorders
// run it once per year
var siblings = $('#ctl00_ContentPlaceHolder1_rightbox a[href^="javascript:__doPostBack(\'ctl00$ContentPlaceHolder1$ctl00$ctl"').siblings(),
sum = isNaN(localStorage.getItem('JE')) ? 0 : parseInt(localStorage.getItem('JE'), 10),
yearSum = 0;
$('#ctl00_ContentPlaceHolder1_rightbox table tbody tr').each(function(){
var amount = parseInt($(this).find('td').eq(3).find('div').find('div').eq(0).text(), 10);
if (isNaN(amount)) return;
yearSum += amount;
});
console.log('Total in', getYear() + ':', yearSum);
localStorage.setItem(getYear(), yearSum);
console.log('Total so far:', getTotal());
localStorage.setItem('JE', getTotal());
function getTotal(){
var total = 0;
for (var i = 0; i < siblings.length; i += 2) {
total += isNaN(localStorage.getItem($(siblings[i]).text())) || !localStorage.getItem($(siblings[i]).text()) ? 0 : parseInt(localStorage.getItem($(siblings[i]).text()), 10);
}
return total;
}
function getYear(){
for (var i = 0; i < siblings.length; i += 2) {
if($(siblings[i]).attr('disabled') == 'disabled')
return $(siblings[i]).text();
}
}
var siblings=$('#ctl00_ContentPlaceHolder1_rightbox a[href^="javascript:__doPostBack(\'ctl00$ContentPlaceHolder1$ctl00$ctl"').siblings(),sum=isNaN(localStorage.getItem('JE'))?0:parseInt(localStorage.getItem('JE'),10),yearSum=0;$('#ctl00_ContentPlaceHolder1_rightbox table tbody tr').each(function(){var amount=parseInt($(this).find('td').eq(3).find('div').find('div').eq(0).text(),10);if(isNaN(amount))return;yearSum+=amount});console.log('Total in',getYear()+':',yearSum);localStorage.setItem(getYear(),yearSum);console.log('Total so far:',getTotal());localStorage.setItem('JE',getTotal());function getTotal(){var total=0;for(var i=0;i<siblings.length;i+=2){total+=isNaN(localStorage.getItem($(siblings[i]).text()))||!localStorage.getItem($(siblings[i]).text())?0:parseInt(localStorage.getItem($(siblings[i]).text()),10)}return total}function getYear(){for(var i=0;i<siblings.length;i+=2){if($(siblings[i]).attr('disabled')=='disabled')return $(siblings[i]).text()}
// list all year totals
var siblings = $('#ctl00_ContentPlaceHolder1_rightbox a[href^="javascript:__doPostBack(\'ctl00$ContentPlaceHolder1$ctl00$ctl"').siblings()
for (var i = 0; i < siblings.length; i += 2) {
console.log($(siblings[i]).text(), parseInt(localStorage.getItem($(siblings[i]).text()), 10))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment