2022-09-15 03:13:05 +02:00
|
|
|
// ==UserScript==
|
|
|
|
// @name onlinetichu.com card counter
|
|
|
|
// @version 1.0.0
|
|
|
|
// @description automatically count cards at onlinetichu.com
|
|
|
|
// @author kesslermaximilian
|
|
|
|
// @match *://*.onlinetichu.com/Site/Game/Table/*
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
// disable auto fold functionality completely
|
|
|
|
if (ot.AutoFold) {
|
|
|
|
ot.$autoFold.click()
|
|
|
|
ot.$autoFold.hide()
|
|
|
|
}
|
|
|
|
var myStyles = `
|
|
|
|
#playedHigh {
|
|
|
|
position: absolute;
|
|
|
|
top: 620px;
|
|
|
|
width: 850px;
|
2022-09-15 08:55:19 +02:00
|
|
|
height: 120px;
|
2022-09-15 03:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#playedLow {
|
|
|
|
position: absolute;
|
|
|
|
top: 750px;
|
|
|
|
width: 850px;
|
2022-09-15 08:55:19 +02:00
|
|
|
height: 120px;
|
2022-09-15 03:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.playedCardsLayout {
|
|
|
|
position: absolute;
|
|
|
|
height: 125px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.playedCardsLayout .card {
|
|
|
|
width: 80px;
|
|
|
|
height: 120px;
|
|
|
|
border-radius: 5px;
|
|
|
|
float: left;
|
|
|
|
margin-left: -50px;
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
.playedCardsLayout .card:hover {
|
|
|
|
z-index: 1400;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var styleSheet = document.createElement("style")
|
|
|
|
styleSheet.innerText = myStyles;
|
|
|
|
console.log(styleSheet);
|
|
|
|
document.head.appendChild(styleSheet);
|
|
|
|
|
|
|
|
// add an extra field where we will put down the played cards
|
|
|
|
|
|
|
|
var playedHigh = document.createElement('div');
|
|
|
|
playedHigh.id = 'playedHigh';
|
|
|
|
playedHigh.style.marginLEft = '25px';
|
|
|
|
playedHigh.className = 'row';
|
|
|
|
|
|
|
|
var playedLow = document.createElement('div');
|
|
|
|
playedLow.id = 'playedLow';
|
|
|
|
playedLow.style.marginLEft = '25px';
|
|
|
|
playedLow.className = 'row';
|
|
|
|
|
|
|
|
tableIG = document.getElementById('gameField').parentNode;
|
|
|
|
tableIG.appendChild(playedHigh);
|
|
|
|
tableIG.appendChild(playedLow);
|
|
|
|
|
|
|
|
var createCardPlace = function(value, shift, node) {
|
|
|
|
var playedCards = document.createElement('ul');
|
|
|
|
playedCards.id = 'playedCards' + value;
|
|
|
|
// playedCards.className = 'layoutPlayedCards list-unstyled col-lg-2';
|
2022-09-15 08:55:19 +02:00
|
|
|
// playedCards.className = 'playedCardsLayout list-unstyled';
|
2022-09-15 03:13:05 +02:00
|
|
|
playedCards.className = 'playedCardsLayout list-unstyled';
|
|
|
|
playedCards.style.width = '160px';
|
|
|
|
playedCards.style.marginLeft = '25px';
|
|
|
|
playedCards.style.left = shift*135 + 'px';
|
|
|
|
|
|
|
|
node.appendChild(playedCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
createCardPlace(1, 0, document.getElementById('playedHigh'));
|
|
|
|
for(let i = 14; i > 8; i--) {
|
|
|
|
createCardPlace(i, 14 - i + 1, document.getElementById('playedHigh'));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(let i = 8; i > 1; i--) {
|
|
|
|
createCardPlace(i, 8 - i, document.getElementById('playedLow'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// playedCards.
|
|
|
|
// ot.$gameField.insertAfter(playedCards, ot.$gameField.lastChild);
|
|
|
|
|
|
|
|
// set up counting of played cards
|
|
|
|
var OnlineTichuCounter = {
|
|
|
|
$playedCards: {},
|
2022-09-15 19:54:02 +02:00
|
|
|
allCards: {},
|
|
|
|
playedCards: {},
|
|
|
|
totalPlayed: [],
|
|
|
|
exchangedTo: {},
|
|
|
|
exchangedFrom: {},
|
|
|
|
|
|
|
|
util: {
|
|
|
|
displayCardsHtmlString: function(cards) {
|
|
|
|
htmlString = "";
|
|
|
|
$(cards).each(function () {
|
|
|
|
var value = this.Value;
|
|
|
|
if (this.Shape == 7) {
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
htmlString += '<li id="c' + this.Shape + '-' + value
|
|
|
|
+ '" class="card c' + this.Shape + '-' + value
|
|
|
|
+ '" data-shape="' + this.Shape + '" data-value="'
|
|
|
|
+ value + '"></li>';
|
|
|
|
});
|
|
|
|
return htmlString;
|
|
|
|
},
|
|
|
|
|
|
|
|
populateAllCards: function() {
|
|
|
|
for(let val = 2; val < 15; val++) {
|
|
|
|
otc.allCards[val] = [];
|
|
|
|
for(let shape = 0; shape < 4; shape++) {
|
|
|
|
otc.allCards[val].push({
|
|
|
|
Shape: shape,
|
|
|
|
Value: val
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
otc.allCards[1] = [
|
|
|
|
{ Shape: 4, Value: 1 },
|
|
|
|
{ Shape: 5, Value: 0 },
|
|
|
|
{ Shape: 6, Value: 15},
|
|
|
|
{ Shape: 7, Value: 14 }
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
cardInArray: function(card, array) {
|
|
|
|
contained = false;
|
|
|
|
for(let i = 0; i < array.length; i++) {
|
|
|
|
if (array[i].Shape == card.Shape && array[i].Value == card.Value) {
|
|
|
|
contained = true;
|
|
|
|
}
|
|
|
|
return contained;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-09-15 03:13:05 +02:00
|
|
|
|
|
|
|
action: {
|
|
|
|
|
|
|
|
handlePlayedCard: function(card) {
|
|
|
|
// console.log('Handling a card:');
|
|
|
|
// console.log(card);
|
|
|
|
// console.log(otc.played);
|
|
|
|
index = 0;
|
2022-09-15 08:55:19 +02:00
|
|
|
if(card.Shape >= 4) {
|
2022-09-15 03:13:05 +02:00
|
|
|
index = 1;
|
|
|
|
} else {
|
|
|
|
index = card.Value;
|
|
|
|
}
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.playedCards[index].push(card);
|
|
|
|
otc.totalPlayed.push(card);
|
2022-09-15 03:13:05 +02:00
|
|
|
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.playedCards[index].sort(function(c1, c2){
|
2022-09-15 03:13:05 +02:00
|
|
|
return c2.Shape - c1.Shape;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
handlePlayedCards: function(cards) {
|
|
|
|
if (cards.length > 0) {
|
|
|
|
contained = false;
|
|
|
|
// console.log(message.Table.TableCards[0].Shape);
|
|
|
|
// console.log(message.Table.TableCards[0].Value);
|
2022-09-15 19:54:02 +02:00
|
|
|
$(otc.totalPlayed).each(function (index, item) {
|
2022-09-15 03:13:05 +02:00
|
|
|
if (item.Shape == cards[0].Shape) {
|
|
|
|
if (item.Value == cards[0].Value) {
|
|
|
|
contained = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(!contained) {
|
|
|
|
$(message.Table.TableCards).each(
|
|
|
|
(index, card) => otc.action.handlePlayedCard(card)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resetPlayedCards: function() {
|
|
|
|
for(let i = 1; i < 15; i++) {
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.playedCards[i] = [];
|
2022-09-15 03:13:05 +02:00
|
|
|
}
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.totalPlayed = [];
|
2022-09-15 03:13:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
drawPlayedCards: function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
console.log('drawing played cards');
|
|
|
|
console.log(otc.playedCards);
|
|
|
|
console.log(otc.allCards);
|
2022-09-15 03:13:05 +02:00
|
|
|
for(let i = 1; i < 15; i++) {
|
2022-09-15 19:54:02 +02:00
|
|
|
cards = [];
|
|
|
|
for(let j=0; j < otc.allCards[i].length; j ++) {
|
|
|
|
if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i])) {
|
|
|
|
cards.push(otc.allCards[i][j]);
|
2022-09-15 03:13:05 +02:00
|
|
|
}
|
2022-09-15 19:54:02 +02:00
|
|
|
}
|
|
|
|
// cards = otc.allCards[i].filter(x => otc.util.cardInArray(x, otc.playedCards[i]));
|
|
|
|
console.log(cards);
|
|
|
|
otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards));
|
2022-09-15 03:13:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!window.otc) {
|
|
|
|
window.otc = OnlineTichuCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(let i = 1; i < 15; i++) {
|
|
|
|
otc.$playedCards[i] = $('#playedCards' + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
otc.action.resetPlayedCards();
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.util.populateAllCards();
|
2022-09-15 03:13:05 +02:00
|
|
|
|
|
|
|
MyTableState = (function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var cachedFunction = ot.reaction.TableState;
|
2022-09-15 03:13:05 +02:00
|
|
|
|
|
|
|
return function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var result = cachedFunction.apply(this, arguments);
|
2022-09-15 03:13:05 +02:00
|
|
|
|
|
|
|
message = arguments[0];
|
|
|
|
|
|
|
|
// console.log('detected table state change event');
|
|
|
|
console.log(message.Table.Status);
|
|
|
|
|
|
|
|
// reset played cards at start of round
|
|
|
|
if(message.Table.Status == 'WaitForNextCards') {
|
|
|
|
otc.action.resetPlayedCards();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(message.Table.Status == 'Playing') {
|
|
|
|
otc.action.handlePlayedCards(message.Table.TableCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
otc.action.drawPlayedCards();
|
|
|
|
|
|
|
|
// otc.$playedCardsQ.html(displayCardsHtmlString);
|
|
|
|
// $('.horizontalLayouta .card').css('margin-left', '-64px');
|
|
|
|
// $('#playedCards').css('margin-left', '32px');
|
|
|
|
// ot.HorizontalAlign(otc.$playedCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
})();
|
|
|
|
|
2022-09-15 08:55:19 +02:00
|
|
|
|
|
|
|
MyChat = (function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var cachedFunction = ot.reaction.Chat;
|
2022-09-15 08:55:19 +02:00
|
|
|
|
|
|
|
return function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var result = cachedFunction.apply(this, arguments);
|
2022-09-15 08:55:19 +02:00
|
|
|
|
|
|
|
message = arguments[0];
|
|
|
|
if (message.User.Username === "System") {
|
|
|
|
var messageArray = message.Text.replace(/</g, '<').replace(/>/g, '>').split(' ');
|
|
|
|
message.Text = messageArray.join(' ');
|
|
|
|
messageArray = message.Text.replace(/</g, '<').replace(/>/g, '>').split(' ');
|
|
|
|
|
|
|
|
for(var i in messageArray) {
|
|
|
|
if(messageArray[i] == "dogs") {
|
|
|
|
otc.action.handlePlayedCard({
|
|
|
|
"Shape": 5,
|
|
|
|
"Value": 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
MyExchangeCards = (function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var cachedFunction = ot.action.ExchangeCards;
|
2022-09-15 08:55:19 +02:00
|
|
|
|
|
|
|
return function() {
|
|
|
|
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.exchangedTo['west'] = {
|
2022-09-15 08:55:19 +02:00
|
|
|
Shape: ot.$westExchange.children('li:nth-child(1)').data('shape'),
|
|
|
|
Value: ot.$westExchange.children('li:nth-child(1)').data('value') };
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.exchangedTo['north'] = {
|
2022-09-15 08:55:19 +02:00
|
|
|
Shape: ot.$northExchange.children('li:nth-child(1)').data('shape'),
|
|
|
|
Value: ot.$northExchange.children('li:nth-child(1)').data('value') };
|
2022-09-15 19:54:02 +02:00
|
|
|
otc.exchangedTo['east'] = {
|
2022-09-15 08:55:19 +02:00
|
|
|
Shape: ot.$eastExchange.children('li:nth-child(1)').data('shape'),
|
|
|
|
Value: ot.$eastExchange.children('li:nth-child(1)').data('value') };
|
|
|
|
|
2022-09-15 19:54:02 +02:00
|
|
|
console.log(otc.exchangedTo);
|
2022-09-15 08:55:19 +02:00
|
|
|
|
2022-09-15 19:54:02 +02:00
|
|
|
var result = cachedFunction.apply(this, arguments);
|
2022-09-15 08:55:19 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
MyReviewExchange = (function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var cachedFunction = ot.reaction.ReviewExchange;
|
2022-09-15 08:55:19 +02:00
|
|
|
|
|
|
|
return function() {
|
2022-09-15 19:54:02 +02:00
|
|
|
var result = cachedFunction.apply(this, arguments);
|
2022-09-15 08:55:19 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2022-09-15 03:13:05 +02:00
|
|
|
ot.reaction.TableState = MyTableState;
|
2022-09-15 08:55:19 +02:00
|
|
|
ot.reaction.Chat = MyChat;
|
|
|
|
ot.action.ExchangeCards = MyExchangeCards;
|