Skip to content

Instantly share code, notes, and snippets.

@petele
Last active March 9, 2018 17:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petele/d0a88a6603b77e8983d2 to your computer and use it in GitHub Desktop.
Save petele/d0a88a6603b77e8983d2 to your computer and use it in GitHub Desktop.
Calculates the number of rides and amount you've spent with Uber.
// To use: Visit https://riders.uber.com/trips, open the Chrome DevTools and
// paste this script into the console, then click the > (next page) icon on the
// bottom of the page, and once the page has finished loading, run `calcPage()`
// again to add that page to your total. Keep going until you've finished all of
// the pages.
// Note: this script doesn't handle different currencies, everything will be
// treated as the same currency.
var total = 0.0;
var count = 0.0;
function calcPage() {
var list = $("tr.trip-expand__origin").find("td:nth-child(4)");
for (var i = 0; i < list.length; i++) {
var line = list[i].innerText.substring(1);
try {
total += parseFloat(line, 10);
count++;
} catch (ex) {
console.log("error", line);
}
}
console.log(count, total);
}
calcPage();
@matt-wright86
Copy link

Hi Pete, in the case of a ride being canceled, the word "canceled" will appear where you expect a number to.

this can be resolved by wrapping the try catch in an if statement that ignores non number values.

var total = 0.0;
var count = 0.0;

function calcPage() {
  var list = $("tr.trip-expand__origin").find("td:nth-child(4)");
  for (var i = 0; i < list.length; i++) {
    var line = list[i].innerText.substring(1);
    
    if (!isNaN(line)) {
      console.log('line', line);
      try {
        total += parseFloat(line, 10);
        console.log('total', total);
        count++;
      } catch (ex) {
        console.log("error", line);
      }
    }
  }
  console.log(count, total);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment