Greasy Fork is available in English.

Chess.com Bot/Cheat

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

Verze ze dne 09. 03. 2023. Zobrazit nejnovější verzi.

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