Skip to content

Instantly share code, notes, and snippets.

@Juice10
Last active November 12, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juice10/743d66e889d7b6543b5802effbac1ac8 to your computer and use it in GitHub Desktop.
Save Juice10/743d66e889d7b6543b5802effbac1ac8 to your computer and use it in GitHub Desktop.
Script to set all items in Splitwise to a specific ratio (useful for couples paying rent etc. based on income)
var yearlyIncomePersonA = 120000;
var yearlyIncomePersonB = 100000;
var query = '.expense:not(.summary)'
var delayMultiplier = 20;
var elLength = $(query).length;
var i = 0;
var maxNum = 0; // maximum number of items it should edit
var interval = setInterval(function () {
var elements = $(query).toArray();
var el = elements[i];
if (typeof el === 'undefined' || (maxNum && maxNum <= i)) {
console.log('out of items', i);
return clearInterval(interval);
}
console.log('processing', i, el);
// skip payments, they don't need to be altered
if ($(el).find('div.summary > .payment').length) {
i++;
return;
}
$(el).find(' div.summary > div > div.main-block > div.header > span > a').click();
console.log('clicked', $(el).find(' div.summary > div > div.main-block > div.header > span > a'));
setTimeout(function(){
$(el).find('a:contains(Edit)').click();
console.log('editing');
setTimeout(function(){
$('.main-window .split').click();
console.log('split');
$('button[data-split-subtype=shares]').click();
console.log('shares');
$('.split_method.shares .person input:first').val(yearlyIncomePersonA);
$('.split_method.shares .person input:nth(1)').val(yearlyIncomePersonB);
$('.split_method.shares .person input:nth(1)').keyup();
console.log('set');
$('.main-window button.submit:contains(Save)').click();
console.log('saved', i);
i++;
}, 100 * delayMultiplier)
}, 100 * delayMultiplier)
}, 250 * delayMultiplier)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment