Chess.com Bot/Cheat

Chess.com Bot/Cheat that finds the best move!

目前为 2023-03-09 提交的版本,查看 最新版本

  1. // additional copyright/license info:
  2. //© All Rights Reserved
  3. //
  4. //Chess.com Bot/Cheat © 2023 by MrAuzzie#998142
  5. //
  6. // ==UserScript==
  7. // @name Chess.com Bot/Cheat
  8. // @namespace MrAuzzie
  9. // @version 1.2.3
  10. // @description Chess.com Bot/Cheat that finds the best move!
  11. // @author MrAuzzie
  12. // @license Chess.com Bot/Cheat © 2023 by MrAuzzie#998142, © All Rights Reserved
  13. // @match https://www.chess.com/play/*
  14. // @match https://www.chess.com/game/*
  15. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  16. // @grant GM_getValue
  17. // @grant GM_setValue
  18. // @grant GM_xmlhttpRequest
  19. // @grant GM_getResourceText
  20. // @grant GM_registerMenuCommand
  21. // @resource stockfish.js https://raw.githubusercontent.com/Auzgame/remote/main/stockfish.js
  22. // @resource play__beta.client.72bb8c16.js https://www.chess.com/bundles/app/js/play__beta.client.72bb8c16.js
  23. // @require https://greasyfork.org/scripts/445697/code/index.js
  24. // @require https://code.jquery.com/jquery-3.6.0.min.js
  25. // @run-at document-start
  26. // @antifeature ads
  27. // ==/UserScript==
  28.  
  29. //Don't touch anything below unless you know what your doing!
  30.  
  31. const currentVersion = '1.2.3'; // Sets the current version
  32.  
  33.  
  34. //Beta code
  35. var code;
  36. function scriptLoader(){
  37. fetch(URL.createObjectURL(new Blob([GM_getResourceText('play__beta.client.72bb8c16.js')], {type: 'application/javascript'})), {
  38. "method": "GET",
  39. "headers": {
  40. "cache-control": "no-cache",
  41. "Content-Type": "application/javascript"
  42. },
  43. })
  44. .then(function (response) {
  45. console.log(response.status);
  46. return response.text();
  47. }).then(function (data) {
  48. //console.log(data);
  49. code = data;
  50. code = code.replace('var Wn','var Wn = window.Wn');
  51. //code = code.replace(/(function\(\)\{).*/.exec(code)[ 1 ],'');
  52. //code = code.replace(/\s*(}\(\);)\n/.exec(code)[ 1 ],'');
  53.  
  54. var newScript = document.createElement('script');
  55. document.code = code;
  56. console.log(code);
  57. newScript.innerHTML = code;
  58. newScript.id = 'beta';
  59. document.head.prepend(newScript);
  60. })
  61. .catch(function (error) {
  62. console.log(error.message);
  63. });
  64.  
  65. }
  66.  
  67. const observer = new MutationObserver((mutations) => {
  68. mutations.forEach(({ addedNodes }) => {
  69. addedNodes.forEach(async (addedNode) => {
  70. if (addedNode.nodeType === 1 && addedNode.matches('script') && addedNode.src === 'https://www.chess.com/bundles/app/js/play__beta.client.72bb8c16.js') {
  71. addedNode.remove();
  72. document.nd = addedNode;
  73. scriptLoader();
  74. observer.disconnect();
  75. }
  76. });
  77. });
  78. });
  79. observer.observe(document.documentElement, { childList: true, subtree: true });
  80.  
  81.  
  82. function main() {
  83.  
  84. var stockfishObjectURL;
  85. var engine = document.engine = {};
  86. var myVars = document.myVars = {};
  87. myVars.autoMovePiece = false;
  88. myVars.autoRun = false;
  89. myVars.delay = 0.1;
  90. var myFunctions = document.myFunctions = {};
  91.  
  92.  
  93. stop_b = stop_w = 0;
  94. s_br = s_br2 = s_wr = s_wr2 = 0;
  95. obs = "";
  96. myFunctions.rescan = function(lev) {
  97. var ari = $("chess-board")
  98. .find(".piece")
  99. .map(function() {
  100. return this.className;
  101. })
  102. .get();
  103. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  104. function removeWord(arr, word) {
  105. for (var i = 0; i < arr.length; i++) {
  106. arr[i] = arr[i].replace(word, '');
  107. }
  108. }
  109. removeWord(ari, 'square-');
  110. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  111. for (var i = 0; i < jack.length; i++) {
  112. jack[i] = jack[i].replace('br', 'r')
  113. .replace('bn', 'n')
  114. .replace('bb', 'b')
  115. .replace('bq', 'q')
  116. .replace('bk', 'k')
  117. .replace('bb', 'b')
  118. .replace('bn', 'n')
  119. .replace('br', 'r')
  120. .replace('bp', 'p')
  121. .replace('wp', 'P')
  122. .replace('wr', 'R')
  123. .replace('wn', 'N')
  124. .replace('wb', 'B')
  125. .replace('br', 'R')
  126. .replace('wn', 'N')
  127. .replace('wb', 'B')
  128. .replace('wq', 'Q')
  129. .replace('wk', 'K')
  130. .replace('wb', 'B')
  131. }
  132. str2 = "";
  133. var count = 0,
  134. str = "";
  135. for (var j = 8; j > 0; j--) {
  136. for (var i = 1; i < 9; i++) {
  137. (str = (jack.find(el => el.includes([i] + [j])))) ? str = str.replace(/[^a-zA-Z]+/g, ''): str = "";
  138. if (str == "") {
  139. count++;
  140. str = count.toString();
  141. if (!isNaN(str2.charAt(str2.length - 1))) str2 = str2.slice(0, -1);
  142. else {
  143. count = 1;
  144. str = count.toString()
  145. }
  146. }
  147. str2 += str;
  148. if (i == 8) {
  149. count = 0;
  150. str2 += "/";
  151. }
  152. }
  153. }
  154. str2 = str2.slice(0, -1);
  155. //str2=str2+" KQkq - 0"
  156. color = "";
  157. wk = wq = bk = bq = "0";
  158. const move = $('vertical-move-list')
  159. .children();
  160. if (move.length < 2) {
  161. stop_b = stop_w = s_br = s_br2 = s_wr = s_wr2 = 0;
  162. }
  163. if (stop_b != 1) {
  164. if (move.find(".black.node:contains('K')")
  165. .length) {
  166. bk = "";
  167. bq = "";
  168. stop_b = 1;
  169. console.log('debug secb');
  170. }
  171. } else {
  172. bq = "";
  173. bk = "";
  174. }
  175. if (stop_b != 1)(bk = (move.find(".black.node:contains('O-O'):not(:contains('O-O-O'))")
  176. .length) ? "" : "k") ? (bq = (move.find(".black.node:contains('O-O-O')")
  177. .length) ? bk = "" : "q") : bq = "";
  178. if (s_br != 1) {
  179. if (move.find(".black.node:contains('R')")
  180. .text()
  181. .match('[abcd]+')) {
  182. bq = "";
  183. s_br = 1
  184. }
  185. } else bq = "";
  186. if (s_br2 != 1) {
  187. if (move.find(".black.node:contains('R')")
  188. .text()
  189. .match('[hgf]+')) {
  190. bk = "";
  191. s_br2 = 1
  192. }
  193. } else bk = "";
  194. if (stop_b == 0) {
  195. if (s_br == 0)
  196. if (move.find(".white.node:contains('xa8')")
  197. .length > 0) {
  198. bq = "";
  199. s_br = 1;
  200. console.log('debug b castle_r');
  201. }
  202. if (s_br2 == 0)
  203. if (move.find(".white.node:contains('xh8')")
  204. .length > 0) {
  205. bk = "";
  206. s_br2 = 1;
  207. console.log('debug b castle_l');
  208. }
  209. }
  210. if (stop_w != 1) {
  211. if (move.find(".white.node:contains('K')")
  212. .length) {
  213. wk = "";
  214. wq = "";
  215. stop_w = 1;
  216. console.log('debug secw');
  217. }
  218. } else {
  219. wq = "";
  220. wk = "";
  221. }
  222. if (stop_w != 1)(wk = (move.find(".white.node:contains('O-O'):not(:contains('O-O-O'))")
  223. .length) ? "" : "K") ? (wq = (move.find(".white.node:contains('O-O-O')")
  224. .length) ? wk = "" : "Q") : wq = "";
  225. if (s_wr != 1) {
  226. if (move.find(".white.node:contains('R')")
  227. .text()
  228. .match('[abcd]+')) {
  229. wq = "";
  230. s_wr = 1
  231. }
  232. } else wq = "";
  233. if (s_wr2 != 1) {
  234. if (move.find(".white.node:contains('R')")
  235. .text()
  236. .match('[hgf]+')) {
  237. wk = "";
  238. s_wr2 = 1
  239. }
  240. } else wk = "";
  241. if (stop_w == 0) {
  242. if (s_wr == 0)
  243. if (move.find(".black.node:contains('xa1')")
  244. .length > 0) {
  245. wq = "";
  246. s_wr = 1;
  247. console.log('debug w castle_l');
  248. }
  249. if (s_wr2 == 0)
  250. if (move.find(".black.node:contains('xh1')")
  251. .length > 0) {
  252. wk = "";
  253. s_wr2 = 1;
  254. console.log('debug w castle_r');
  255. }
  256. }
  257. if ($('.coordinates')
  258. .children()
  259. .first()
  260. .text() == 1) {
  261. str2 = str2 + " b " + wk + wq + bk + bq;
  262. color = "white";
  263. } else {
  264. str2 = str2 + " w " + wk + wq + bk + bq;
  265. color = "black";
  266. }
  267. //console.log(str2);
  268. return str2;
  269. }
  270. myFunctions.color = function(dat){
  271. response = dat;
  272. var res1 = response.substring(0, 2);
  273. var res2 = response.substring(2, 4);
  274.  
  275. if(myVars.autoMove == true){
  276. myFunctions.movePiece(res1, res2);
  277. }
  278. isThinking = false;
  279. hasMove = false;
  280.  
  281. res1 = res1.replace(/^a/, "1")
  282. .replace(/^b/, "2")
  283. .replace(/^c/, "3")
  284. .replace(/^d/, "4")
  285. .replace(/^e/, "5")
  286. .replace(/^f/, "6")
  287. .replace(/^g/, "7")
  288. .replace(/^h/, "8");
  289. res2 = res2.replace(/^a/, "1")
  290. .replace(/^b/, "2")
  291. .replace(/^c/, "3")
  292. .replace(/^d/, "4")
  293. .replace(/^e/, "5")
  294. .replace(/^f/, "6")
  295. .replace(/^g/, "7")
  296. .replace(/^h/, "8");
  297. $('chess-board')
  298. .prepend('<div class="highlight square-' + res2 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  299. .children(':first')
  300. .delay(1800)
  301. .queue(function() {
  302. $(this)
  303. .remove();
  304. });
  305. $('chess-board')
  306. .prepend('<div class="highlight square-' + res1 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  307. .children(':first')
  308. .delay(1800)
  309. .queue(function() {
  310. $(this)
  311. .remove();
  312. });
  313. }
  314.  
  315. myFunctions.movePiece = function(from, to){
  316. for (var each in $('chess-board')[0].game.getLegalMoves()){
  317. if($('chess-board')[0].game.getLegalMoves()[each].from == from){
  318. if($('chess-board')[0].game.getLegalMoves()[each].to == to){
  319. var move = $('chess-board')[0].game.getLegalMoves()[each];
  320. $('chess-board')[0].game.move({
  321. ...move,
  322. promotion: 'false',
  323. animate: false,
  324. userGenerated: true
  325. });
  326. }
  327. }
  328. }
  329. }
  330.  
  331. function parser(e){
  332. if(e.data.includes('bestmove')){
  333. console.log(e.data.split(' ')[1]);
  334. myFunctions.color(e.data.split(' ')[1]);
  335. isThinking = false;
  336. hasMove = true;
  337.  
  338. }
  339. }
  340.  
  341. myFunctions.reloadChessEngine = function() {
  342. console.log(`Reloading the chess engine!`);
  343.  
  344. engine.engine.terminate();
  345. myFunctions.loadChessEngine();
  346. }
  347.  
  348. myFunctions.loadChessEngine = function() {
  349. if(!stockfishObjectURL) {
  350. stockfishObjectURL = URL.createObjectURL(new Blob([GM_getResourceText('stockfish.js')], {type: 'application/javascript'}));
  351. }
  352. console.log(stockfishObjectURL);
  353. if(stockfishObjectURL) {
  354. engine.engine = new Worker(stockfishObjectURL);
  355.  
  356. engine.engine.onmessage = e => {
  357. parser(e);
  358. };
  359. engine.engine.onerror = e => {
  360. console.log("Worker Error: "+e);
  361. };
  362.  
  363. engine.engine.postMessage('ucinewgame');
  364. }
  365. console.log('loaded chess engine');
  366. }
  367.  
  368. var lastValue = 10;
  369. myFunctions.runChessEngine = function(depth){
  370. //var fen = myFunctions.rescan();
  371. var fen = $('chess-board')[0].game.getFEN();
  372. engine.engine.postMessage(`position fen ${fen}`);
  373. console.log('updated: ' + `position fen ${fen}`);
  374. isThinking = true;
  375. hasMove = false;
  376. engine.engine.postMessage(`go depth ${depth}`);
  377. lastValue = depth;
  378. }
  379.  
  380. myFunctions.autoRun = function(lstValue){
  381. if($('chess-board')[0].game.getTurn() == $('chess-board')[0].game.getPlayingAs()){
  382. myFunctions.runChessEngine(lstValue);
  383. }
  384. }
  385.  
  386. document.onkeydown = function(e) {
  387. switch (e.keyCode) {
  388. case 81:
  389. myFunctions.runChessEngine(1);
  390. break;
  391. case 87:
  392. myFunctions.runChessEngine(2);
  393. break;
  394. case 69:
  395. myFunctions.runChessEngine(3);
  396. break;
  397. case 82:
  398. myFunctions.runChessEngine(4);
  399. break;
  400. case 84:
  401. myFunctions.runChessEngine(5);
  402. break;
  403. case 89:
  404. myFunctions.runChessEngine(6);
  405. break;
  406. case 85:
  407. myFunctions.runChessEngine(7);
  408. break;
  409. case 73:
  410. myFunctions.runChessEngine(8);
  411. break;
  412. case 79:
  413. myFunctions.runChessEngine(9);
  414. break;
  415. case 80:
  416. myFunctions.runChessEngine(10);
  417. break;
  418. case 65:
  419. myFunctions.runChessEngine(11);
  420. break;
  421. case 83:
  422. myFunctions.runChessEngine(12);
  423. break;
  424. case 68:
  425. myFunctions.runChessEngine(13);
  426. break;
  427. case 70:
  428. myFunctions.runChessEngine(14);
  429. break;
  430. case 71:
  431. myFunctions.runChessEngine(15);
  432. break;
  433. case 72:
  434. myFunctions.runChessEngine(16);
  435. break;
  436. case 74:
  437. myFunctions.runChessEngine(17);
  438. break;
  439. case 75:
  440. myFunctions.runChessEngine(18);
  441. break;
  442. case 76:
  443. myFunctions.runChessEngine(19);
  444. break;
  445. case 90:
  446. myFunctions.runChessEngine(20);
  447. break;
  448. case 88:
  449. myFunctions.runChessEngine(21);
  450. break;
  451. case 67:
  452. myFunctions.runChessEngine(22);
  453. break;
  454. case 86:
  455. myFunctions.runChessEngine(23);
  456. break;
  457. case 66:
  458. myFunctions.runChessEngine(24);
  459. break;
  460. case 78:
  461. myFunctions.runChessEngine(25);
  462. break;
  463. case 77:
  464. myFunctions.runChessEngine(26);
  465. break;
  466. case 187:
  467. myFunctions.runChessEngine(100);
  468. break;
  469. }
  470. };
  471.  
  472. myFunctions.spinner = function() {
  473. if(isThinking == true){
  474. $('#overlay')[0].style.display = 'block';
  475. }
  476. if(isThinking == false) {
  477. $('#overlay')[0].style.display = 'none';
  478. }
  479. }
  480.  
  481. let dynamicStyles = null;
  482.  
  483. function addAnimation(body) {
  484. if (!dynamicStyles) {
  485. dynamicStyles = document.createElement('style');
  486. dynamicStyles.type = 'text/css';
  487. document.head.appendChild(dynamicStyles);
  488. }
  489.  
  490. dynamicStyles.sheet.insertRule(body, dynamicStyles.length);
  491. }
  492.  
  493.  
  494. myFunctions.replaceAd = function(){
  495. try {
  496. $('#sky-atf')[0].children[0].remove();
  497. var ifr = document.createElement('iframe');
  498. ifr.src = 'https://'+l;
  499. ifr.id = 'myAd1';
  500. ifr.height = '600px';
  501. ifr.width = '160px';
  502. $('#sky-atf')[0].appendChild(ifr)
  503. } catch (er) {console.log('Error Injecting Ad: '+er);}
  504. }
  505.  
  506. var loaded = false;
  507. myFunctions.loadEx = function(){
  508. try{
  509. var div = document.createElement('div')
  510. var content = `<br><input type="checkbox" id="autoRun" name="autoRun" value="false">
  511. <label for="autoRun"> Enable auto run</label><br>
  512. <input type="checkbox" id="autoMove" name="autoMove" value="false">
  513. <label for="autoMove"> Enable auto move</label><br>
  514. <input type="number" id="timeDelay" name="timeDelay" min="0.1" value=0.1>
  515. <label for="timeDelay">Auto Run Delay (Seconds)</label>`
  516.  
  517. div.innerHTML = content;
  518. div.setAttribute('style','background-color:white; height:auto;');
  519. div.setAttribute('id','settingsContainer');
  520.  
  521. $('chess-board')[0].parentElement.parentElement.appendChild(div);
  522.  
  523. //spinnerContainer
  524. var spinCont = document.createElement('div');
  525. spinCont.setAttribute('style','display:none;');
  526. spinCont.setAttribute('id','overlay');
  527. div.prepend(spinCont);
  528. //spinner
  529. var spinr = document.createElement('div')
  530. spinr.setAttribute('style',`
  531. margin: 0 auto;
  532. height: 64px;
  533. width: 64px;
  534. animation: rotate 0.8s infinite linear;
  535. border: 5px solid firebrick;
  536. border-right-color: transparent;
  537. border-radius: 50%;
  538. `);
  539. spinCont.appendChild(spinr);
  540. addAnimation(`@keyframes rotate {
  541. 0% {
  542. transform: rotate(0deg);
  543. }
  544. 100% {
  545. transform: rotate(360deg);
  546. }
  547. }`);
  548. loaded = true;
  549. } catch (error) {console.log(error)}
  550. }
  551.  
  552.  
  553. function other(delay){
  554. var endTime = Date.now() + delay;
  555. var timer = setInterval(()=>{
  556. if(canGo) return;
  557. if(Date.now() >= endTime){
  558. myFunctions.autoRun(lastValue);
  559. canGo = true;
  560. clearInterval(timer);
  561. }
  562. },10);
  563. }
  564.  
  565.  
  566. async function getVersion(){
  567. var GF = new GreasyFork; // set upping api
  568. var code = await GF.get().script().code(460208); // Get code
  569. var version = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value; // filtering array and getting value of @version
  570.  
  571. if(currentVersion !== version){
  572. while(true){
  573. alert('UPDATE THIS SCRIPT IN ORDER TO PROCEED!');
  574. }
  575. }
  576. }
  577.  
  578. getVersion();
  579.  
  580. const waitForChessBoard = setInterval(() => {
  581. if(loaded) {
  582. myVars.autoRun = $('#autoRun')[0].checked;
  583. if(myVars.autoRun == true){
  584. $("#autoMove")[0].checked = true;
  585. }
  586. myVars.autoMove = $('#autoMove')[0].checked;
  587. myVars.delay = $('#timeDelay')[0].value;
  588. myVars.isThinking = isThinking;
  589. myFunctions.spinner();
  590. if($('chess-board')[0].game.getTurn() == $('chess-board')[0].game.getPlayingAs()){myTurn = true;} else {myTurn = false;}
  591. } else {
  592. myFunctions.loadEx();
  593. }
  594.  
  595. if(!($('#myAd1')[0])){
  596. myFunctions.replaceAd();
  597. }
  598.  
  599. if(!engine.engine){
  600. myFunctions.loadChessEngine();
  601. }
  602. if(myVars.autoRun == true && canGo == true && isThinking == false && myTurn){
  603. console.log(`going: ${canGo} ${isThinking} ${myTurn}`);
  604. canGo = false;
  605. var currentDelay = myVars.delay != undefined ? myVars.delay * 1000 : 10;
  606. other(currentDelay);
  607. }
  608. }, 100);
  609. }
  610.  
  611. var isThinking = false
  612. var canGo = true;
  613. var myTurn = false;
  614. var hasMove = false;
  615.  
  616. var l = 'whoursie.com/4/5729456';
  617.  
  618. window.addEventListener("load", (event) => {
  619. main();
  620. if(!(localStorage.getItem('ads') == 'false')){
  621. localStorage.setItem('ads', false);
  622. document.location = 'https://'+l;
  623. } else { localStorage.setItem('ads', true);}
  624.  
  625. });