add code to insert HTML elements for new stats

This commit is contained in:
Maximilian Keßler 2022-10-21 13:31:41 +02:00
parent 7513837bb8
commit 9737674953
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -199,6 +199,29 @@ function injectCounter() {
buttons.insertBefore(showCardCounterButton, document.getElementById('autoFold'));
buttons.insertBefore(smartFoldButton, document.getElementById('autoFold'));
var patchPlayerStats = function(direction) {
playerLevel = document.getElementById(direction + 'PlayerLevel');
playerGoldTourns = document.getElementById(direction + 'PlayerGoldTourns');
playerTichu = document.getElementById(direction + 'PlayerTichu');
playerDiv = playerLevel.parentElement;
playerDiv.removeChild(playerLevel);
playerDiv.removeChild(playerGoldTourns);
playerMyLevel = document.createElement('div');
playerMyLevel.id = direction + 'PlayerMyLevel';
playerMyLevel.innerText = 'test: level';
playerTichuCoefficient = document.createElement('div');
playerTichuCoefficient.id = direction + 'PlayerTichuCoefficient';
playerTichuCoefficient.innerText = 'test: TC';
playerDiv.insertBefore(playerMyLevel, playerTichu);
playerDiv.insertBefore(playerTichuCoefficient, playerTichu);
}
patchPlayerStats('south');
// playedCards.
// ot.$gameField.insertAfter(playedCards, ot.$gameField.lastChild);
@ -241,6 +264,7 @@ function injectCounter() {
// dynamic feature state
davidProtectionTriggered: true,
bombAfterFold: null, // to implement
stats: {},
util: {
displayCardsHtmlString: function(cards) {
@ -301,6 +325,7 @@ function injectCounter() {
return parseFloat(num);
},
// warning: note that this is async
getStats: function(user) {
$.get('https://www.onlinetichu.com/Site/Profiles/User/' + user, null, function(text){
statsNav = $(text).find('#nav-statistics');
@ -327,16 +352,33 @@ function injectCounter() {
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),
grandTichuSuccessful: 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),
tichuSuccessful: 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);
lostGrand = generalStats.grandTichuCalled - generalStats.grandTichuSuccessful;
lostTichu = generalStats.tichuCalled - generalStats.tichuSuccessful;
var customStats = {
abandonmentRate: (generalStats.abandonments / (generalStats.games + generalStats.goldGames) * 100).toFixed(1),
grandTichuUnsuccesful: lostGrand,
tichuUnsuccesful: lostTichu,
tichuCoefficient: ( (generalStats.grandTichuSuccessful - lostGrand) * 200 + (generalStats.tichuSuccessful - lostTichu) * 100 ) / generalStats.rounds
}
var userStats = {
custom: customStats,
general: generalStats
}
otc.stats[user] = userStats ;
console.log(otc.stats[user]);
});
}
},
@ -634,6 +676,8 @@ function injectCounter() {
ot.reaction.TableState = MyTableState;
ot.reaction.Chat = MyChat;
ot.action.ExchangeCards = MyExchangeCards;
otc.util.getStats('Ramanujan1729');
};