diff --git a/onlinetichu-counter.js b/onlinetichu-counter.js index d7b078c..326f25d 100644 --- a/onlinetichu-counter.js +++ b/onlinetichu-counter.js @@ -284,6 +284,60 @@ function injectCounter() { } } return contained; + }, + + extractInt: function(text) { + num = /\d+(m|k)?/.exec(text)[0]; + if (num.includes('k')) { + return 1000 * parseInt(num.split('k')[0]); + } else if (num.includes('m')) { + return 1000000 * parseInt(num.split('m')[0]); + } + return parseInt(num); + }, + + extractFloat: function(text) { + num = /\d+(\.\d+)?/.exec(text)[0]; + return parseFloat(num); + }, + + getStats: function(user) { + $.get('https://www.onlinetichu.com/Site/Profiles/User/' + user, null, function(text){ + statsNav = $(text).find('#nav-statistics'); + wbox1 = statsNav.children()[1]; + + c1 = wbox1.children[0].children[0].children[1].children; + c2 = wbox1.children[0].children[0].children[2].children; + + + var generalStats = { + level: otc.util.extractInt( c1[0].innerText), + nextLevelIn: otc.util.extractFloat( c1[1].innerText), + rating: otc.util.extractInt( c1[2].innerText), + games: otc.util.extractFloat( c1[3].innerText), + wins: otc.util.extractFloat( c1[4].innerText.split("-")[0]), + defeats: otc.util.extractFloat( c1[4].innerText.split("-")[1]), + winningPercentage: otc.util.extractFloat( c1[5].innerText), + goldGames: otc.util.extractFloat( c1[6].innerText), + goldWins: otc.util.extractFloat( c1[7].innerText.split("-")[0]), + goldDefeats: otc.util.extractFloat( c1[7].innerText.split("-")[1]), + goldWinningPercentage: otc.util.extractFloat( c1[8].innerText), + points: otc.util.extractInt( c1[9].innerText), + rounds: otc.util.extractInt( c1[10].innerText), + oneTwo: otc.util.extractInt( c1[11].innerText), + grandTichuPercentage: otc.util.extractFloat( c2[0].innerText), + grandTichuCalled: otc.util.extractInt( c2[1].innerText), + grandTichuSuccesful: otc.util.extractInt( c2[2].innerText), + tichuPercentage: otc.util.extractFloat( c2[3].innerText), + tichuCalled: otc.util.extractInt( c2[4].innerText), + tichuSuccesful: otc.util.extractInt( c2[5].innerText), + tournaments: otc.util.extractInt( c2[6].innerText), + tournamentsFirstAward: otc.util.extractInt( c2[7].innerText), + tournamentsSecondAward: otc.util.extractInt( c2[8].innerText), + abandonments: otc.util.extractInt( c2[9].innerText) + }; + console.log(generalStats); + }); } },