new feature: hide own cards when showing remaining cards

This commit is contained in:
Maximilian Keßler 2023-01-09 18:58:29 +01:00
parent 23bf7d7cec
commit fbf28302b2
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -1,6 +1,6 @@
// ==UserScript== // ==UserScript==
// @name onlinetichu.com card counter // @name onlinetichu.com card counter
// @version 1.3.6 // @version 1.4.0
// @description automatically count cards at onlinetichu.com // @description automatically count cards at onlinetichu.com
// @match *://*.onlinetichu.com/Site/Game/Table/* // @match *://*.onlinetichu.com/Site/Game/Table/*
// @author Maximilian Keßler // @author Maximilian Keßler
@ -119,12 +119,19 @@ function injectCounter() {
showRemainingButton.type = "button"; showRemainingButton.type = "button";
showRemainingButton.innerHTML = 'Show: <span id="showRemainingValue" data-on="Remaining" data-off="Played">Remaining</span>'; showRemainingButton.innerHTML = 'Show: <span id="showRemainingValue" data-on="Remaining" data-off="Played">Remaining</span>';
var showOwnCardsButton = document.createElement('button');
showOwnCardsButton.className = "btn btn-primary btn-xs";
showOwnCardsButton.id = "showOwnCards";
showOwnCardsButton.type = "button";
showOwnCardsButton.innerHTML = 'OwnCards: <span id="showOwnCardsValue" data-on="Shown" data-off="Hidden">Shown</span>';
var showCountedCardsButton = document.createElement('button'); var showCountedCardsButton = document.createElement('button');
showCountedCardsButton.className = "btn btn-success btn-xs"; showCountedCardsButton.className = "btn btn-success btn-xs";
showCountedCardsButton.id = "showCountedCards"; showCountedCardsButton.id = "showCountedCards";
showCountedCardsButton.type = "button"; showCountedCardsButton.type = "button";
showCountedCardsButton.innerHTML = 'Show cards: <span id="showCountedCardsValue" data-on="Yes" data-off="No">No</span>'; showCountedCardsButton.innerHTML = 'Show cards: <span id="showCountedCardsValue" data-on="Yes" data-off="No">No</span>';
controlButtonsRight.appendChild(showOwnCardsButton);
controlButtonsRight.appendChild(showRemainingButton); controlButtonsRight.appendChild(showRemainingButton);
controlButtonsRight.appendChild(showCountedCardsButton); controlButtonsRight.appendChild(showCountedCardsButton);
controlButtonsLeft.appendChild(davidProtectionButton); controlButtonsLeft.appendChild(davidProtectionButton);
@ -237,6 +244,8 @@ function injectCounter() {
$showCardCounterValue: $('#showCardCounterValue'), $showCardCounterValue: $('#showCardCounterValue'),
$showRemaining: $('#showRemaining'), $showRemaining: $('#showRemaining'),
$showRemainingValue: $('#showRemainingValue'), $showRemainingValue: $('#showRemainingValue'),
$showOwnCards: $('#showOwnCards'),
$showOwnCardsValue: $('#showOwnCardsValue'),
$showCountedCards: $('#showCountedCards'), $showCountedCards: $('#showCountedCards'),
$showCountedCardsValue: $('#showCountedCardsValue'), $showCountedCardsValue: $('#showCountedCardsValue'),
$davidProtection: $('#davidProtection'), $davidProtection: $('#davidProtection'),
@ -267,10 +276,12 @@ function injectCounter() {
exchangedFrom: {}, exchangedFrom: {},
handCardShuffle: [], handCardShuffle: [],
playerNames: {}, playerNames: {},
ownCards: [],
// config values, triggered with buttons // config values, triggered with buttons
smartFold: false, smartFold: false,
showCardCounter: false, showCardCounter: false,
showOwnCards: true,
showRemaining: true, showRemaining: true,
showCountedCards: false, showCountedCards: false,
davidProtection: false, davidProtection: false,
@ -476,7 +487,7 @@ function injectCounter() {
if (otc.showRemaining) { if (otc.showRemaining) {
cards = []; cards = [];
for(let j=0; j < otc.allCards[i].length; j ++) { for(let j=0; j < otc.allCards[i].length; j ++) {
if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i])) { if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i]) && (otc.showOwnCards || !otc.util.cardInArray(otc.allCards[i][j], otc.ownCards))) {
cards.push(otc.allCards[i][j]); cards.push(otc.allCards[i][j]);
} }
otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards)); otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards));
@ -578,6 +589,16 @@ function injectCounter() {
otc.action.drawPlayedCards(); otc.action.drawPlayedCards();
}); });
otc.$showOwnCards.click(function () {
otc.showOwnCards = !otc.showOwnCards;
if (otc.showOwnCards) {
otc.$showOwnCardsValue.text(otc.$showOwnCardsValue.data('on'));
} else {
otc.$showOwnCardsValue.text(otc.$showOwnCardsValue.data('off'));
}
otc.action.drawPlayedCards();
});
for(let i = 1; i < 15; i++) { for(let i = 1; i < 15; i++) {
otc.$playedCards[i] = $('#playedCards' + i); otc.$playedCards[i] = $('#playedCards' + i);
} }
@ -635,6 +656,7 @@ function injectCounter() {
southPosition = 1; southPosition = 1;
$(message.Table.Players).each(function () { $(message.Table.Players).each(function () {
if (this.Username == ot.$Username.val()) { if (this.Username == ot.$Username.val()) {
otc.ownCards = this.Cards;
spectator = false; spectator = false;
southPosition = this.Position; southPosition = this.Position;
// console.log('found player'); // console.log('found player');