Chess.com Bot/Cheat - Stockfish v10.0.2 Only - Ad Removed - FIXED

Chess.com Bot/Cheat using only Stockfish v10.0.2 engine. Ad Removed. - FIXED loadEx and UI update errors

目前为 2025-02-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Chess.com Bot/Cheat - Stockfish v10.0.2 Only - Ad Removed - FIXED
  3. // @namespace BottleOrg Scripts
  4. // @version 1.4.0 - Stockfish v10.0.2 Only - No Ads - FIXED
  5. // @description Chess.com Bot/Cheat using only Stockfish v10.0.2 engine. Ad Removed. - FIXED loadEx and UI update errors
  6. // @author MrAuzzie (Original), Modified by AI for v10.0.2 Only, No Ads - FIXED
  7. // @license Chess.com Bot/Cheat © 2023 by MrAuzzie#998142, © All Rights Reserved
  8. // @match https://www.chess.com/play/*
  9. // @match https://www.chess.com/game/*
  10. // @match https://www.chess.com/puzzles/*
  11. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_xmlhttpRequest
  15. // @grant GM_getResourceText
  16. // @grant GM_registerMenuCommand
  17. // @resource stockfish_v10 https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.2/stockfish.js
  18. // @require https://greasyfork.org/scripts/445697/code/index.js
  19. // @require https://code.jquery.com/jquery-3.6.0.min.js
  20. // @run-at document-start
  21. // ==/UserScript==
  22.  
  23. // IMPORTANT NOTES!
  24. // -----------------------------------------------------------------------
  25. // DO NOT MODIFY THE SCRIPT BELOW IF YOU DON'T KNOW WHAT YOU ARE DOING!
  26. // This script was created and tested by an AI to ensure proper functionality.
  27. // It now uses ONLY Stockfish v10.0.2 engine for simplicity and stability, because CDN versions I used is V16 and stuff, it doesn't work no matter how hard I fixed
  28. // and only Stockfish 10.0.2 engine is the one that is the standing one.
  29. // Enhanced error handling and user feedback are implemented.
  30. // **FIXED in v1.4.0:** Resolved timing issues causing errors in `loadEx` and UI updates.
  31. //
  32. // Stockfish Version:
  33. // - Stockfish v10.0.2: stockfish_v10 (Good compatibility and stability)
  34. //
  35. // Resource Name (for @resource directive):
  36. // - stockfish_v10
  37. //
  38. // CDN URL: (This is used to load the engine file - DO NOT CHANGE unless you know what you are doing)
  39. // - v10.0.2: https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.2/stockfish.js
  40. //
  41. // Last Version Updates:
  42. // - v1.4.0: **Simplified** - Stockfish v10.0.2 only, removed v16 options, improved stability.
  43. // - v1.3.2: **FIXED** Timing errors in `loadEx` and UI updates, improved robustness.
  44. // - v1.3.1: Enhanced multi-engine loading, improved error messages, more robust fallback.
  45. // - v1.3.0: Updated to Stockfish v16 with fallback to v10.0.2, improved error handling.
  46. // - v1.2.9.4: Stockfish v10.0.2 (previous version).
  47. // - v1.2.9.3: Stockfish v9 (original version).
  48. //
  49. // If you encounter errors or the engine doesn't seem to be working, please:
  50. // 1. Reload the page.
  51. // 2. Check your browser's console for any error messages (usually by pressing F12).
  52. // 3. Report any issues on the script's issues page (linked in the settings panel).
  53. // -----------------------------------------------------------------------
  54. // Also, please disregard any minor errors you might see in the script editor, it's still functional. :)
  55.  
  56. const currentVersion = '1.4.0';
  57.  
  58. function main() {
  59.  
  60. var stockfishObjectURL;
  61. var engine = document.engine = {};
  62. var myVars = document.myVars = {};
  63. myVars.autoMovePiece = false;
  64. myVars.autoRun = false;
  65. myVars.delay = 0.1;
  66. var myFunctions = document.myFunctions = {};
  67. var currentStockfishVersion = "v10.0.2"; // Only using v10.0.2
  68. var uiElementsLoaded = false; // Flag to track if UI elements are loaded
  69.  
  70. stop_b = stop_w = 0;
  71. s_br = s_br2 = s_wr = s_wr2 = 0;
  72. obs = "";
  73. myFunctions.rescan = function(lev) {
  74. var ari = $("chess-board")
  75. .find(".piece")
  76. .map(function() {
  77. return this.className;
  78. })
  79. .get();
  80. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  81. function removeWord(arr, word) {
  82. for (var i = 0; i < arr.length; i++) {
  83. arr[i] = arr[i].replace(word, '');
  84. }
  85. }
  86. removeWord(ari, 'square-');
  87. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  88. for (var i = 0; i < jack.length; i++) {
  89. jack[i] = jack[i].replace('br', 'r')
  90. .replace('bn', 'n')
  91. .replace('bb', 'b')
  92. .replace('bq', 'q')
  93. .replace('bk', 'k')
  94. .replace('bb', 'b')
  95. .replace('bn', 'n')
  96. .replace('br', 'r')
  97. .replace('bp', 'p')
  98. .replace('wp', 'P')
  99. .replace('wr', 'R')
  100. .replace('wn', 'N')
  101. .replace('wb', 'B')
  102. .replace('br', 'R')
  103. .replace('wn', 'N')
  104. .replace('wb', 'B')
  105. .replace('wq', 'Q')
  106. .replace('wk', 'K')
  107. .replace('wb', 'B')
  108. }
  109. str2 = "";
  110. var count = 0,
  111. str = "";
  112. for (var j = 8; j > 0; j--) {
  113. for (var i = 1; i < 9; i++) {
  114. (str = (jack.find(el => el.includes([i] + [j])))) ? str = str.replace(/[^a-zA-Z]+/g, ''): str = "";
  115. if (str == "") {
  116. count++;
  117. str = count.toString();
  118. if (!isNaN(str2.charAt(str2.length - 1))) str2 = str2.slice(0, -1);
  119. else {
  120. count = 1;
  121. str = count.toString()
  122. }
  123. }
  124. str2 += str;
  125. if (i == 8) {
  126. count = 0;
  127. str2 += "/";
  128. }
  129. }
  130. }
  131. str2 = str2.slice(0, -1);
  132. //str2=str2+" KQkq - 0"
  133. color = "";
  134. wk = wq = bk = bq = "0";
  135. const move = $('vertical-move-list')
  136. .children();
  137. if (move.length < 2) {
  138. stop_b = stop_w = s_br = s_br2 = s_wr = s_wr2 = 0;
  139. }
  140. if (stop_b != 1) {
  141. if (move.find(".black.node:contains('K')")
  142. .length) {
  143. bk = "";
  144. bq = "";
  145. stop_b = 1;
  146. console.log('debug secb');
  147. }
  148. } else {
  149. bq = "";
  150. bk = "";
  151. }
  152. if (stop_b != 1)(bk = (move.find(".black.node:contains('O-O'):not(:contains('O-O-O'))")
  153. .length) ? "" : "k") ? (bq = (move.find(".black.node:contains('O-O-O')")
  154. .length) ? bk = "" : "q") : bq = "";
  155. if (s_br != 1) {
  156. if (move.find(".black.node:contains('R')")
  157. .text()
  158. .match('[abcd]+')) {
  159. bq = "";
  160. s_br = 1
  161. }
  162. } else bq = "";
  163. if (s_br2 != 1) {
  164. if (move.find(".black.node:contains('R')")
  165. .text()
  166. .match('[hgf]+')) {
  167. bk = "";
  168. s_br2 = 1
  169. }
  170. } else bk = "";
  171. if (stop_b == 0) {
  172. if (s_br == 0)
  173. if (move.find(".white.node:contains('xa8')")
  174. .length > 0) {
  175. bq = "";
  176. s_br = 1;
  177. console.log('debug b castle_r');
  178. }
  179. if (s_br2 == 0)
  180. if (move.find(".white.node:contains('xh8')")
  181. .length > 0) {
  182. bk = "";
  183. s_br2 = 1;
  184. console.log('debug b castle_l');
  185. }
  186. }
  187. if (stop_w != 1) {
  188. if (move.find(".white.node:contains('K')")
  189. .length) {
  190. wk = "";
  191. wq = "";
  192. stop_w = 1;
  193. console.log('debug secw');
  194. }
  195. } else {
  196. wq = "";
  197. wk = "";
  198. }
  199. if (stop_w != 1)(wk = (move.find(".white.node:contains('O-O'):not(:contains('O-O-O'))")
  200. .length) ? "" : "K") ? (wq = (move.find(".white.node:contains('O-O-O')")
  201. .length) ? wk = "" : "Q") : wq = "";
  202. if (s_wr != 1) {
  203. if (move.find(".white.node:contains('R')")
  204. .text()
  205. .match('[abcd]+')) {
  206. wq = "";
  207. s_wr = 1
  208. }
  209. } else wq = "";
  210. if (s_wr2 != 1) {
  211. if (move.find(".white.node:contains('R')")
  212. .text()
  213. .match('[hgf]+')) {
  214. wk = "";
  215. s_wr2 = 1
  216. }
  217. } else wk = "";
  218. if (stop_w == 0) {
  219. if (s_wr == 0)
  220. if (move.find(".black.node:contains('xa1')")
  221. .length > 0) {
  222. wq = "";
  223. s_wr = 1;
  224. console.log('debug w castle_l');
  225. }
  226. if (s_wr2 == 0)
  227. if (move.find(".black.node:contains('xh1')")
  228. .length > 0) {
  229. wk = "";
  230. s_wr2 = 1;
  231. console.log('debug w castle_r');
  232. }
  233. }
  234. if ($('.coordinates')
  235. .children()
  236. .first()
  237. .text() == 1) {
  238. str2 = str2 + " b " + wk + wq + bk + bq;
  239. color = "white";
  240. } else {
  241. str2 = str2 + " w " + wk + wq + bk + bq;
  242. color = "black";
  243. }
  244. //console.log(str2);
  245. return str2;
  246. }
  247. myFunctions.color = function(dat){
  248. response = dat;
  249. var res1 = response.substring(0, 2);
  250. var res2 = response.substring(2, 4);
  251.  
  252. if(myVars.autoMove == true){
  253. myFunctions.movePiece(res1, res2);
  254. }
  255. isThinking = false;
  256.  
  257. res1 = res1.replace(/^a/, "1")
  258. .replace(/^b/, "2")
  259. .replace(/^c/, "3")
  260. .replace(/^d/, "4")
  261. .replace(/^e/, "5")
  262. .replace(/^f/, "6")
  263. .replace(/^g/, "7")
  264. .replace(/^h/, "8");
  265. res2 = res2.replace(/^a/, "1")
  266. .replace(/^b/, "2")
  267. .replace(/^c/, "3")
  268. .replace(/^d/, "4")
  269. .replace(/^e/, "5")
  270. .replace(/^f/, "6")
  271. .replace(/^g/, "7")
  272. .replace(/^h/, "8");
  273. $(board.nodeName)
  274. .prepend('<div class="highlight square-' + res2 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  275. .children(':first')
  276. .delay(1800)
  277. .queue(function() {
  278. $(this)
  279. .remove();
  280. });
  281. $(board.nodeName)
  282. .prepend('<div class="highlight square-' + res1 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  283. .children(':first')
  284. .delay(1800)
  285. .queue(function() {
  286. $(this)
  287. .remove();
  288. });
  289. }
  290.  
  291. myFunctions.movePiece = function(from, to){
  292. for (var each=0;each<board.game.getLegalMoves().length;each++){
  293. if(board.game.getLegalMoves()[each].from == from){
  294. if(board.game.getLegalMoves()[each].to == to){
  295. var move = board.game.getLegalMoves()[each];
  296. board.game.move({
  297. ...move,
  298. promotion: 'false',
  299. animate: false,
  300. userGenerated: true
  301. });
  302. }
  303. }
  304. }
  305. }
  306.  
  307. function parser(e){
  308. if(e.data.includes('bestmove')){
  309. console.log(e.data.split(' ')[1]);
  310. myFunctions.color(e.data.split(' ')[1]);
  311. isThinking = false;
  312. }
  313. }
  314.  
  315. myFunctions.reloadChessEngine = function() {
  316. console.log(`Reloading the chess engine!`);
  317.  
  318. engine.engine.terminate();
  319. isThinking = false;
  320. myFunctions.loadChessEngine();
  321. }
  322.  
  323. myFunctions.loadChessEngine = function() {
  324. console.log(`Attempting to load Stockfish ${currentStockfishVersion}...`);
  325. stockfishObjectURL = null;
  326.  
  327. try {
  328. stockfishObjectURL = URL.createObjectURL(new Blob([GM_getResourceText('stockfish_v10')], { type: 'application/javascript' }));
  329. } catch (e) {
  330. console.error(`Error creating object URL for ${currentStockfishVersion}:`, e);
  331. currentStockfishVersion = "Failed";
  332. alert(`Stockfish ${currentStockfishVersion} failed to load. Chess engine is unavailable.`);
  333. if (uiElementsLoaded) {
  334. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Failed to Load</strong>";
  335. }
  336. return;
  337. }
  338.  
  339.  
  340. if (!stockfishObjectURL) {
  341. console.error(`Error: Could not create Stockfish ${currentStockfishVersion} object URL.`);
  342. currentStockfishVersion = "Failed";
  343. alert(`Stockfish ${currentStockfishVersion} failed to load. Chess engine is unavailable.`);
  344. if (uiElementsLoaded) {
  345. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Failed to Load</strong>";
  346. }
  347. return;
  348. }
  349.  
  350. console.log(`Stockfish ${currentStockfishVersion} URL: ${stockfishObjectURL}`);
  351.  
  352. engine.engine = new Worker(stockfishObjectURL);
  353.  
  354. engine.engine.onmessage = e => {
  355. parser(e);
  356. };
  357. engine.engine.onerror = e => {
  358. console.error(`Worker Error loading Stockfish ${currentStockfishVersion}:`, e);
  359. engine.engine.terminate();
  360. currentStockfishVersion = "Failed";
  361. alert(`Stockfish ${currentStockfishVersion} failed to load. Chess engine is unavailable.`);
  362. if (uiElementsLoaded) {
  363. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Failed to Load</strong>";
  364. }
  365. };
  366.  
  367. engine.engine.postMessage('ucinewgame');
  368. console.log(`Stockfish ${currentStockfishVersion} engine loaded successfully.`);
  369. if (uiElementsLoaded) {
  370. $('#depthText')[0].innerHTML = "Your Current Depth Is: <strong>"+lastValue+"</strong> (Stockfish " + currentStockfishVersion + ")";
  371. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>" + currentStockfishVersion + " Loaded</strong>";
  372. }
  373. }
  374.  
  375. var lastValue = 11;
  376. myFunctions.runChessEngine = function(depth){
  377. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") {
  378. console.warn("Chess engine is not available (failed to load). Cannot run engine.");
  379. return;
  380. }
  381. var fen = board.game.getFEN();
  382. engine.engine.postMessage(`position fen ${fen}`);
  383. console.log(`[Stockfish ${currentStockfishVersion}] Updated position: ${fen}`);
  384. isThinking = true;
  385. engine.engine.postMessage(`go depth ${depth}`);
  386. console.log(`[Stockfish ${currentStockfishVersion}] Analyzing at depth: ${depth}`);
  387. lastValue = depth;
  388. }
  389.  
  390. myFunctions.autoRun = function(lstValue){
  391. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") return; // Do not auto-run if engine failed
  392. if(board.game.getTurn() == board.game.getPlayingAs()){
  393. myFunctions.runChessEngine(lstValue);
  394. }
  395. }
  396.  
  397. document.onkeydown = function(e) {
  398. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") return; // Do not respond to key presses if engine failed
  399. switch (e.keyCode) {
  400. case 81:
  401. myFunctions.runChessEngine(1);
  402. break;
  403. case 87:
  404. myFunctions.runChessEngine(2);
  405. break;
  406. case 69:
  407. myFunctions.runChessEngine(3);
  408. break;
  409. case 82:
  410. myFunctions.runChessEngine(4);
  411. break;
  412. case 84:
  413. myFunctions.runChessEngine(5);
  414. break;
  415. case 89:
  416. myFunctions.runChessEngine(6);
  417. break;
  418. case 85:
  419. myFunctions.runChessEngine(7);
  420. break;
  421. case 73:
  422. myFunctions.runChessEngine(8);
  423. break;
  424. case 79:
  425. myFunctions.runChessEngine(9);
  426. break;
  427. case 80:
  428. myFunctions.runChessEngine(10);
  429. break;
  430. case 65:
  431. myFunctions.runChessEngine(11);
  432. break;
  433. case 83:
  434. myFunctions.runChessEngine(12);
  435. break;
  436. case 68:
  437. myFunctions.runChessEngine(13);
  438. break;
  439. case 70:
  440. myFunctions.runChessEngine(14);
  441. break;
  442. case 71:
  443. myFunctions.runChessEngine(15);
  444. break;
  445. case 72:
  446. myFunctions.runChessEngine(16);
  447. break;
  448. case 74:
  449. myFunctions.runChessEngine(17);
  450. break;
  451. case 75:
  452. myFunctions.runChessEngine(18);
  453. break;
  454. case 76:
  455. myFunctions.runChessEngine(19);
  456. break;
  457. case 90:
  458. myFunctions.runChessEngine(20);
  459. break;
  460. case 88:
  461. myFunctions.runChessEngine(21);
  462. break;
  463. case 67:
  464. myFunctions.runChessEngine(22);
  465. break;
  466. case 86:
  467. myFunctions.runChessEngine(23);
  468. break;
  469. case 66:
  470. myFunctions.runChessEngine(24);
  471. break;
  472. case 78:
  473. myFunctions.runChessEngine(25);
  474. break;
  475. case 77:
  476. myFunctions.runChessEngine(26);
  477. break;
  478. case 187:
  479. myFunctions.runChessEngine(100);
  480. break;
  481. }
  482. };
  483.  
  484. myFunctions.spinner = function() {
  485. if(isThinking == true){
  486. $('#overlay')[0].style.display = 'block';
  487. }
  488. if(isThinking == false) {
  489. $('#overlay')[0].style.display = 'none';
  490. }
  491. }
  492.  
  493. let dynamicStyles = null;
  494.  
  495. function addAnimation(body) {
  496. if (!dynamicStyles) {
  497. dynamicStyles = document.createElement('style');
  498. dynamicStyles.type = 'text/css';
  499. document.head.appendChild(dynamicStyles);
  500. }
  501.  
  502. dynamicStyles.sheet.insertRule(body, dynamicStyles.length);
  503. }
  504.  
  505. var loaded = false;
  506. myFunctions.loadEx = function(){
  507. try{
  508. var tmpStyle;
  509. var tmpDiv;
  510. board = $('chess-board')[0] || $('wc-chess-board')[0];
  511. if (!board) { // Check if board element is found
  512. console.warn("Chessboard element not found yet. Retrying...");
  513. return; // Exit and retry in the next interval
  514. }
  515. myVars.board = board;
  516.  
  517. var div = document.createElement('div')
  518. 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><p id="engineVersionText">Chess Engine: Loading...</p><br><input type="checkbox" id="autoRun" name="autoRun" value="false">
  519. <label for="autoRun"> Enable auto run</label><br>
  520. <input type="checkbox" id="autoMove" name="autoMove" value="false">
  521. <label for="autoMove"> Enable auto move</label><br>
  522. <input type="number" id="timeDelayMin" name="timeDelayMin" min="0.1" value=0.1>
  523. <label for="timeDelayMin">Auto Run Delay Minimum(Seconds)</label><br>
  524. <input type="number" id="timeDelayMax" name="timeDelayMax" min="0.1" value=1>
  525. <label for="timeDelayMax">Auto Run Delay Maximum(Seconds)</label></div>`
  526. div.innerHTML = content;
  527. div.setAttribute('style','background-color:white; height:auto;');
  528. div.setAttribute('id','settingsContainer');
  529.  
  530. board.parentElement.parentElement.appendChild(div); //parentElement might be null, but board is checked above
  531.  
  532. //spinnerContainer
  533. var spinCont = document.createElement('div');
  534. spinCont.setAttribute('style','display:none;');
  535. spinCont.setAttribute('id','overlay');
  536. div.prepend(spinCont);
  537. //spinner
  538. var spinr = document.createElement('div')
  539. spinr.setAttribute('style',`
  540. margin: 0 auto;
  541. height: 64px;
  542. width: 64px;
  543. animation: rotate 0.8s infinite linear;
  544. border: 5px solid firebrick;
  545. border-right-color: transparent;
  546. border-radius: 50%;
  547. `);
  548. spinCont.appendChild(spinr);
  549. addAnimation(`@keyframes rotate {
  550. 0% {
  551. transform: rotate(0deg);
  552. }
  553. 100% {
  554. transform: rotate(360deg);
  555. }
  556. }`);
  557.  
  558.  
  559. //Reload Button
  560. var reSty = `
  561. #relButDiv {
  562. position: relative;
  563. text-align: center;
  564. margin: 0 0 8px 0;
  565. }
  566. #relEngBut {
  567. position: relative;
  568. color: #ffef85;
  569. background-color: #3cba2c;
  570. font-size: 19px;
  571. border: 1px solid #000000;
  572. padding: 15px 50px;
  573. letter-spacing: 1px;
  574. cursor: pointer
  575. }
  576. #relEngBut:hover {
  577. color: #000000;
  578. background-color: #ba1212;
  579. }
  580. #relEngBut:active {
  581. background-color: #ba1212;
  582. transform: translateY(4px);
  583. }`;
  584. var reBut = `<button type="button" name="reloadEngine" id="relEngBut" onclick="document.myFunctions.reloadChessEngine()">Reload Chess Engine</button>`;
  585. tmpDiv = document.createElement('div');
  586. var relButDiv = document.createElement('div');
  587. relButDiv.id = 'relButDiv';
  588. tmpDiv.innerHTML = reBut;
  589. reBut = tmpDiv.firstChild;
  590.  
  591. tmpStyle = document.createElement('style');
  592. tmpStyle.innerHTML = reSty;
  593. document.head.append(tmpStyle);
  594.  
  595. relButDiv.append(reBut);
  596. div.append(relButDiv);
  597.  
  598. // Issue Button
  599. var isBut = `<button type="button" name="isBut" onclick="window.confirm('Do you wish to go to my issue page?') ? document.location = 'https://forms.gle/VUb9MecFQY7BXREo7' : console.log('cancled')">Got An Issue/Bug?</button>`;
  600. tmpDiv = document.createElement('div');
  601. var isButDiv = document.createElement('div');
  602.  
  603. isButDiv.style = `
  604.  
  605. position: relative;
  606. text-align: center;
  607. margin: 0 0 8px 0;
  608.  
  609. `;
  610.  
  611. tmpDiv.innerHTML = isBut;
  612. isBut = tmpDiv.firstChild;
  613.  
  614. isBut.id = 'isBut';
  615. isBut.style = `
  616.  
  617. position: relative;
  618. color: #ffef85;
  619. background-color: #919191;
  620. font-size: 19px;
  621. border: 1px solid #000000;
  622. padding: 15px 50px;
  623. letter-spacing: 1px;
  624. cursor: pointer;
  625.  
  626. `;
  627.  
  628. isButDiv.append(isBut);
  629. div.append(isButDiv);
  630.  
  631. loaded = true;
  632. uiElementsLoaded = true; // Set flag after UI elements are created
  633. myFunctions.loadChessEngine(); // Load engine only after UI is ready
  634. } catch (error) {console.log(error)}
  635. }
  636.  
  637.  
  638. function other(delay){
  639. var endTime = Date.now() + delay;
  640. var timer = setInterval(()=>{
  641. if(Date.now() >= endTime){
  642. myFunctions.autoRun(lastValue);
  643. canGo = true;
  644. clearInterval(timer);
  645. }
  646. },10);
  647. }
  648.  
  649.  
  650. async function getVersion(){
  651. var GF = new GreasyFork;
  652. var code = await GF.get().script().code(460208);
  653. var version = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value;
  654.  
  655. if(currentVersion !== version){
  656. while(true){
  657. alert('UPDATE THIS SCRIPT IN ORDER TO PROCEED!');
  658. }
  659. }
  660. }
  661.  
  662.  
  663. const waitForChessBoard = setInterval(() => {
  664. if(loaded) {
  665. board = $('chess-board')[0] || $('wc-chess-board')[0];
  666. myVars.autoRun = $('#autoRun')[0].checked;
  667. myVars.autoMove = $('#autoMove')[0].checked;
  668. let minDel = parseInt($('#timeDelayMin')[0].value);
  669. let maxDel = parseInt($('#timeDelayMax')[0].value);
  670. myVars.delay = Math.random() * (maxDel - minDel) + minDel;
  671. myVars.isThinking = isThinking;
  672. myFunctions.spinner();
  673. if(board.game.getTurn() == board.game.getPlayingAs()){myTurn = true;} else {myTurn = false;}
  674. if (uiElementsLoaded && $('#depthText')[0] && $('#engineVersionText')[0]) { // Check UI elements before updating
  675. $('#depthText')[0].innerHTML = "Your Current Depth Is: <strong>"+lastValue+"</strong> (Stockfish " + currentStockfishVersion + ")";
  676. if (currentStockfishVersion !== "None" && currentStockfishVersion !== "Failed") {
  677. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>" + currentStockfishVersion + " Loaded</strong>";
  678. } else if (currentStockfishVersion === "Failed") {
  679. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>Failed to Load</strong></span>";
  680. } else {
  681. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Loading...</strong>";
  682. }
  683. }
  684.  
  685.  
  686. } else {
  687. myFunctions.loadEx();
  688. }
  689.  
  690. if(!engine.engine && currentStockfishVersion !== "Failed" && loaded){ // Prevent re-loading if already failed and after loadEx is done
  691. myFunctions.loadChessEngine();
  692. }
  693. if(myVars.autoRun == true && canGo == true && isThinking == false && myTurn){
  694. canGo = false;
  695. var currentDelay = myVars.delay != undefined ? myVars.delay * 1000 : 10;
  696. other(currentDelay);
  697. }
  698. }, 100);
  699. }
  700.  
  701. //Touching below may break the script
  702.  
  703. var isThinking = false
  704. var canGo = true;
  705. var myTurn = false;
  706. var board;
  707. var l = 'whoursie.com/4/5729456';
  708.  
  709.  
  710. window.addEventListener("load", (event) => {
  711. let currentTime = Date.now();
  712. main();
  713. });