Skip to content

Instantly share code, notes, and snippets.

@fernandobhz
Created May 16, 2017 04:23
Show Gist options
  • Select an option

  • Save fernandobhz/cd4def9a77646ee2092d294bcfce1f9f to your computer and use it in GitHub Desktop.

Select an option

Save fernandobhz/cd4def9a77646ee2092d294bcfce1f9f to your computer and use it in GitHub Desktop.
javascript: (function() {
var results = [];
var totalTrips = 0;
var cancelledTrips = 0;
var nbTripsShared = 0;
var finishedParsing = false;
var totalNbPeopleSharedWith = 0;
var urlCalculated = [];
function parsePage(page) {
if (urlCalculated.indexOf(document.URL) != -1) return;
for (var i = 0; i < document.querySelectorAll('td.text--right').length; ++i) {
totalNbPeopleSharedWith = 1;
var cancelled = false;
while (document.getElementsByClassName('icon_surge').length > 0) {
document.getElementsByClassName('icon_surge')[0].parentNode.removeChild(document.getElementsByClassName('icon_surge')[0]);
}
var classNameToDelete = 'caption';
while (document.getElementsByClassName(classNameToDelete).length > 0) {
document.getElementsByClassName(classNameToDelete)[0].parentNode.removeChild(document.getElementsByClassName(classNameToDelete)[0]);
cancelledTrips++;
}
var priceElemContainer = document.querySelectorAll('td.text--right')[i];
var priceElemInnerHtml = document.querySelectorAll('td.text--right')[i].innerHTML;
if (document.querySelectorAll('td.text--right')[i].parentNode.childNodes[1].childNodes.length > 1) {
var sharedRide = document.querySelectorAll('td.text--right')[i].parentNode.childNodes[1].childNodes[1];
var peopleSharedWith = sharedRide.innerHTML.split(',');
totalNbPeopleSharedWith = peopleSharedWith.length + 1;
nbTripsShared++;
}
if (priceElemInnerHtml != '') {
for (z = 0; z < 5; ++z) {
priceElemInnerHtml = priceElemInnerHtml.replace('%C2%A0', '');
priceElemInnerHtml = priceElemInnerHtml.replace('null;', '');
}
var valueToAdd = priceElemInnerHtml.match(/[0-9]{1,6}?[.|,]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?/gm);
if (Array.isArray(valueToAdd)) {
if (valueToAdd.length == 1) {
valueToAdd = valueToAdd[0]
} else if (valueToAdd.length == 2) {
if (priceElemInnerHtml.indexOf('.') != -1) {
valueToAdd = valueToAdd[0] + '.' + valueToAdd[1];
} else if (priceElemInnerHtml.indexOf(',') != -1) {
valueToAdd = valueToAdd[0] + ',' + valueToAdd[1];
} else {
alert('tweet @alexeichemenda and say error log : commas are buggy #uberStats');
}
}
}
var currency = priceElemInnerHtml.replace(valueToAdd, '');
currency = currency.replace('%C2%A0', '');
currency = currency.replace('%C2%A0', '');
currency = currency.replace('%C2%A0', '');
currency = currency.replace('null', '');
currency = currency.replace('null', '');
currency = currency.replace('null', '');
valueToAdd = parseInt(valueToAdd) / totalNbPeopleSharedWith;
if (currency.length > 0 && currency.length != '' && results[currency] == null) {
results[currency] = 0;
}
results[currency] += valueToAdd;
if (valueToAdd > 0) totalTrips++;
urlCalculated.push(document.URL);
}
}
for (var key in results) {
console.log('Now at ' + results[key] + ' paid in ' + key);
}
console.log('Now at ' + totalTrips + ' number of trips made');
console.log('Now at ' + cancelledTrips + ' number of trips cancelled');
}
var counter = 0;
var startedParsing = false;
var finishUberRatingCalculus = false;
function myinterval() {
if (finishUberRatingCalculus == true) return;
console.log('Gathering trip infos ...');
startedParsing = false;
parsePage(counter);
$($('#trips-table')[0]).one('DOMNodeInserted DOMNodeRemoved DOMSubtreeModified', function(event) {
if (startedParsing == false) {
startedParsing = true;
setTimeout(function() {
if (startedParsing == true) {
console.log('starting analyzing new page...');
startedParsing = false;
myinterval();
}
}, 2000);
}
});
if ($('.icon_right-arrow')[$('.icon_right-arrow').length - 1].parentNode.getAttribute('href') != null) {
$('.pagination__next')[0].click();
counter++;
} else {
function displayStats() {
var url = 'https://uberstats.parseapp.com/index';
var arr = [];
for (var key in results) {
arr.push(key);
arr.push(results[key]);
}
finishUberRatingCalculus = true;
var form = document.createElement('form');
form.setAttribute('method', 'POST');
form.setAttribute('action', url);
var hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'text');
hiddenField.setAttribute('name', 'form_dollars_spent_value');
hiddenField.setAttribute('value', JSON.stringify(arr));
form.appendChild(hiddenField);
var hiddenField2 = document.createElement('input');
hiddenField2.setAttribute('type', 'text');
hiddenField2.setAttribute('name', 'form_nb_shared_rides_value');
hiddenField2.setAttribute('value', nbTripsShared);
form.appendChild(hiddenField2);
var hiddenField3 = document.createElement('input');
hiddenField3.setAttribute('type', 'text');
hiddenField3.setAttribute('name', 'form_nb_cancelled_value');
hiddenField3.setAttribute('value', cancelledTrips);
form.appendChild(hiddenField3);
var hiddenField4 = document.createElement('input');
hiddenField4.setAttribute('type', 'text');
hiddenField4.setAttribute('name', 'form_nb_total_rides_value');
hiddenField4.setAttribute('value', totalTrips);
form.appendChild(hiddenField4);
$('body').append(form);
$(form).submit();
}
displayStats();
}
}
myinterval();
console.log('Starting gathering your history on Uber');
alert('Starting gathering trip infos. Don\'t touch this page until you see your results. (~40 seconds usually). You can see the URL moving from page to page');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment