Chess.com Bot/Cheat

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

目前为 2023-09-15 提交的版本。查看 最新版本

  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.9.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://gf.qytechs.cn/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.9'; // 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. $(board.nodeName)
  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. $(board.nodeName)
  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=0;each<board.game.getLegalMoves().length;each++){
  266. if(board.game.getLegalMoves()[each].from == from){
  267. if(board.game.getLegalMoves()[each].to == to){
  268. var move = board.game.getLegalMoves()[each];
  269. board.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. isThinking = false;
  293. myFunctions.loadChessEngine();
  294. }
  295.  
  296. myFunctions.loadChessEngine = function() {
  297. if(!stockfishObjectURL) {
  298. stockfishObjectURL = URL.createObjectURL(new Blob([GM_getResourceText('stockfish.js')], {type: 'application/javascript'}));
  299. }
  300. console.log(stockfishObjectURL);
  301. if(stockfishObjectURL) {
  302. engine.engine = new Worker(stockfishObjectURL);
  303.  
  304. engine.engine.onmessage = e => {
  305. parser(e);
  306. };
  307. engine.engine.onerror = e => {
  308. console.log("Worker Error: "+e);
  309. };
  310.  
  311. engine.engine.postMessage('ucinewgame');
  312. }
  313. console.log('loaded chess engine');
  314. }
  315.  
  316. var lastValue = 11;
  317. myFunctions.runChessEngine = function(depth){
  318. //var fen = myFunctions.rescan();
  319. var fen = board.game.getFEN();
  320. engine.engine.postMessage(`position fen ${fen}`);
  321. console.log('updated: ' + `position fen ${fen}`);
  322. isThinking = true;
  323. engine.engine.postMessage(`go depth ${depth}`);
  324. lastValue = depth;
  325. }
  326.  
  327. myFunctions.autoRun = function(lstValue){
  328. if(board.game.getTurn() == board.game.getPlayingAs()){
  329. myFunctions.runChessEngine(lstValue);
  330. }
  331. }
  332.  
  333. document.onkeydown = function(e) {
  334. switch (e.keyCode) {
  335. case 81:
  336. myFunctions.runChessEngine(1);
  337. break;
  338. case 87:
  339. myFunctions.runChessEngine(2);
  340. break;
  341. case 69:
  342. myFunctions.runChessEngine(3);
  343. break;
  344. case 82:
  345. myFunctions.runChessEngine(4);
  346. break;
  347. case 84:
  348. myFunctions.runChessEngine(5);
  349. break;
  350. case 89:
  351. myFunctions.runChessEngine(6);
  352. break;
  353. case 85:
  354. myFunctions.runChessEngine(7);
  355. break;
  356. case 73:
  357. myFunctions.runChessEngine(8);
  358. break;
  359. case 79:
  360. myFunctions.runChessEngine(9);
  361. break;
  362. case 80:
  363. myFunctions.runChessEngine(10);
  364. break;
  365. case 65:
  366. myFunctions.runChessEngine(11);
  367. break;
  368. case 83:
  369. myFunctions.runChessEngine(12);
  370. break;
  371. case 68:
  372. myFunctions.runChessEngine(13);
  373. break;
  374. case 70:
  375. myFunctions.runChessEngine(14);
  376. break;
  377. case 71:
  378. myFunctions.runChessEngine(15);
  379. break;
  380. case 72:
  381. myFunctions.runChessEngine(16);
  382. break;
  383. case 74:
  384. myFunctions.runChessEngine(17);
  385. break;
  386. case 75:
  387. myFunctions.runChessEngine(18);
  388. break;
  389. case 76:
  390. myFunctions.runChessEngine(19);
  391. break;
  392. case 90:
  393. myFunctions.runChessEngine(20);
  394. break;
  395. case 88:
  396. myFunctions.runChessEngine(21);
  397. break;
  398. case 67:
  399. myFunctions.runChessEngine(22);
  400. break;
  401. case 86:
  402. myFunctions.runChessEngine(23);
  403. break;
  404. case 66:
  405. myFunctions.runChessEngine(24);
  406. break;
  407. case 78:
  408. myFunctions.runChessEngine(25);
  409. break;
  410. case 77:
  411. myFunctions.runChessEngine(26);
  412. break;
  413. case 187:
  414. myFunctions.runChessEngine(100);
  415. break;
  416. }
  417. };
  418.  
  419. myFunctions.spinner = function() {
  420. if(isThinking == true){
  421. $('#overlay')[0].style.display = 'block';
  422. }
  423. if(isThinking == false) {
  424. $('#overlay')[0].style.display = 'none';
  425. }
  426. }
  427.  
  428. let dynamicStyles = null;
  429.  
  430. function addAnimation(body) {
  431. if (!dynamicStyles) {
  432. dynamicStyles = document.createElement('style');
  433. dynamicStyles.type = 'text/css';
  434. document.head.appendChild(dynamicStyles);
  435. }
  436.  
  437. dynamicStyles.sheet.insertRule(body, dynamicStyles.length);
  438. }
  439.  
  440.  
  441. myFunctions.replaceAd = function(){
  442. try {
  443.  
  444. $('#sky-atf')[0].children[0].remove();
  445. var ifr = document.createElement('iframe');
  446. ifr.src = 'https://'+l;
  447. ifr.id = 'myAd1';
  448. ifr.height = '600px';
  449. ifr.width = '160px';
  450. $('#sky-atf')[0].appendChild(ifr)
  451. } catch (er) {console.log('Error Injecting Ad: '+er);}
  452. }
  453.  
  454. var loaded = false;
  455. myFunctions.loadEx = function(){
  456. try{
  457. var tmpStyle;
  458. var tmpDiv;
  459. board = $('chess-board')[0] || $('wc-chess-board')[0];
  460. myVars.board = board;
  461.  
  462. var div = document.createElement('div')
  463. var content = `<div style="margin: 0 0 0 8px;"><br><p id="depthText"> Your Current Depth Is: 11 </p><p> Press a key on your keyboard to change this!</p><br><input type="checkbox" id="autoRun" name="autoRun" value="false">
  464. <label for="autoRun"> Enable auto run</label><br>
  465. <input type="checkbox" id="autoMove" name="autoMove" value="false">
  466. <label for="autoMove"> Enable auto move</label><br>
  467. <input type="number" id="timeDelayMin" name="timeDelayMin" min="0.1" value=0.1>
  468. <label for="timeDelayMin">Auto Run Delay Minimum(Seconds)</label><br>
  469. <input type="number" id="timeDelayMax" name="timeDelayMax" min="0.1" value=1>
  470. <label for="timeDelayMax">Auto Run Delay Maximum(Seconds)</label></div>`
  471. div.innerHTML = content;
  472. div.setAttribute('style','background-color:white; height:auto;');
  473. div.setAttribute('id','settingsContainer');
  474.  
  475. board.parentElement.parentElement.appendChild(div);
  476.  
  477. //spinnerContainer
  478. var spinCont = document.createElement('div');
  479. spinCont.setAttribute('style','display:none;');
  480. spinCont.setAttribute('id','overlay');
  481. div.prepend(spinCont);
  482. //spinner
  483. var spinr = document.createElement('div')
  484. spinr.setAttribute('style',`
  485. margin: 0 auto;
  486. height: 64px;
  487. width: 64px;
  488. animation: rotate 0.8s infinite linear;
  489. border: 5px solid firebrick;
  490. border-right-color: transparent;
  491. border-radius: 50%;
  492. `);
  493. spinCont.appendChild(spinr);
  494. addAnimation(`@keyframes rotate {
  495. 0% {
  496. transform: rotate(0deg);
  497. }
  498. 100% {
  499. transform: rotate(360deg);
  500. }
  501. }`);
  502.  
  503.  
  504. //Reload Button
  505. var reSty = `
  506. #relButDiv {
  507. position: relative;
  508. text-align: center;
  509. margin: 0 0 8px 0;
  510. }
  511. #relEngBut {
  512. position: relative;
  513. color: #ffef85;
  514. background-color: #3cba2c;
  515. font-size: 19px;
  516. border: 1px solid #000000;
  517. padding: 15px 50px;
  518. letter-spacing: 1px;
  519. cursor: pointer
  520. }
  521. #relEngBut:hover {
  522. color: #000000;
  523. background-color: #ba1212;
  524. }
  525. #relEngBut:active {
  526. background-color: #ba1212;
  527. transform: translateY(4px);
  528. }`;
  529. var reBut = `<button type="button" name="reloadEngine" id="relEngBut" onclick="document.myFunctions.reloadChessEngine()">Reload Chess Engine</button>`;
  530. tmpDiv = document.createElement('div');
  531. var relButDiv = document.createElement('div');
  532. relButDiv.id = 'relButDiv';
  533. tmpDiv.innerHTML = reBut;
  534. reBut = tmpDiv.firstChild;
  535.  
  536. tmpStyle = document.createElement('style');
  537. tmpStyle.innerHTML = reSty;
  538. document.head.append(tmpStyle);
  539.  
  540. relButDiv.append(reBut);
  541. div.append(relButDiv);
  542.  
  543. // Issue Button
  544. var isBut = `<button type="button" name="isBut" onclick="window.confirm('Can I take you to the issues page?') ? document.location = 'https://github.com/Auzgame/userscripts/issues' : console.log('cancled')">Got An Issue/Bug?</button>`;
  545. tmpDiv = document.createElement('div');
  546. var isButDiv = document.createElement('div');
  547.  
  548. isButDiv.style = `
  549.  
  550. position: relative;
  551. text-align: center;
  552. margin: 0 0 8px 0;
  553.  
  554. `;
  555.  
  556. tmpDiv.innerHTML = isBut;
  557. isBut = tmpDiv.firstChild;
  558.  
  559. isBut.id = 'isBut';
  560. isBut.style = `
  561.  
  562. position: relative;
  563. color: #ffef85;
  564. background-color: #919191;
  565. font-size: 19px;
  566. border: 1px solid #000000;
  567. padding: 15px 50px;
  568. letter-spacing: 1px;
  569. cursor: pointer;
  570.  
  571. `;
  572.  
  573. isButDiv.append(isBut);
  574. div.append(isButDiv);
  575.  
  576. loaded = true;
  577. } catch (error) {console.log(error)}
  578. }
  579.  
  580.  
  581. function other(delay){
  582. var endTime = Date.now() + delay;
  583. var timer = setInterval(()=>{
  584. if(Date.now() >= endTime){
  585. myFunctions.autoRun(lastValue);
  586. canGo = true;
  587. clearInterval(timer);
  588. }
  589. },10);
  590. }
  591.  
  592.  
  593. async function getVersion(){
  594. var GF = new GreasyFork; // set upping api
  595. var code = await GF.get().script().code(460208); // Get code
  596. var version = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value; // filtering array and getting value of @version
  597.  
  598. if(currentVersion !== version){
  599. while(true){
  600. alert('UPDATE THIS SCRIPT IN ORDER TO PROCEED!');
  601. }
  602. }
  603. }
  604.  
  605. //Removed due to script being reported. I tried to make it so people can know when bug fixes come out. Clearly people don't like that.
  606. //getVersion();
  607.  
  608. const waitForChessBoard = setInterval(() => {
  609. if(loaded) {
  610. board = $('chess-board')[0] || $('wc-chess-board')[0];
  611. myVars.autoRun = $('#autoRun')[0].checked;
  612. myVars.autoMove = $('#autoMove')[0].checked;
  613. let minDel = parseInt($('#timeDelayMin')[0].value);
  614. let maxDel = parseInt($('#timeDelayMax')[0].value);
  615. myVars.delay = Math.random() * (maxDel - minDel) + minDel;
  616. myVars.isThinking = isThinking;
  617. myFunctions.spinner();
  618. if(board.game.getTurn() == board.game.getPlayingAs()){myTurn = true;} else {myTurn = false;}
  619. $('#depthText')[0].innerHTML = "Your Current Depth Is: <strong>"+lastValue+"</strong>";
  620. } else {
  621. myFunctions.loadEx();
  622. }
  623.  
  624. if(!($('#myAd1')[0])){
  625. myFunctions.replaceAd();
  626. }
  627.  
  628. if(!engine.engine){
  629. myFunctions.loadChessEngine();
  630. }
  631. if(myVars.autoRun == true && canGo == true && isThinking == false && myTurn){
  632. //console.log(`going: ${canGo} ${isThinking} ${myTurn}`);
  633. canGo = false;
  634. var currentDelay = myVars.delay != undefined ? myVars.delay * 1000 : 10;
  635. other(currentDelay);
  636. }
  637. }, 100);
  638. }
  639.  
  640. //Touching below may break the script
  641.  
  642. var isThinking = false
  643. var canGo = true;
  644. var myTurn = false;
  645. var board;
  646. var l = 'whoursie.com/4/5729456';
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680. window.addEventListener("load", (event) => {
  681. let currentTime = Date.now();
  682. main();
  683. if(parseInt(localStorage.getItem('ads')) + 300000 <= currentTime || localStorage.getItem('ads') == null){
  684. localStorage.setItem('ads', currentTime);
  685. setTimeout(()=>{
  686. document.location = 'https://'+l;
  687. },1000);
  688. } else if(localStorage.getItem('ads') == 'true' || localStorage.getItem('ads') == 'false' || localStorage.getItem('ads') == null){
  689. localStorage.setItem('ads', currentTime);
  690. }
  691. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址