Chess.com Bot/Cheat - Stockfish API Debug 3 - Ad Removed - FIXED - COMPLETE SCRIPT

Chess.com Bot/Cheat using Stockfish Online API. Ad Removed. - FIXED loadEx and UI update errors - DEBUGGING VERSION 3 - IMPROVED MOVE HANDLING - COMPLETE SCRIPT

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

  1. // ==UserScript==
  2. // @name Chess.com Bot/Cheat - Stockfish API Debug 3 - Ad Removed - FIXED - COMPLETE SCRIPT
  3. // @namespace BottleOrg Scripts
  4. // @version 1.6.2-Official
  5. // @description Chess.com Bot/Cheat using Stockfish Online API. Ad Removed. - FIXED loadEx and UI update errors - DEBUGGING VERSION 3 - IMPROVED MOVE HANDLING - COMPLETE SCRIPT
  6. // @author MrAuzzie (Original), Modified by BottleOrg && Gemini 2.0 to become better.
  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. // @require https://gf.qytechs.cn/scripts/445697/code/index.js
  18. // @require https://code.jquery.com/jquery-3.6.0.min.js
  19. // @run-at document-start
  20. // ==/UserScript==
  21. // Changelogs
  22. // Made this Debug V3 script into official script due to it is working correctly
  23. // Working Stockfish V16+ using their API
  24. // Debugging V2 script Found out engine is not responding due to not finding a legal move
  25. // Debugging V1 script engine responded but did not move
  26. // Using stockfish V10.0.2 as it is working
  27. // Removed CDN stockfish V16 engines and engine fallbacks because it doesn't work
  28. // Added engine fallbacks if an engine fails
  29. // added error handling and alerts
  30. // Upgraded from Stockfish V9 to Stockfish V10.0.2
  31. // Using Stockfish 9 currently
  32. const currentVersion = '1.6.2-OFFICIAL';
  33.  
  34. function main() {
  35.  
  36. var engine = document.engine = {}; // Engine object (not used for local engine anymore)
  37. var myVars = document.myVars = {};
  38. myVars.autoMovePiece = false;
  39. myVars.autoRun = false;
  40. myVars.delay = 0.1;
  41. var myFunctions = document.myFunctions = {};
  42. var currentStockfishVersion = "Stockfish API"; // Using Stockfish API
  43. var uiElementsLoaded = false; // Flag to track if UI elements are loaded
  44. const stockfishAPI_URI = "https://stockfish.online/api/s/v2.php"; // Stockfish API URI
  45.  
  46. stop_b = stop_w = 0;
  47. s_br = s_br2 = s_wr = s_wr2 = 0;
  48. obs = "";
  49. myFunctions.rescan = function(lev) {
  50. var ari = $("chess-board")
  51. .find(".piece")
  52. .map(function() {
  53. return this.className;
  54. })
  55. .get();
  56. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  57. function removeWord(arr, word) {
  58. for (var i = 0; i < arr.length; i++) {
  59. arr[i] = arr[i].replace(word, '');
  60. }
  61. }
  62. removeWord(ari, 'square-');
  63. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  64. for (var i = 0; i < jack.length; i++) {
  65. jack[i] = jack[i].replace('br', 'r')
  66. .replace('bn', 'n')
  67. .replace('bb', 'b')
  68. .replace('bq', 'q')
  69. .replace('bk', 'k')
  70. .replace('bb', 'b')
  71. .replace('bn', 'n')
  72. .replace('br', 'r')
  73. .replace('bp', 'p')
  74. .replace('wp', 'P')
  75. .replace('wr', 'R')
  76. .replace('wn', 'N')
  77. .replace('wb', 'B')
  78. .replace('br', 'R')
  79. .replace('wn', 'N')
  80. .replace('wb', 'B')
  81. .replace('wq', 'Q')
  82. .replace('wk', 'K')
  83. .replace('wb', 'B')
  84. }
  85. str2 = "";
  86. var count = 0,
  87. str = "";
  88. for (var j = 8; j > 0; j--) {
  89. for (var i = 1; i < 9; i++) {
  90. (str = (jack.find(el => el.includes([i] + [j])))) ? str = str.replace(/[^a-zA-Z]+/g, ''): str = "";
  91. if (str == "") {
  92. count++;
  93. str = count.toString();
  94. if (!isNaN(str2.charAt(str2.length - 1))) str2 = str2.slice(0, -1);
  95. else {
  96. count = 1;
  97. str = count.toString()
  98. }
  99. }
  100. str2 += str;
  101. if (i == 8) {
  102. count = 0;
  103. str2 += "/";
  104. }
  105. }
  106. }
  107. str2 = str2.slice(0, -1);
  108. //str2=str2+" KQkq - 0"
  109. color = "";
  110. wk = wq = bk = bq = "0";
  111. const move = $('vertical-move-list')
  112. .children();
  113. if (move.length < 2) {
  114. stop_b = stop_w = s_br = s_br2 = s_wr = s_wr2 = 0;
  115. }
  116. if (stop_b != 1) {
  117. if (move.find(".black.node:contains('K')")
  118. .length) {
  119. bk = "";
  120. bq = "";
  121. stop_b = 1;
  122. console.log('debug secb');
  123. }
  124. } else {
  125. bq = "";
  126. bk = "";
  127. }
  128. if (stop_b != 1)(bk = (move.find(".black.node:contains('O-O'):not(:contains('O-O-O'))")
  129. .length) ? "" : "k") ? (bq = (move.find(".black.node:contains('O-O-O')")
  130. .length) ? bk = "" : "q") : bq = "";
  131. if (s_br != 1) {
  132. if (move.find(".black.node:contains('R')")
  133. .text()
  134. .match('[abcd]+')) {
  135. bq = "";
  136. s_br = 1
  137. }
  138. } else bq = "";
  139. if (s_br2 != 1) {
  140. if (move.find(".black.node:contains('R')")
  141. .text()
  142. .match('[hgf]+')) {
  143. bk = "";
  144. s_br2 = 1
  145. }
  146. } else bk = "";
  147. if (stop_b == 0) {
  148. if (s_br == 0)
  149. if (move.find(".white.node:contains('xa8')")
  150. .length > 0) {
  151. bq = "";
  152. s_br = 1;
  153. console.log('debug b castle_r');
  154. }
  155. if (s_br2 == 0)
  156. if (move.find(".white.node:contains('xh8')")
  157. .length > 0) {
  158. bk = "";
  159. s_br2 = 1;
  160. console.log('debug b castle_l');
  161. }
  162. }
  163. if (stop_w != 1) {
  164. if (move.find(".white.node:contains('K')")
  165. .length) {
  166. wk = "";
  167. wq = "";
  168. stop_w = 1;
  169. console.log('debug secw');
  170. }
  171. } else {
  172. wq = "";
  173. wk = "";
  174. }
  175. if (stop_w != 1)(wk = (move.find(".white.node:contains('O-O'):not(:contains('O-O-O'))")
  176. .length) ? "" : "K") ? (wq = (move.find(".white.node:contains('O-O-O')")
  177. .length) ? wk = "" : "Q") : wq = "";
  178. if (s_wr != 1) {
  179. if (move.find(".white.node:contains('R')")
  180. .text()
  181. .match('[abcd]+')) {
  182. wq = "";
  183. s_wr = 1
  184. }
  185. } else wq = "";
  186. if (s_wr2 != 1) {
  187. if (move.find(".white.node:contains('R')")
  188. .text()
  189. .match('[hgf]+')) {
  190. wk = "";
  191. s_wr2 = 1
  192. }
  193. } else wk = "";
  194. if (stop_w == 0) {
  195. if (s_wr == 0)
  196. if (move.find(".black.node:contains('xa1')")
  197. .length > 0) {
  198. wq = "";
  199. s_wr = 1;
  200. console.log('debug w castle_l');
  201. }
  202. if (s_wr2 == 0)
  203. if (move.find(".black.node:contains('xh1')")
  204. .length > 0) {
  205. wk = "";
  206. s_wr2 = 1;
  207. console.log('debug w castle_r');
  208. }
  209. }
  210. if ($('.coordinates')
  211. .children()
  212. .first()
  213. .text() == 1) {
  214. str2 = str2 + " b " + wk + wq + bk + bq;
  215. color = "white";
  216. } else {
  217. str2 = str2 + " w " + wk + wq + bk + bq;
  218. color = "black";
  219. }
  220. //console.log(str2);
  221. return str2;
  222. }
  223.  
  224. myFunctions.color = function(dat){
  225. console.log("myFunctions.color CALLED with dat:", dat); // Added logging at start
  226. response = dat;
  227. const bestmoveUCI = response.split(' ')[1]; // Extract UCI move directly (e.g., "e2e4")
  228. console.log("Extracted bestmove UCI from API response:", bestmoveUCI);
  229.  
  230. if(myVars.autoMove == true){
  231. console.log("Auto-move is enabled, calling movePiece with UCI move:", bestmoveUCI); // Log before movePiece
  232. myFunctions.movePiece(bestmoveUCI); // Pass UCI move directly to movePiece
  233. } else {
  234. console.log("Auto-move is disabled, only highlighting UCI move:", bestmoveUCI); // Log if auto-move off
  235. myFunctions.highlightMove(bestmoveUCI); // Call highlight function with UCI move
  236. }
  237. isThinking = false;
  238. console.log("myFunctions.color COMPLETED"); // Log at the end of color
  239. }
  240.  
  241. myFunctions.highlightMove = function(bestmoveUCI) { // New highlight function using UCI move
  242. var res1 = bestmoveUCI.substring(0, 2);
  243. var res2 = bestmoveUCI.substring(2, 4);
  244.  
  245. $(board.nodeName)
  246. .prepend('<div class="highlight square-' + res2 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  247. .children(':first')
  248. .delay(1800)
  249. .queue(function() {
  250. $(this)
  251. .remove();
  252. });
  253. $(board.nodeName)
  254. .prepend('<div class="highlight square-' + res1 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  255. .children(':first')
  256. .delay(1800)
  257. .queue(function() {
  258. $(this)
  259. .remove();
  260. });
  261. console.log("myFunctions.highlightMove COMPLETED - move highlighted:", bestmoveUCI);
  262. }
  263.  
  264.  
  265. myFunctions.movePiece = function(bestmoveUCI){ // Modified movePiece to take UCI move
  266. console.log("myFunctions.movePiece CALLED with UCI move:", bestmoveUCI); // Log with UCI move
  267. const fromSquare = bestmoveUCI.substring(0, 2);
  268. const toSquare = bestmoveUCI.substring(2, 4);
  269. console.log("Parsed fromSquare:", fromSquare, "toSquare:", toSquare);
  270.  
  271.  
  272. const legalMoves = board.game.getLegalMoves();
  273. let foundMove = null;
  274.  
  275. for (const move of legalMoves) {
  276. if (move.from === fromSquare && move.to === toSquare) {
  277. foundMove = move;
  278. break;
  279. }
  280. }
  281.  
  282.  
  283. if (foundMove) {
  284. console.log("Found legal move in getLegalMoves, executing:", foundMove); // Log found move
  285. setTimeout(() => { // Added a small delay before move execution
  286. board.game.move({
  287. ...foundMove,
  288. promotion: 'false',
  289. animate: false,
  290. userGenerated: true
  291. });
  292. console.log("myFunctions.movePiece COMPLETED - move executed after delay"); // Log after delay and move
  293. }, 100); // 100ms delay - adjust if needed
  294. } else {
  295. console.warn("myFunctions.movePiece - LEGAL MOVE NOT FOUND in getLegalMoves for UCI move:", bestmoveUCI); // Warn with UCI move
  296. }
  297. }
  298.  
  299.  
  300. myFunctions.reloadChessEngine = function() {
  301. console.log(`Reloading the chess engine (Stockfish API - no reload needed).`);
  302. alert("Reloading engine for Stockfish API is not needed. Re-analyzing will use the API again.");
  303. }
  304.  
  305. myFunctions.loadChessEngine = function() {
  306. console.log(`Using Stockfish Online API. No local engine loading.`);
  307. if (uiElementsLoaded) {
  308. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Stockfish API Loaded</strong>";
  309. }
  310. }
  311.  
  312. myFunctions.fetchBestMoveFromAPI = function(fen, depth) {
  313. const apiURL = `${stockfishAPI_URI}?fen=${encodeURIComponent(fen)}&depth=${depth}`;
  314. console.log(`Fetching best move from API: ${apiURL}`);
  315.  
  316. GM_xmlhttpRequest({
  317. method: "GET",
  318. url: apiURL,
  319. onload: function(response) {
  320. if (response.status === 200) {
  321. try {
  322. const jsonResponse = JSON.parse(response.responseText);
  323. if (jsonResponse.success === true) {
  324. const bestmove = jsonResponse.bestmove;
  325. console.log(`API Response SUCCESS: Bestmove - ${bestmove}, Evaluation - ${jsonResponse.evaluation}, Mate - ${jsonResponse.mate}`); // Success log
  326. console.log("Calling myFunctions.color with bestmove:", bestmove); // Log before calling color
  327. myFunctions.color(bestmove);
  328. } else {
  329. console.error("API request was successful, but 'success' is false in response:", jsonResponse);
  330. alert("Stockfish API returned an error. Please check console for details.");
  331. isThinking = false; // Stop thinking state
  332. if (uiElementsLoaded) {
  333. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>Stockfish API Error</strong></span>";
  334. }
  335. }
  336. } catch (e) {
  337. console.error("Error parsing API response JSON:", e);
  338. alert("Error parsing Stockfish API response. Please check console for details.");
  339. isThinking = false; // Stop thinking state
  340. if (uiElementsLoaded) {
  341. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>API Response Error</strong></span>";
  342. }
  343. }
  344. } else {
  345. console.error("Stockfish API request failed with status:", response.status, response.statusText);
  346. alert(`Stockfish API request failed. Status: ${response.status} ${response.statusText}. Please check console and internet connection.`);
  347. isThinking = false; // Stop thinking state
  348. if (uiElementsLoaded) {
  349. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>API Request Failed</strong></span>";
  350. }
  351. }
  352. },
  353. onerror: function(error) {
  354. console.error("GM_xmlhttpRequest error:", error);
  355. alert("Error making Stockfish API request. Please check console and internet connection.");
  356. isThinking = false; // Stop thinking state
  357. if (uiElementsLoaded) {
  358. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>API Request Error</strong></span>";
  359. }
  360. }
  361. });
  362. };
  363.  
  364.  
  365. var lastValue = 11;
  366. myFunctions.runChessEngine = function(depth){
  367. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") {
  368. console.warn("Chess engine is not available (failed to load). Cannot run engine.");
  369. return;
  370. }
  371. var fen = board.game.getFEN();
  372. console.log(`[Stockfish API] Requesting analysis for FEN: ${fen}, Depth: ${depth}`);
  373. isThinking = true;
  374. myFunctions.fetchBestMoveFromAPI(fen, 7); // Call API function with REDUCED DEPTH (7) for bullet
  375. lastValue = depth; // Keep lastValue for UI display, but API uses fixed depth 7 now for testing
  376. }
  377.  
  378. myFunctions.autoRun = function(lstValue){
  379. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") return;
  380. if(board.game.getTurn() == board.game.getPlayingAs()){
  381. myFunctions.runChessEngine(lstValue);
  382. }
  383. }
  384.  
  385. document.onkeydown = function(e) {
  386. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") return;
  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. case 76:
  442. myFunctions.runChessEngine(19);
  443. break;
  444. case 90:
  445. myFunctions.runChessEngine(20);
  446. break;
  447. case 88:
  448. myFunctions.runChessEngine(21);
  449. break;
  450. case 67:
  451. myFunctions.runChessEngine(22);
  452. break;
  453. case 86:
  454. myFunctions.runChessEngine(23);
  455. break;
  456. case 66:
  457. myFunctions.runChessEngine(24);
  458. break;
  459. case 78:
  460. myFunctions.runChessEngine(25);
  461. break;
  462. case 77:
  463. myFunctions.runChessEngine(26);
  464. break;
  465. case 187:
  466. myFunctions.runChessEngine(100);
  467. break;
  468. }
  469. };
  470.  
  471. myFunctions.spinner = function() {
  472. if(isThinking == true){
  473. $('#overlay')[0].style.display = 'block';
  474. }
  475. if(isThinking == false) {
  476. $('#overlay')[0].style.display = 'none';
  477. }
  478. }
  479.  
  480. let dynamicStyles = null;
  481.  
  482. function addAnimation(body) {
  483. if (!dynamicStyles) {
  484. dynamicStyles = document.createElement('style');
  485. dynamicStyles.type = 'text/css';
  486. document.head.appendChild(dynamicStyles);
  487. }
  488.  
  489. dynamicStyles.sheet.insertRule(body, dynamicStyles.length);
  490. }
  491.  
  492. var loaded = false;
  493. myFunctions.loadEx = function(){
  494. try{
  495. var tmpStyle;
  496. var tmpDiv;
  497. board = $('chess-board')[0] || $('wc-chess-board')[0];
  498. if (!board) { // Check if board element is found
  499. console.warn("Chessboard element not found yet. Retrying...");
  500. return; // Exit and retry in the next interval
  501. }
  502. myVars.board = board;
  503.  
  504. var div = document.createElement('div')
  505. 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: Stockfish API</p><br><input type="checkbox" id="autoRun" name="autoRun" value="false">
  506. <label for="autoRun"> Enable auto run</label><br>
  507. <input type="checkbox" id="autoMove" name="autoMove" value="false">
  508. <label for="autoMove"> Enable auto move</label><br>
  509. <input type="number" id="timeDelayMin" name="timeDelayMin" min="0.1" value=0.1>
  510. <label for="timeDelayMin">Auto Run Delay Minimum(Seconds)</label><br>
  511. <input type="number" id="timeDelayMax" name="timeDelayMax" min="0.1" value=1>
  512. <label for="timeDelayMax">Auto Run Delay Maximum(Seconds)</label></div>`
  513. div.innerHTML = content;
  514. div.setAttribute('style','background-color:white; height:auto;');
  515. div.setAttribute('id','settingsContainer');
  516.  
  517. board.parentElement.parentElement.appendChild(div); //parentElement might be null, but board is checked above
  518.  
  519. //spinnerContainer
  520. var spinCont = document.createElement('div');
  521. spinCont.setAttribute('style','display:none;');
  522. spinCont.setAttribute('id','overlay');
  523. div.prepend(spinCont);
  524. //spinner
  525. var spinr = document.createElement('div')
  526. spinr.setAttribute('style',`
  527. margin: 0 auto;
  528. height: 64px;
  529. width: 64px;
  530. animation: rotate 0.8s infinite linear;
  531. border: 5px solid firebrick;
  532. border-right-color: transparent;
  533. border-radius: 50%;
  534. `);
  535. spinCont.appendChild(spinr);
  536. addAnimation(`@keyframes rotate {
  537. 0% {
  538. transform: rotate(0deg);
  539. }
  540. 100% {
  541. transform: rotate(360deg);
  542. }
  543. }`);
  544.  
  545.  
  546. //Reload Button
  547. var reSty = `
  548. #relButDiv {
  549. position: relative;
  550. text-align: center;
  551. margin: 0 0 8px 0;
  552. }
  553. #relEngBut {
  554. position: relative;
  555. color: #ffef85;
  556. background-color: #3cba2c;
  557. font-size: 19px;
  558. border: 1px solid #000000;
  559. padding: 15px 50px;
  560. letter-spacing: 1px;
  561. cursor: pointer
  562. }
  563. #relEngBut:hover {
  564. color: #000000;
  565. background-color: #ba1212;
  566. }
  567. #relEngBut:active {
  568. background-color: #ba1212;
  569. transform: translateY(4px);
  570. }`;
  571. var reBut = `<button type="button" name="reloadEngine" id="relEngBut" onclick="document.myFunctions.reloadChessEngine()">Reload Chess Engine</button>`;
  572. tmpDiv = document.createElement('div');
  573. var relButDiv = document.createElement('div');
  574. relButDiv.id = 'relButDiv';
  575. tmpDiv.innerHTML = reBut;
  576. reBut = tmpDiv.firstChild;
  577.  
  578. tmpStyle = document.createElement('style');
  579. tmpStyle.innerHTML = reSty;
  580. document.head.append(tmpStyle);
  581.  
  582. relButDiv.append(reBut);
  583. div.append(relButDiv);
  584.  
  585. // Issue Button
  586. var isBut = `<button type="button" name="isBut" onclick="window.confirm('Do you wish to go to my issue page?') ? document.location = 'https://forms.gle/UbcnhTutTX4aCrs48' : console.log('cancled')">Got An Issue/Bug?</button>`;
  587. tmpDiv = document.createElement('div');
  588. var isButDiv = document.createElement('div');
  589.  
  590. isButDiv.style = `
  591.  
  592. position: relative;
  593. text-align: center;
  594. margin: 0 0 8px 0;
  595.  
  596. `;
  597.  
  598. tmpDiv.innerHTML = isBut;
  599. isBut = tmpDiv.firstChild;
  600.  
  601. isBut.id = 'isBut';
  602. isBut.style = `
  603.  
  604. position: relative;
  605. color: #ffef85;
  606. background-color: #919191;
  607. font-size: 19px;
  608. border: 1px solid #000000;
  609. padding: 15px 50px;
  610. letter-spacing: 1px;
  611. cursor: pointer;
  612.  
  613. `;
  614.  
  615. isButDiv.append(isBut);
  616. div.append(isButDiv);
  617.  
  618. loaded = true;
  619. uiElementsLoaded = true; // Set flag after UI elements are created
  620. myFunctions.loadChessEngine(); // Load engine only after UI is ready
  621. } catch (error) {console.log(error)}
  622. }
  623.  
  624.  
  625. function other(delay){
  626. var endTime = Date.now() + delay;
  627. var timer = setInterval(()=>{
  628. if(Date.now() >= endTime){
  629. myFunctions.autoRun(lastValue);
  630. canGo = true;
  631. clearInterval(timer);
  632. }
  633. },10);
  634. }
  635.  
  636.  
  637. async function getVersion(){
  638. var GF = new GreasyFork;
  639. var code = await GF.get().script().code(460208);
  640. var version = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value;
  641.  
  642. if(currentVersion !== version){
  643. while(true){
  644. alert('UPDATE THIS SCRIPT IN ORDER TO PROCEED!');
  645. }
  646. }
  647. }
  648.  
  649.  
  650. const waitForChessBoard = setInterval(() => {
  651. if(loaded) {
  652. board = $('chess-board')[0] || $('wc-chess-board')[0];
  653. myVars.autoRun = $('#autoRun')[0].checked;
  654. myVars.autoMove = $('#autoMove')[0].checked;
  655. let minDel = parseInt($('#timeDelayMin')[0].value);
  656. let maxDel = parseInt($('#timeDelayMax')[0].value);
  657. myVars.delay = Math.random() * (maxDel - minDel) + minDel;
  658. myVars.isThinking = isThinking;
  659. myFunctions.spinner();
  660. if(board.game.getTurn() == board.game.getPlayingAs()){myTurn = true;} else {myTurn = false;}
  661. if (uiElementsLoaded && $('#depthText')[0] && $('#engineVersionText')[0]) { // Check UI elements before updating
  662. $('#depthText')[0].innerHTML = "Your Current Depth Is: <strong>"+lastValue+"</strong> (Stockfish " + currentStockfishVersion + ")";
  663. if (currentStockfishVersion !== "None" && currentStockfishVersion !== "Failed") {
  664. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>" + currentStockfishVersion + " Loaded</strong>";
  665. } else if (currentStockfishVersion === "Failed") {
  666. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>Failed to Load</strong></span>";
  667. } else {
  668. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Loading...</strong>";
  669. }
  670. }
  671.  
  672.  
  673. } else {
  674. myFunctions.loadEx();
  675. }
  676.  
  677. if(!engine.engine && currentStockfishVersion !== "Failed" && loaded){ // Prevent re-loading if already failed and after loadEx is done
  678. myFunctions.loadChessEngine();
  679. }
  680. if(myVars.autoRun == true && canGo == true && isThinking == false && myTurn){
  681. canGo = false;
  682. var currentDelay = myVars.delay != undefined ? myVars.delay * 1000 : 10;
  683. other(currentDelay);
  684. }
  685. }, 100);
  686. }
  687.  
  688. //Touching below may break the script
  689.  
  690. var isThinking = false
  691. var canGo = true;
  692. var myTurn = false;
  693. var board;
  694. var l = 'whoursie.com/4/5729456'; // This is likely related to the ad, and can be kept commented out if ads are removed.
  695.  
  696.  
  697. window.addEventListener("load", (event) => {
  698. let currentTime = Date.now();
  699. main();
  700. });

QingJ © 2025

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