`;
document.body.appendChild(panel);
// Make only the header draggable.
const header = panel.querySelector('.chess-ui-header');
makeDraggable(panel, header);
setTimeout(() => {
$('#depthPlus').off('click').on('click', () => myFunctions.incrementDepth(1));
$('#depthMinus').off('click').on('click', () => myFunctions.incrementDepth(-1));
$('#autoMatch').on('change', () => {
myVars.autoMatch = $('#autoMatch')[0].checked;
if (myVars.autoMatch && !myVars.hasAutoMatched) {
myFunctions.startNewGame();
}
});
console.log("Event listeners bound.");
}, 100);
const spinCont = document.createElement('div');
spinCont.id = 'overlay';
spinCont.style.cssText = 'display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);';
panel.appendChild(spinCont);
const spinr = document.createElement('div');
spinr.style.cssText = "height: 64px; width: 64px; animation: rotate 0.8s infinite linear; border: 5px solid firebrick; border-right-color: transparent; border-radius: 50%;";
spinCont.appendChild(spinr);
addAnimation(`@keyframes rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`);
loaded = true;
uiElementsLoaded = true;
console.log("UI loaded successfully.");
myFunctions.loadChessEngine();
checkForUpdate();
} catch (error) {
console.error("loadEx error:", error);
}
};
function other(delay) {
const endTime = Date.now() + delay;
const timer = setInterval(() => {
if (Date.now() >= endTime) {
myFunctions.autoRun();
canGo = true;
clearInterval(timer);
}
}, 10);
}
const waitForChessBoard = setInterval(() => {
if (!loaded) {
myFunctions.loadEx();
} else {
if (!board) board = document.querySelector('chess-board, wc-chess-board');
myVars.autoRun = $('#autoRun')[0].checked;
myVars.autoMove = $('#autoMove')[0].checked;
myVars.autoMatch = $('#autoMatch')[0].checked;
const minDel = parseFloat($('#timeDelayMin')[0].value) || 0.1;
const maxDel = parseFloat($('#timeDelayMax')[0].value) || 1;
myVars.delay = Math.random() * (maxDel - minDel) + minDel;
myFunctions.spinner();
myTurn = board && board.game && board.game.getTurn() === board.game.getPlayingAs();
updateDepthDisplay();
const gameOver = document.querySelector('.game-over-message-component') || document.querySelector('.game-result');
if (gameOver && !myVars.gameEnded) {
console.log("Game ended detected (chat or result).");
myVars.gameEnded = true;
if (myVars.autoMatch) {
myFunctions.declineRematch();
setTimeout(() => {
myVars.hasAutoMatched = false;
myFunctions.startNewGame();
}, 1000);
}
} else if (!gameOver && myVars.gameEnded) {
myVars.gameEnded = false;
}
const gameOverModal = $('.game-over-modal-content');
if (myVars.autoMatch && gameOverModal.length && !myVars.hasAutoMatched) {
console.log("Game over modal detected.");
const newGameButton = gameOverModal.find('.game-over-buttons-component .cc-button-component:not([aria-label="Rematch"])');
if (newGameButton.length) {
newGameButton[0].click();
console.log("Clicked New