From 45ee7214c18a7c5756f6ce3be6dc17f728fc1ede Mon Sep 17 00:00:00 2001 From: Haka <76921756+Hakorr@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:03:42 +0300 Subject: [PATCH] Fix chess.com variants --- acas.user.js | 53 ++++++---------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) diff --git a/acas.user.js b/acas.user.js index 5f3df7b..ed44a59 100644 --- a/acas.user.js +++ b/acas.user.js @@ -296,7 +296,6 @@ Object.values(configKeys).forEach(key => { let BoardDrawer = null; let chessBoardElem = null; -let chesscomVariantBoardCoordsTable = null; let chesscomVariantPlayerColorsTable = null; let activeSiteMoveHighlights = []; let inactiveGuiMoveMarkings = []; @@ -716,35 +715,6 @@ function getElemCoordinatesFromLeftTopPixels(elem) { } } -function updateChesscomVariantBoardCoordsTable() { - chesscomVariantBoardCoordsTable = {}; - - const boardElem = getBoardElem(); - const [boardWidth, boardHeight] = getBoardDimensions(); - const boardOrientation = getBoardOrientation(); - - const squareElems = getSquareElems(boardElem); - - let squareIndex = 0; - - for(let x = 0; x < boardWidth; x++) { - for(let y = boardHeight; y > 0; y--) { - const squareElem = squareElems[squareIndex]; - const id = squareElem?.dataset?.theme; - - if(id) { - if(boardOrientation === 'b') { - chesscomVariantBoardCoordsTable[id] = [boardWidth - (x + 1), boardHeight - y]; - } else { - chesscomVariantBoardCoordsTable[id] = [x, y - 1]; - } - } - - squareIndex++; - } - } -} - function updateChesscomVariantPlayerColorsTable() { let colors = []; @@ -1323,6 +1293,10 @@ addSupportedChessSite('chess.com', { pieceColor = chesscomVariantPlayerColorsTable[pieceElem?.dataset?.color]; pieceName = pieceElem?.dataset?.piece; + + if(pieceName?.length > 1) { + pieceName = pieceName[0]; + } } else { const pieceStr = [...pieceElem.classList].find(x => x.match(/^(b|w)[prnbqk]{1}$/)); @@ -1337,18 +1311,7 @@ addSupportedChessSite('chess.com', { const pieceElem = obj.pieceElem; if(pathname?.includes('/variants')) { - if(!chesscomVariantBoardCoordsTable) { - updateChesscomVariantBoardCoordsTable(); - } - - const pieceBoundary = pieceElem.getBoundingClientRect(); - const elementsBehindPieceElem = document.elementsFromPoint(pieceBoundary.x, pieceBoundary.y); - - const squareElem = elementsBehindPieceElem?.find(x => x?.classList?.contains('square')); - - //console.log(squareElem?.dataset?.theme, chesscomVariantBoardCoordsTable[squareElem?.dataset?.theme]); - - const coords = chesscomVariantBoardCoordsTable[squareElem?.dataset?.theme]; + const coords = getElemCoordinatesFromTransform(pieceElem); return coords; } @@ -1380,8 +1343,6 @@ addSupportedChessSite('chess.com', { } }); - //console.log([ranks, files]); - return [ranks, files]; } else { return [8, 8]; @@ -2585,8 +2546,6 @@ addSupportedChessSite('chessfriends.com', { 'pieceElemCoords': obj => { const pieceElem = obj.pieceElem; - //console.log(getElemCoordinatesFromLeftTopPixels(pieceElem)); - return getElemCoordinatesFromLeftTopPixels(pieceElem); }, @@ -2746,4 +2705,4 @@ if(typeof GM_registerMenuCommand === 'function') { } } -setInterval(initializeIfSiteReady, 1000); +setInterval(initializeIfSiteReady, 1000); \ No newline at end of file