Skip to content

Instantly share code, notes, and snippets.

@vjo
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save vjo/db72ca5e839c51d8c816 to your computer and use it in GitHub Desktop.

Select an option

Save vjo/db72ca5e839c51d8c816 to your computer and use it in GitHub Desktop.
Get how much money you already have spend on Capitainetrain.com
var t = {'total': 0, 'detail': {}};
$.each(document.getElementsByClassName('folder'),
function(k, v){
var date_str = v.getElementsByClassName('large-date')[0].title;
var year = date_str.slice(-4);
var price = parseFloat(v.getElementsByClassName('folder__price-label')[0].textContent.replace(/€/, '').replace(/ /, '').replace(',', '.'));
if(!t.detail[year]){
t.detail[year] = {'total': 0, 'tickets': []};
}
t.detail[year].tickets.push({'price': price, 'date_str': date_str});
t.detail[year].total += price;
t.total += price;
}
);
console.log(t);
/*
On tickets page (https://www.capitainetrain.com/tickets), you need to scroll down to your first ticket.
Then, open the developer console of your browser and paste this code.
Price on English interface: €XX.XX
Price on French interface: XX,XX €
*/
var devise = "€", t = 0;
$('.folder__price-label').each(
function(k, v){
var i = v.innerHTML.replace(/€/, '').replace(/ /, '').replace(',', '.');
t += parseFloat(i);
}
);
console.log(t + devise);
/* Functional way */
$.makeArray($('.folder__price-label')).reduce(
function(sum, e){
return sum + parseFloat(e.innerHTML.replace(/€/, '').replace(/ /, '').replace(',', '.'))
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment