Last active
March 9, 2018 17:29
-
-
Save petele/d0a88a6603b77e8983d2 to your computer and use it in GitHub Desktop.
Calculates the number of rides and amount you've spent with Uber.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.