Skip to content

Instantly share code, notes, and snippets.

@lilliliilil
Last active February 22, 2016 10:44
Show Gist options
  • Select an option

  • Save lilliliilil/9fdd4e293f9f5de54253 to your computer and use it in GitHub Desktop.

Select an option

Save lilliliilil/9fdd4e293f9f5de54253 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name CSGL Total Value
// @version 0.1
// @match *://csgolounge.com/mybets
// @grant none
// ==/UserScript==
function value(item) {
return +item.querySelector('.value').textContent.slice(2);
}
function total(items) {
return [].reduce.call(items, function(total, item) {
return total + value(item);
}, 0);
}
function render(header, items) {
header = document.querySelector(header);
items = document.querySelectorAll(items + ' .item');
header.textContent = header.textContent
.replace(/(.*[a-z]).*/i, '$1: $$' + total(items).toFixed(2));
}
function update() {
render('#betreturns > :nth-child(1)', '#betreturns > :nth-child(2)'); // won
render('#betreturns > :nth-child(3)', '#betreturns > :nth-child(1n+4)'); // returned
render('#betreturns ~ div', '#betreturns ~ form'); // requested
}
render('.box:nth-child(1) .title', '.box:nth-child(1)'); // bets
render('.box:nth-child(2) .title', '.box:nth-child(2)'); // returns
update();
new MutationObserver(update)
.observe(document.querySelector('#betreturns'),
{ childList: true, subtree: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment