onlinetichu-counter/onlinetichu-counter.js

760 lines
25 KiB
JavaScript
Raw Normal View History

// ==UserScript==
// @name onlinetichu.com card counter
2022-10-21 17:48:20 +02:00
// @version 1.3.2
// @description automatically count cards at onlinetichu.com
// @match *://*.onlinetichu.com/Site/Game/Table/*
2022-09-17 22:34:09 +02:00
// @author Maximilian Keßler
// @namespace https://gitlab.com/kesslermaximilian/onlinetichu-counter
// @license MIT
// ==/UserScript==
// disable auto fold functionality completely
2022-09-17 01:22:20 +02:00
function injectCounter() {
if (ot.AutoFold) {
ot.$autoFold.click()
ot.$autoFold.hide()
}
2022-09-17 01:22:20 +02:00
var myStyles = `
#playedHigh {
position: absolute;
top: 45px;
left: 5px;
width: 935px;
2022-09-17 01:22:20 +02:00
height: 120px;
}
2022-09-17 01:22:20 +02:00
#playedLow {
position: absolute;
top: 170px;
left: 5px;
width: 935px;
2022-09-17 01:22:20 +02:00
height: 120px;
}
#counterField {
position: absolute;
width: 945px;
height: 300px;
top: 635px;
border: 1px solid black;
box-shadow: 1px 1px 1px #555;
background: #88CC00;
}
#controlBar {
position: absolute;
min-height: 32px;
width: 925px;
top: 5px;
left: 5px;
border-radius: 20px;
background: #000000;
}
#controlButtonsLeft {
position: absolute;
top: 4px;
left: 15px;
}
#controlButtonsRight {
position: absolute;
top: 4px;
right: 15px;
}
2022-09-17 01:22:20 +02:00
.playedCardsLayout {
position: absolute;
height: 125px;
}
2022-09-17 01:22:20 +02:00
.playedCardsLayout .card {
width: 80px;
height: 120px;
border-radius: 5px;
float: left;
margin-left: -50px;
text-align: left;
2022-09-17 11:20:20 +02:00
box-shadow: 2px 2px 5px #555;
border: 1px solid #000000;
}
2022-09-17 01:22:20 +02:00
.playedCardsLayout .card:hover {
z-index: 1400;
}
`
var styleSheet = document.createElement("style")
styleSheet.innerText = myStyles;
console.log(styleSheet);
document.head.appendChild(styleSheet);
var controlBar = document.createElement('div');
controlBar.id = 'controlBar';
var controlButtonsLeft = document.createElement('div');
controlButtonsLeft.className = 'btn-group';
controlButtonsLeft.id = 'controlButtonsLeft';
var controlButtonsRight = document.createElement('div');
controlButtonsRight.className = 'btn-group';
controlButtonsRight.id = 'controlButtonsRight';
var davidProtectionButton = document.createElement('button');
davidProtectionButton.className = "btn btn-success btn-xs";
davidProtectionButton.id = "davidProtection";
davidProtectionButton.type = "button";
2022-09-18 00:03:01 +02:00
davidProtectionButton.innerHTML = 'David protection: <span id="davidProtectionValue" data-on="On" data-off="Off">Off</span>';
2022-09-18 10:16:32 +02:00
var autoWishButton = document.createElement('button');
autoWishButton.className = "btn btn-info btn-xs";
autoWishButton.id = "autoWish";
autoWishButton.type = "button";
autoWishButton.innerHTML = 'Auto Wish: <span id="autoWishValue" data-on="On" data-off="Off">Off</span>';
var showRemainingButton = document.createElement('button');
showRemainingButton.className = "btn btn-info btn-xs";
showRemainingButton.id = "showRemaining";
showRemainingButton.type = "button";
showRemainingButton.innerHTML = 'Show: <span id="showRemainingValue" data-on="Remaining" data-off="Played">Remaining</span>';
var showCountedCardsButton = document.createElement('button');
showCountedCardsButton.className = "btn btn-success btn-xs";
showCountedCardsButton.id = "showCountedCards";
showCountedCardsButton.type = "button";
showCountedCardsButton.innerHTML = 'Show cards: <span id="showCountedCardsValue" data-on="Yes" data-off="No">No</span>';
controlButtonsRight.appendChild(showRemainingButton);
controlButtonsRight.appendChild(showCountedCardsButton);
controlButtonsLeft.appendChild(davidProtectionButton);
2022-09-18 10:16:32 +02:00
controlButtonsLeft.appendChild(autoWishButton);
controlBar.appendChild(controlButtonsLeft);
controlBar.appendChild(controlButtonsRight);
var counterField = document.createElement("div");
counterField.id = 'counterField';
counterField.appendChild(controlBar);
2022-09-17 01:22:20 +02:00
// add an extra field where we will put down the played cards
var cardsField = document.createElement('div');
cardsField.id = 'cardsField';
cardsField.style.marginLeft = '25px';
var playedHigh = document.createElement('div');
playedHigh.id = 'playedHigh';
playedHigh.style.marginLeft = '25px';
playedHigh.className = 'row';
playedHigh.hidden = true;
var playedLow = document.createElement('div');
playedLow.id = 'playedLow';
playedLow.style.marginLeft = '25px';
playedLow.className = 'row';
playedLow.hidden = true;
counterField.appendChild(playedHigh);
counterField.appendChild(playedLow);
2022-09-17 01:22:20 +02:00
tableIG = document.getElementById('gameField').parentNode;
tableIG.appendChild(counterField);
2022-09-17 01:22:20 +02:00
var createCardPlace = function(value, shift, node) {
var playedCards = document.createElement('ul');
playedCards.id = 'playedCards' + value;
// playedCards.className = 'layoutPlayedCards list-unstyled col-lg-2';
// playedCards.className = 'playedCardsLayout list-unstyled';
playedCards.className = 'playedCardsLayout list-unstyled';
playedCards.style.width = '160px';
playedCards.style.marginLeft = '25px';
playedCards.style.left = shift*127 + 'px';
2022-09-17 01:22:20 +02:00
node.appendChild(playedCards);
}
2022-09-17 01:22:20 +02:00
createCardPlace(1, 0, document.getElementById('playedHigh'));
for(let i = 14; i > 8; i--) {
createCardPlace(i, 14 - i + 1, document.getElementById('playedHigh'));
}
2022-09-17 01:22:20 +02:00
for(let i = 8; i > 1; i--) {
createCardPlace(i, 8 - i, document.getElementById('playedLow'));
}
2022-09-15 19:54:02 +02:00
2022-09-17 01:22:20 +02:00
var smartFoldButton = document.createElement('button');
smartFoldButton.className = "btn btn-danger btn-xs";
smartFoldButton.id = "smartFold";
smartFoldButton.type = "button";
2022-09-18 10:26:51 +02:00
smartFoldButton.innerHTML = 'Smart fold: <span id="smartFoldValue" data-on="On" data-off="Off">On</span>';
2022-09-17 01:22:20 +02:00
var showCardCounterButton = document.createElement('button');
showCardCounterButton.className = "btn btn-primary btn-xs";
showCardCounterButton.id = "showCardCounter";
showCardCounterButton.type = "button";
showCardCounterButton.innerHTML = 'Card Counter: <span id="showCardCounterValue" data-on="On" data-off="Off">No</span>';
2022-09-17 01:22:20 +02:00
buttons = document.getElementById('statusButtons');
buttons.insertBefore(showCardCounterButton, document.getElementById('autoFold'));
2022-09-17 01:22:20 +02:00
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 = '';
playerTichuCoefficient = document.createElement('div');
playerTichuCoefficient.id = direction + 'PlayerTichuCoefficient';
playerTichuCoefficient.innerText = '';
playerDiv.insertBefore(playerTichuCoefficient, playerTichu);
2022-10-21 14:31:51 +02:00
playerDiv.insertBefore(playerMyLevel, playerTichu);
}
patchPlayerStats('south');
2022-10-21 14:31:51 +02:00
patchPlayerStats('north');
patchPlayerStats('east');
patchPlayerStats('west');
2022-09-17 01:22:20 +02:00
// playedCards.
// ot.$gameField.insertAfter(playedCards, ot.$gameField.lastChild);
// set up counting of played cards
var OnlineTichuCounter = {
$playedCards: {},
$smartFold: $('#smartFold'),
$smartFoldValue: $('#smartFoldValue'),
$showCardCounter: $('#showCardCounter'),
$showCardCounterValue: $('#showCardCounterValue'),
2022-09-17 01:22:20 +02:00
$showRemaining: $('#showRemaining'),
$showRemainingValue: $('#showRemainingValue'),
$showCountedCards: $('#showCountedCards'),
$showCountedCardsValue: $('#showCountedCardsValue'),
$davidProtection: $('#davidProtection'),
2022-09-18 10:16:32 +02:00
$autoWishValue: $('#autoWishValue'),
$autoWish: $('#autoWish'),
$davidProtectionValue: $('#davidProtectionValue'),
2022-09-17 01:22:20 +02:00
$playedHigh: $('#playedHigh'),
$playedLow: $('#playedLow'),
$counterField: $('#counterField'),
2022-10-21 14:31:51 +02:00
$playerMyLevel: {
'east': $('#eastPlayerMyLevel'),
'north': $('#northPlayerMyLevel'),
'west': $('#westPlayerMyLevel'),
'south': $('#southPlayerMyLevel'),
},
$playerTichuCoefficient: {
'east': $('#eastPlayerTichuCoefficient'),
'north': $('#northPlayerTichuCoefficient'),
'west': $('#westPlayerTichuCoefficient'),
'south': $('#southPlayerTichuCoefficient'),
},
2022-09-17 01:22:20 +02:00
2022-09-18 10:16:32 +02:00
// dynamic game state
2022-09-17 01:22:20 +02:00
allCards: {},
playedCards: {},
totalPlayed: [],
exchangedTo: {},
exchangedFrom: {},
2022-09-18 10:16:32 +02:00
handCardShuffle: [],
2022-10-21 14:31:51 +02:00
playerNames: {},
2022-09-18 10:16:32 +02:00
// config values, triggered with buttons
2022-09-17 01:22:20 +02:00
smartFold: true,
showCardCounter: false,
2022-09-17 01:22:20 +02:00
showRemaining: true,
showCountedCards: false,
davidProtection: false,
2022-09-18 10:16:32 +02:00
autoWish: false,
shuffleCards: true,
// dynamic feature state
davidProtectionTriggered: true,
2022-09-18 10:16:32 +02:00
bombAfterFold: null, // to implement
stats: {},
2022-09-17 01:22:20 +02:00
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>';
2022-09-15 19:54:02 +02:00
});
2022-09-17 01:22:20 +02:00
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 }, // mahjong
{ Shape: 5, Value: 0 }, // dog
{ Shape: 6, Value: 15}, // dragon
{ Shape: 7, Value: 14 } // phoenix
];
},
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;
}
2022-09-15 19:54:02 +02:00
}
2022-09-17 01:22:20 +02:00
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);
},
// 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');
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),
grandTichuSuccessful: otc.util.extractInt( c2[2].innerText),
tichuPercentage: otc.util.extractFloat( c2[3].innerText),
tichuCalled: otc.util.extractInt( c2[4].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)
};
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,
2022-10-21 14:31:51 +02:00
tichuCoefficient: (( (generalStats.grandTichuSuccessful - lostGrand) * 200 + (generalStats.tichuSuccessful - lostTichu) * 100 ) / generalStats.rounds).toFixed(1),
oneTwoCoefficient: (200 * generalStats.oneTwo / generalStats.rounds).toFixed(1)
}
var userStats = {
custom: customStats,
general: generalStats
}
otc.stats[user] = userStats ;
2022-10-21 14:31:51 +02:00
// console.log('Fetched stats of user ' + user);
// update stats shown at table
otc.action.updateDisplayStats();
});
2022-09-15 19:54:02 +02:00
}
},
2022-09-17 01:22:20 +02:00
action: {
2022-09-18 10:16:32 +02:00
selectAutoWish: function() {
if (otc.exchangedTo['east'] == null) {
return;
}
val = 0;
if (otc.exchangedTo['east'].Shape < 4 ) {
val = otc.exchangedTo['east'].Value;
} else if (otc.exchangedTo['east'].Shape == 5) {
val = 14; // wish for ace by default if we gave a dog to the right
}
button = document.getElementById("askCard_" + val);
button.click();
},
deSelectAutoWish: function() {
2022-09-18 12:11:27 +02:00
button = document.getElementById("askCard_0");
2022-09-18 10:16:32 +02:00
button.click();
},
2022-09-17 01:22:20 +02:00
handlePlayedCard: function(card) {
index = 0;
// special cards have Shapes 4,5,6,7. We group them at value 1
if(card.Shape >= 4) {
index = 1;
if (card.Shape == 7) {
// Treat phoenix as if it had value 14
// This is important for comparisons later
card.Value = 14;
}
} else {
index = card.Value;
}
2022-09-17 01:22:20 +02:00
otc.playedCards[index].push(card);
otc.totalPlayed.push(card);
2022-09-17 01:22:20 +02:00
otc.playedCards[index].sort(function(c1, c2){
return c2.Shape - c1.Shape;
});
},
2022-09-17 01:22:20 +02:00
handlePlayedCards: function(cards) {
if (cards.length === 0) {
return;
}
if (!otc.util.cardInArray(cards[0], otc.totalPlayed)) {
$(message.Table.TableCards).each(
(index, card) => otc.action.handlePlayedCard(card)
);
}
},
2022-09-18 10:16:32 +02:00
reset: function() {
2022-09-17 01:22:20 +02:00
for(let i = 1; i < 15; i++) {
otc.playedCards[i] = [];
}
2022-09-18 10:16:32 +02:00
dirs = ['east', 'north', 'west'];
for (i in dirs) {
2022-09-18 10:25:25 +02:00
otc.exchangedTo[dirs[i]] = null;
otc.exchangedFrom[dirs[i]] = null;
2022-09-18 10:16:32 +02:00
}
2022-09-17 01:22:20 +02:00
otc.totalPlayed = [];
2022-09-18 10:16:32 +02:00
otc.handCardShuffle = [];
otc.playerNames = {};
otc.stats = {};
2022-09-17 01:22:20 +02:00
},
drawPlayedCards: function() {
for(let i = 1; i < 15; i++) {
if (otc.showRemaining) {
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]);
}
otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards));
}
2022-09-17 01:22:20 +02:00
} else {
otc.$playedCards[i].html(otc.util.displayCardsHtmlString(otc.playedCards[i]));
}
}
2022-10-21 14:31:51 +02:00
},
updateDisplayStats: function() {
dirs = ['east', 'north', 'south', 'west'];
for(i in dirs) {
stats = otc.stats[otc.playerNames[dirs[i]]];
if (stats != undefined) {
t = 'L ' + stats.general.level + ' A ' + stats.custom.abandonmentRate + '%';
otc.$playerMyLevel[dirs[i]].text(t);
t = 'T ' + stats.custom.tichuCoefficient + ' O ' + stats.custom.oneTwoCoefficient;
otc.$playerTichuCoefficient[dirs[i]].text(t);
} else {
otc.$playerMyLevel[dirs[i]].text('');
otc.$playerTichuCoefficient[dirs[i]].text('');
2022-10-21 14:31:51 +02:00
}
}
2022-10-21 17:48:20 +02:00
// console.log('updated shown stats');
}
}
}
2022-09-17 01:22:20 +02:00
if (!window.otc) {
window.otc = OnlineTichuCounter;
}
otc.$counterField.hide();
2022-09-17 01:22:20 +02:00
// add functionality to smartFold button
otc.$smartFold.click(function () {
otc.smartFold = !otc.smartFold;
if (otc.smartFold) {
otc.$smartFoldValue.text(otc.$smartFoldValue.data('on'));
} else {
otc.$smartFoldValue.text(otc.$smartFoldValue.data('off'));
}
});
// add functionality to show button
otc.$showCardCounter.click(function () {
otc.showCardCounter = !otc.showCardCounter;
if (otc.showCardCounter) {
otc.$showCardCounterValue.text(otc.$showCardCounterValue.data('on'));
otc.$counterField.show();
} else {
otc.$showCardCounterValue.text(otc.$showCardCounterValue.data('off'));
otc.$counterField.hide();
}
});
otc.$showCountedCards.click(function () {
otc.showCountedCards = !otc.showCountedCards;
if (otc.showCountedCards) {
otc.$showCountedCardsValue.text(otc.$showCountedCardsValue.data('on'));
2022-09-17 01:22:20 +02:00
otc.$playedHigh.show();
otc.$playedLow.show();
} else {
otc.$showCountedCardsValue.text(otc.$showCountedCardsValue.data('off'));
2022-09-17 01:22:20 +02:00
otc.$playedHigh.hide();
otc.$playedLow.hide();
}
});
otc.$davidProtection.click(function () {
otc.davidProtection = !otc.davidProtection;
if (otc.davidProtection) {
otc.$davidProtectionValue.text(otc.$davidProtectionValue.data('on'));
} else {
otc.$davidProtectionValue.text(otc.$davidProtectionValue.data('off'));
2022-09-17 01:22:20 +02:00
}
});
2022-09-18 10:16:32 +02:00
otc.$autoWish.click(function () {
otc.autoWish = !otc.autoWish;
if (otc.autoWish) {
otc.$autoWishValue.text(otc.$autoWishValue.data('on'));
otc.action.selectAutoWish();
} else {
otc.$autoWishValue.text(otc.$autoWishValue.data('off'));
otc.action.deSelectAutoWish();
}
});
2022-09-17 01:22:20 +02:00
otc.$showRemaining.click(function () {
otc.showRemaining = !otc.showRemaining;
if (otc.showRemaining) {
otc.$showRemainingValue.text(otc.$showRemainingValue.data('on'));
} else {
otc.$showRemainingValue.text(otc.$showRemainingValue.data('off'));
}
otc.action.drawPlayedCards();
});
2022-09-17 01:22:20 +02:00
for(let i = 1; i < 15; i++) {
otc.$playedCards[i] = $('#playedCards' + i);
}
2022-09-18 10:16:32 +02:00
otc.action.reset();
2022-09-17 01:22:20 +02:00
otc.util.populateAllCards();
// overwrite functionality of fold button
ot.$fold.unbind();
2022-09-17 22:30:53 +02:00
ot.$fold.hide().click(function () {
if (otc.davidProtection) {
2022-09-18 00:03:01 +02:00
if(ot.$passCards().length != 0 && !otc.davidProtectionTriggered) {
console.log('david protection triggered');
ot.$gameMessage.text("Selected cards detected. Press again to fold!");
ot.HorizontalAlign(ot.$gameMessage);
otc.davidProtectionTriggered = true;
return;
}
}
2022-09-17 22:30:53 +02:00
ot.action.Fold();
otc.davidProtectionTriggered = false;
$(this).hide();
});
2022-09-17 01:22:20 +02:00
MyTableState = (function() {
var cachedFunction = ot.reaction.TableState;
2022-09-17 01:22:20 +02:00
return function() {
var result = cachedFunction.apply(this, arguments);
2022-09-17 01:22:20 +02:00
message = arguments[0];
// console.log(message);
2022-09-17 01:22:20 +02:00
// console.log('detected table state change event');
2022-10-21 17:48:20 +02:00
// console.log(message.Table.Players);
2022-09-17 01:22:20 +02:00
// reset played cards at start of round
2022-09-18 10:16:32 +02:00
if(message.Table.Status == 'WaitForNextCards' && otc.totalPlayed.length != 0) {
otc.action.reset();
2022-09-17 01:22:20 +02:00
}
2022-09-17 01:22:20 +02:00
if(message.Table.Status == 'Playing') {
otc.action.handlePlayedCards(message.Table.TableCards);
}
otc.action.drawPlayedCards();
2022-09-17 22:30:53 +02:00
// console.log('reached smartFold point');
2022-10-21 14:31:51 +02:00
spectator = true;
// reset player names as they might have changed
otc.playerNames = {};
southPosition = 1;
2022-09-17 01:22:20 +02:00
$(message.Table.Players).each(function () {
if (this.Username == ot.$Username.val()) {
2022-10-21 14:31:51 +02:00
spectator = false;
southPosition = this.Position;
2022-09-17 22:30:53 +02:00
// console.log('found player');
2022-09-17 01:22:20 +02:00
if (message.Table.Turn == this.Position) {
2022-09-17 22:30:53 +02:00
// console.log('my turn!');
2022-09-17 01:22:20 +02:00
if (this.Cards.length < 4 && this.Cards.length < message.Table.TableCards.length) {
if (otc.smartFold) {
2022-10-15 21:07:56 +02:00
if(this.MustFold) {
ot.action.Fold();
2022-10-21 10:13:58 +02:00
console.log('smart fold activated');
2022-10-15 21:07:56 +02:00
} else {
console.log('prevented bug by not smartfolding');
}
2022-09-17 01:22:20 +02:00
}
}
}
}
2022-10-21 14:31:51 +02:00
// get stats of player if we don't have them yet)
if (otc.stats[this.Username] === undefined) {
otc.util.getStats(this.Username);
}
2022-09-17 01:22:20 +02:00
});
$(message.Table.Players).each(function () {
dirs = ['south', 'east', 'north', 'west'];
index = (this.Position - southPosition + 4) % 4;
otc.playerNames[dirs[index]] = this.Username;
});
2022-10-21 14:31:51 +02:00
otc.action.updateDisplayStats();
2022-09-17 01:22:20 +02:00
return result;
}
2022-09-17 01:22:20 +02:00
})();
2022-09-17 01:22:20 +02:00
MyChat = (function() {
var cachedFunction = ot.reaction.Chat;
2022-09-17 01:22:20 +02:00
return function() {
var result = cachedFunction.apply(this, arguments);
2022-09-17 01:22:20 +02:00
message = arguments[0];
if (message.User.Username === "System") {
var messageArray = message.Text.replace(/</g, '&lt;').replace(/>/g, '&gt;').split(' ');
message.Text = messageArray.join(' ');
messageArray = message.Text.replace(/</g, '&lt;').replace(/>/g, '&gt;').split(' ');
for(var i in messageArray) {
if(messageArray[i] == "dogs") {
otc.action.handlePlayedCard({
"Shape": 5,
"Value": 0
});
}
}
}
2022-09-17 01:22:20 +02:00
return result;
}
})();
2022-09-17 01:22:20 +02:00
MyExchangeCards = (function() {
var cachedFunction = ot.action.ExchangeCards;
2022-09-17 01:22:20 +02:00
return function() {
2022-09-17 01:22:20 +02:00
otc.exchangedTo['west'] = {
Shape: ot.$westExchange.children('li:nth-child(1)').data('shape'),
Value: ot.$westExchange.children('li:nth-child(1)').data('value') };
otc.exchangedTo['north'] = {
Shape: ot.$northExchange.children('li:nth-child(1)').data('shape'),
Value: ot.$northExchange.children('li:nth-child(1)').data('value') };
otc.exchangedTo['east'] = {
Shape: ot.$eastExchange.children('li:nth-child(1)').data('shape'),
Value: ot.$eastExchange.children('li:nth-child(1)').data('value') };
2022-09-17 01:22:20 +02:00
console.log(otc.exchangedTo);
2022-09-18 10:16:32 +02:00
if(otc.autoWish) {
otc.action.selectAutoWish();
} else {
otc.action.deSelectAutoWish();
}
2022-09-17 01:22:20 +02:00
var result = cachedFunction.apply(this, arguments);
return result;
}
})();
2022-09-17 01:22:20 +02:00
MyReviewExchange = (function() {
var cachedFunction = ot.reaction.ReviewExchange;
2022-09-17 01:22:20 +02:00
return function() {
var result = cachedFunction.apply(this, arguments);
return result;
}
})();
ot.reaction.TableState = MyTableState;
ot.reaction.Chat = MyChat;
ot.action.ExchangeCards = MyExchangeCards;
};
2022-10-15 19:10:44 +02:00
// Special care is to be taken to safely inject our javascript into the website
2022-09-17 01:22:20 +02:00
// without the website being able to talk back to greasemonkey
// (which would be a security problem)
// see
// https://stackoverflow.com/questions/5006460/userscripts-greasemonkey-calling-a-websites-javascript-functions
// and the excellent answer by Wayne for details on this
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); // run the script
document.body.removeChild(script); // clean up
}
2022-09-17 01:22:20 +02:00
exec(injectCounter);