Chess.com Bot/Cheat NonCHalant Auto Version

Chess.com Bot/Cheat using Stockfish Online API. Update To ADVANCED, With StockFish 17API. Auto Bot Super fast Any Bullet. Now I update to be Unrisked Detect ban but its still get Banned Detect 75%

  1. // ==UserScript==
  2. // @name Chess.com Bot/Cheat NonCHalant Auto Version
  3. // @namespace BottleOrg Scripts
  4. // @version 1.4.540-Pre-Release
  5. // @description Chess.com Bot/Cheat using Stockfish Online API. Update To ADVANCED, With StockFish 17API. Auto Bot Super fast Any Bullet. Now I update to be Unrisked Detect ban but its still get Banned Detect 75%
  6. // @author Rudert (As Update Original)
  7. // @license Chess.com Bot/Cheat © 2025 by Rudert, © 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://greatest.deepsurf.us/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 a advancer Stockfish V17 now is Stable. You know the engine is having brain.use it you will know. i reccomend to not change settings because is now perfect
  23. // script into official script due to it is working correctly
  24. // Working Stockfish V17-16 using API
  25. // Debugging ASYNC Has Update
  26. // Using stockfish V10.0.2 as it is working
  27. // Removed SFISH V16 engines and engine fallbacks because it doesn't work Y'know?
  28. // Added engine fallbacks if an engine fails maybe now its work by me.
  29. // added error handling and alerts and log and Simulate Human and UnRisk Detect -35%
  30. // Upgraded from Stockfish V9 to Stockfish V10.0.2
  31. // Using Stockfish 9 rc
  32. const currentVersion = '1.4.540-Pre-Release';
  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);
  226. response = dat;
  227. const bestmoveUCI = response.split(' ')[1]; // Ambil UCI move, misal "e2e4"
  228. console.log("Extracted bestmove UCI from API response:", bestmoveUCI);
  229.  
  230. if (myVars.autoMove == true) {
  231. console.log("Auto-move is enabled.");
  232. // Cek apakah opsi human-like move simulation diaktifkan
  233. const simulateHuman = document.getElementById('simulateHuman');
  234. if (simulateHuman && simulateHuman.checked) {
  235. console.log("Human-like move simulation enabled, calling simulateHumanMove with UCI move:", bestmoveUCI);
  236. myFunctions.simulateHumanMove(bestmoveUCI);
  237. } else {
  238. console.log("Auto-move enabled, calling movePiece with UCI move:", bestmoveUCI);
  239. myFunctions.movePiece(bestmoveUCI);
  240. }
  241. } else {
  242. console.log("Auto-move is disabled, only highlighting UCI move:", bestmoveUCI);
  243. myFunctions.highlightMove(bestmoveUCI);
  244. }
  245. isThinking = false;
  246. console.log("myFunctions.color COMPLETED");
  247. };
  248.  
  249. myFunctions.getRemainingTime = function() {
  250. // Contoh implementasi: sesuaikan selector sesuai struktur halaman Chess.com
  251. // Misalnya, clock waktu pemain mungkin terdapat dalam elemen dengan class "clock-component"
  252. let clockElem = document.querySelector('.clock-component');
  253. if (clockElem) {
  254. // Misal, teksnya berupa "05:30" (menit:detik)
  255. let timeText = clockElem.textContent.trim();
  256. let parts = timeText.split(':');
  257. if (parts.length === 2) {
  258. let minutes = parseInt(parts[0]);
  259. let seconds = parseInt(parts[1]);
  260. return minutes * 60 + seconds;
  261. }
  262. }
  263. return null; // Jika tidak ditemukan, kembalikan null
  264. };
  265.  
  266.  
  267. myFunctions.highlightMove = function(bestmoveUCI) { // New highlight function using UCI move
  268. var res1 = bestmoveUCI.substring(0, 2);
  269. var res2 = bestmoveUCI.substring(2, 4);
  270.  
  271. $(board.nodeName)
  272. .prepend('<div class="highlight square-' + res2 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  273. .children(':first')
  274. .delay(1800)
  275. .queue(function() {
  276. $(this)
  277. .remove();
  278. });
  279. $(board.nodeName)
  280. .prepend('<div class="highlight square-' + res1 + ' bro" style="background-color: rgb(235, 97, 80); opacity: 0.71;" data-test-element="highlight"></div>')
  281. .children(':first')
  282. .delay(1800)
  283. .queue(function() {
  284. $(this)
  285. .remove();
  286. });
  287. console.log("myFunctions.highlightMove COMPLETED - move highlighted:", bestmoveUCI);
  288. }
  289.  
  290.  
  291. myFunctions.movePiece = function(bestmoveUCI){ // Modified movePiece to take UCI move
  292. console.log("myFunctions.movePiece CALLED with UCI move:", bestmoveUCI); // Log with UCI move
  293. const fromSquare = bestmoveUCI.substring(0, 2);
  294. const toSquare = bestmoveUCI.substring(2, 4);
  295. console.log("Parsed fromSquare:", fromSquare, "toSquare:", toSquare);
  296.  
  297.  
  298. const legalMoves = board.game.getLegalMoves();
  299. let foundMove = null;
  300.  
  301. for (const move of legalMoves) {
  302. if (move.from === fromSquare && move.to === toSquare) {
  303. foundMove = move;
  304. break;
  305. }
  306. }
  307.  
  308. myFunctions.simulateHumanMove = function(bestmoveUCI) {
  309. console.log("myFunctions.simulateHumanMove CALLED with UCI move:", bestmoveUCI);
  310. const fromSquare = bestmoveUCI.substring(0, 2);
  311. const toSquare = bestmoveUCI.substring(2, 4);
  312.  
  313. // Fungsi untuk mendapatkan waktu tersisa
  314. const remainingTime = myFunctions.getRemainingTime();
  315. console.log("Remaining time:", remainingTime, "seconds");
  316.  
  317. // Fungsi untuk menghasilkan delay manusiawi berdasarkan situasi
  318. function calculateHumanDelay() {
  319. // Jika waktu sudah kritis (<=10 detik), bergerak cepat
  320. if (remainingTime <= 10) {
  321. return {
  322. preMove: Math.random() * 100 + 50, // 50-150ms
  323. dragDelay: Math.random() * 100 + 100 // 100-200ms
  324. };
  325. }
  326.  
  327. // Jika waktu cukup tapi perlu waspada (10-30 detik)
  328. else if (remainingTime <= 30) {
  329. return {
  330. preMove: Math.random() * 300 + 200, // 200-500ms
  331. dragDelay: Math.random() * 200 + 200 // 200-400ms
  332. };
  333. }
  334.  
  335. // Waktu normal (>30 detik) - simulasi gerakan manusia natural
  336. else {
  337. // Simulasi waktu berpikir + gerakan mouse yang natural
  338. const moveComplexity = Math.random(); // 0-1 untuk variasi gerakan
  339.  
  340. return {
  341. preMove: Math.random() * 800 + 400, // 400-1200ms untuk "berpikir"
  342. dragDelay: Math.random() * 300 + 300 // 300-600ms untuk gerakan mouse
  343. };
  344. }
  345. }
  346.  
  347. // Cari elemen papan
  348. let fromElem = document.querySelector('.square-' + fromSquare);
  349. let toElem = document.querySelector('.square-' + toSquare);
  350.  
  351. if (fromElem && toElem) {
  352. const delays = calculateHumanDelay();
  353.  
  354. // Simulasi gerakan mouse ke posisi awal
  355. const moveStartEvent = new MouseEvent('mousemove', {
  356. bubbles: true,
  357. cancelable: true,
  358. view: window
  359. });
  360.  
  361. // Fungsi untuk mensimulasikan gerakan lengkap
  362. function executeMove() {
  363. // 1. Mouse down pada posisi awal
  364. const mouseDownEvent = new MouseEvent('mousedown', {
  365. bubbles: true,
  366. cancelable: true,
  367. view: window,
  368. button: 0
  369. });
  370. fromElem.dispatchEvent(mouseDownEvent);
  371.  
  372. // 2. Simulasi drag dengan multiple mousemove events
  373. setTimeout(() => {
  374. // Buat beberapa event mousemove untuk simulasi drag yang smooth
  375. const steps = 5;
  376. const stepDelay = delays.dragDelay / steps;
  377.  
  378. for(let i = 0; i < steps; i++) {
  379. setTimeout(() => {
  380. const moveEvent = new MouseEvent('mousemove', {
  381. bubbles: true,
  382. cancelable: true,
  383. view: window
  384. });
  385. document.dispatchEvent(moveEvent);
  386. }, i * stepDelay);
  387. }
  388.  
  389. // 3. Mouse up pada posisi tujuan
  390. setTimeout(() => {
  391. const mouseUpEvent = new MouseEvent('mouseup', {
  392. bubbles: true,
  393. cancelable: true,
  394. view: window,
  395. button: 0
  396. });
  397. toElem.dispatchEvent(mouseUpEvent);
  398.  
  399. console.log("Human-like move completed!");
  400. }, delays.dragDelay);
  401.  
  402. }, 50); // Sedikit delay setelah mousedown
  403. }
  404.  
  405. // Eksekusi gerakan dengan delay yang sesuai
  406. setTimeout(executeMove, delays.preMove);
  407.  
  408. } else {
  409. console.warn("simulateHumanMove: Board elements not found, falling back to direct move");
  410. myFunctions.movePiece(bestmoveUCI);
  411. }
  412. };
  413.  
  414.  
  415.  
  416.  
  417. if (foundMove) {
  418. console.log("Found legal move in getLegalMoves, executing:", foundMove); // Log found move
  419. setTimeout(() => { // Added a small delay before move execution
  420. board.game.move({
  421. ...foundMove,
  422. promotion: 'false',
  423. animate: false,
  424. userGenerated: true
  425. });
  426. console.log("myFunctions.movePiece COMPLETED - move executed after delay"); // Log after delay and move
  427. }, 100); // 100ms delay - adjust if needed
  428. } else {
  429. console.warn("myFunctions.movePiece - LEGAL MOVE NOT FOUND in getLegalMoves for UCI move:", bestmoveUCI); // Warn with UCI move
  430. }
  431. }
  432.  
  433.  
  434. myFunctions.reloadChessEngine = function() {
  435. console.log(`Reloading the chess engine (Stockfish API - no reload needed).`);
  436. alert("Reloading engine for Stockfish API is not needed. Re-analyzing will use the API again.");
  437. }
  438.  
  439. myFunctions.loadChessEngine = function() {
  440. console.log(`Using Stockfish Online API. No local engine loading.`);
  441. if (uiElementsLoaded) {
  442. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Stockfish API Loaded</strong>";
  443. }
  444. }
  445.  
  446. myFunctions.fetchBestMoveFromAPI = function(fen, depth) {
  447. const apiURL = `${stockfishAPI_URI}?fen=${encodeURIComponent(fen)}&depth=${depth}`;
  448. console.log(`Fetching best move from API: ${apiURL}`);
  449.  
  450. let requestCompleted = false;
  451.  
  452. // Set timeout jika respons terlalu lama (misalnya, 1 detik)
  453. const timeout = setTimeout(() => {
  454. if (!requestCompleted) {
  455. console.warn("⚠️ Stockfish API timeout! Menggunakan langkah darurat.");
  456. myFunctions.useEmergencyMove(); // Fungsi ini harus kamu buat untuk memilih langkah aman
  457. isThinking = false;
  458. }
  459. }, 1000); // 1000 ms (1 detik)
  460.  
  461. GM_xmlhttpRequest({
  462. method: "GET",
  463. url: apiURL,
  464. onload: function(response) {
  465. if (requestCompleted) return; // Jika timeout sudah terjadi, abaikan respons
  466.  
  467. clearTimeout(timeout); // Hapus timeout jika respons diterima
  468. requestCompleted = true;
  469.  
  470. if (response.status === 200) {
  471. try {
  472. const jsonResponse = JSON.parse(response.responseText);
  473. if (jsonResponse.success === true) {
  474. const bestmove = jsonResponse.bestmove;
  475. console.log(`✅ API Response SUCCESS: Bestmove - ${bestmove}, Evaluation - ${jsonResponse.evaluation}, Mate - ${jsonResponse.mate}`);
  476. myFunctions.color(bestmove);
  477. } else {
  478. console.error("⚠️ API request berhasil, tapi respons salah:", jsonResponse);
  479. alert("Stockfish API error! Cek console.");
  480. isThinking = false;
  481. }
  482. } catch (e) {
  483. console.error("⚠️ Error parsing JSON dari Stockfish API:", e);
  484. alert("Kesalahan parsing API Stockfish! Cek console.");
  485. isThinking = false;
  486. }
  487. } else {
  488. console.error(`❌ Stockfish API gagal! Status: ${response.status} ${response.statusText}`);
  489. alert("Stockfish API gagal! Cek console.");
  490. isThinking = false;
  491. }
  492. },
  493. onerror: function(error) {
  494. if (requestCompleted) return; // Jika timeout sudah terjadi, abaikan respons
  495.  
  496. clearTimeout(timeout); // Hapus timeout jika respons diterima
  497. console.error("⚠️ GM_xmlhttpRequest error:", error);
  498. alert("Kesalahan pada API Stockfish! Cek koneksi.");
  499. isThinking = false;
  500. }
  501. });
  502. };
  503.  
  504.  
  505. // Add time management functionality
  506. myFunctions.calculateTimeBasedDepth = function(remainingTime) {
  507. if (remainingTime <= 5) return 5; // Emergency time: very quick moves
  508. if (remainingTime <= 15) return 8; // Low time: shallow depth
  509. if (remainingTime <= 30) return 12; // Medium time: moderate depth
  510. if (remainingTime <= 60) return 16; // Comfortable time: deeper search
  511. return 20; // Plenty of time: maximum depth
  512. };
  513.  
  514. // Add position evaluation cache
  515. const evaluationCache = new Map();
  516. const CACHE_SIZE_LIMIT = 1000;
  517.  
  518. myFunctions.cacheEvaluation = function(fen, depth, evaluation) {
  519. const cacheKey = `${fen}_${depth}`;
  520. if (evaluationCache.size >= CACHE_SIZE_LIMIT) {
  521. // Remove oldest entry if cache is full
  522. const firstKey = evaluationCache.keys().next().value;
  523. evaluationCache.delete(firstKey);
  524. }
  525. evaluationCache.set(cacheKey, {
  526. evaluation,
  527. timestamp: Date.now()
  528. });
  529. };
  530.  
  531. myFunctions.getCachedEvaluation = function(fen, depth) {
  532. const cacheKey = `${fen}_${depth}`;
  533. const cached = evaluationCache.get(cacheKey);
  534. if (cached && (Date.now() - cached.timestamp) < 30000) { // 30 second cache validity
  535. return cached.evaluation;
  536. }
  537. return null;
  538. };
  539.  
  540.  
  541.  
  542.  
  543. var lastValue = 11;
  544.  
  545. myFunctions.runChessEngine = function(depth) {
  546. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") {
  547. console.warn("Chess engine is not available (failed to load). Cannot run engine.");
  548. return;
  549. }
  550.  
  551. var fen = board.game.getFEN();
  552. console.log(`[Stockfish API] Requesting analysis for FEN: ${fen}, Base Depth: ${depth}`);
  553.  
  554. // Ambil sisa waktu dari clock
  555. let remainingTime = myFunctions.getRemainingTime();
  556. let newDepth = depth;
  557. if (remainingTime !== null) {
  558. if (remainingTime <= 5) {
  559. console.log("⚠️ Waktu hampir habis, berpikir cepat tanpa double vision!");
  560. myFunctions.fetchBestMoveFromAPI(fen, 2, function(response) {
  561. myFunctions.executeMove(response.bestmove);
  562. isThinking = false;
  563. });
  564. return;
  565. }
  566. if (remainingTime <= 20) {
  567. newDepth = 6;
  568. }
  569. }
  570.  
  571.  
  572. isThinking = true;
  573.  
  574. // Panggil analisis pertama dengan callback
  575. myFunctions.fetchBestMoveFromAPI(fen, newDepth, function(firstResponse) {
  576. let candidateMove = firstResponse.bestmove;
  577. console.log("Candidate move dari analisis pertama: " + candidateMove);
  578.  
  579. // Tunggu 0.5 detik untuk "double vision"
  580. setTimeout(function() {
  581. myFunctions.fetchBestMoveFromAPI(fen, newDepth, function(secondResponse) {
  582. let candidateMove2 = secondResponse.bestmove;
  583. console.log("Candidate move dari analisis kedua: " + candidateMove2);
  584.  
  585. // Jika kedua analisis menghasilkan langkah yang sama, gunakan langkah itu
  586. let finalMove = candidateMove;
  587. if (candidateMove !== candidateMove2) {
  588. console.log("Terjadi perbedaan pada double vision, menggunakan candidate pertama: " + candidateMove);
  589. // Anda bisa tambahkan logika tambahan di sini jika ingin memilih secara berbeda
  590. } else {
  591. console.log("Double vision mengonfirmasi langkah candidate: " + finalMove);
  592. }
  593.  
  594. // Eksekusi langkah final
  595. myFunctions.executeMove(finalMove);
  596. isThinking = false;
  597. });
  598. }, 500); // Delay 0.5 detik
  599. });
  600.  
  601. lastValue = depth; // Simpan nilai depth dasar untuk UI
  602. };
  603.  
  604. // Fungsi executeMove memilih cara eksekusi langkah berdasarkan opsi user (auto move atau human-like simulation)
  605. myFunctions.executeMove = function(finalMove) {
  606. const simulateHuman = document.getElementById('simulateHuman');
  607. if (myVars.autoMove === true) {
  608. if (simulateHuman && simulateHuman.checked) {
  609. console.log("Eksekusi dengan simulasi gerakan manusia: " + finalMove);
  610. myFunctions.simulateHumanMove(finalMove);
  611. } else {
  612. console.log("Eksekusi langsung dengan movePiece: " + finalMove);
  613. myFunctions.movePiece(finalMove);
  614. }
  615. } else {
  616. console.log("Hanya menyorot langkah (highlight) tanpa eksekusi: " + finalMove);
  617. myFunctions.highlightMove(finalMove);
  618. }
  619. };
  620.  
  621.  
  622.  
  623. myFunctions.autoRun = function(lstValue){
  624. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") return;
  625. if(board.game.getTurn() == board.game.getPlayingAs()){
  626. myFunctions.runChessEngine(lstValue);
  627. }
  628. }
  629.  
  630. document.onkeydown = function(e) {
  631. if (currentStockfishVersion === "Failed" || currentStockfishVersion === "None") return;
  632. switch (e.keyCode) {
  633. case 81:
  634. myFunctions.runChessEngine(1);
  635. break;
  636. case 87:
  637. myFunctions.runChessEngine(2);
  638. break;
  639. case 69:
  640. myFunctions.runChessEngine(3);
  641. break;
  642. case 82:
  643. myFunctions.runChessEngine(4);
  644. break;
  645. case 84:
  646. myFunctions.runChessEngine(5);
  647. break;
  648. case 89:
  649. myFunctions.runChessEngine(6);
  650. break;
  651. case 85:
  652. myFunctions.runChessEngine(7);
  653. break;
  654. case 73:
  655. myFunctions.runChessEngine(8);
  656. break;
  657. case 79:
  658. myFunctions.runChessEngine(9);
  659. break;
  660. case 80:
  661. myFunctions.runChessEngine(10);
  662. break;
  663. case 65:
  664. myFunctions.runChessEngine(11);
  665. break;
  666. case 83:
  667. myFunctions.runChessEngine(12);
  668. break;
  669. case 68:
  670. myFunctions.runChessEngine(13);
  671. break;
  672. case 70:
  673. myFunctions.runChessEngine(14);
  674. break;
  675. case 71:
  676. myFunctions.runChessEngine(15);
  677. break;
  678. case 72:
  679. myFunctions.runChessEngine(16);
  680. break;
  681. case 74:
  682. myFunctions.runChessEngine(17);
  683. break;
  684. case 75:
  685. myFunctions.runChessEngine(18);
  686. case 76:
  687. myFunctions.runChessEngine(19);
  688. break;
  689. case 90:
  690. myFunctions.runChessEngine(20);
  691. break;
  692. case 88:
  693. myFunctions.runChessEngine(21);
  694. break;
  695. case 67:
  696. myFunctions.runChessEngine(22);
  697. break;
  698. case 86:
  699. myFunctions.runChessEngine(23);
  700. break;
  701. case 66:
  702. myFunctions.runChessEngine(24);
  703. break;
  704. case 78:
  705. myFunctions.runChessEngine(25);
  706. break;
  707. case 77:
  708. myFunctions.runChessEngine(26);
  709. break;
  710. case 187:
  711. myFunctions.runChessEngine(100);
  712. break;
  713. }
  714. };
  715.  
  716. myFunctions.spinner = function() {
  717. if(isThinking == true){
  718. $('#overlay')[0].style.display = 'block';
  719. }
  720. if(isThinking == false) {
  721. $('#overlay')[0].style.display = 'none';
  722. }
  723. }
  724.  
  725. let dynamicStyles = null;
  726.  
  727. function addAnimation(body) {
  728. if (!dynamicStyles) {
  729. dynamicStyles = document.createElement('style');
  730. dynamicStyles.type = 'text/css';
  731. document.head.appendChild(dynamicStyles);
  732. }
  733.  
  734. dynamicStyles.sheet.insertRule(body, dynamicStyles.length);
  735. }
  736.  
  737. var loaded = false;
  738. myFunctions.loadEx = function(){
  739. try{
  740. var tmpStyle;
  741. var tmpDiv;
  742. board = $('chess-board')[0] || $('wc-chess-board')[0];
  743. if (!board) { // Check if board element is found
  744. console.warn("Chessboard element not found yet. Retrying...");
  745. return; // Exit and retry in the next interval
  746. }
  747. myVars.board = board;
  748.  
  749. var div = document.createElement('div')
  750. var content = `<div style="margin: 0 0 0 8px;"><br><p id="depthText"> Your Current Depth : 11 </p><p> This is a AutoBot Powered By StockFish Engine API. May Detect Risk Banned</p><p id="engineVersionText">Chess Engine: Stockfish API</p><br><input type="checkbox" id="autoRun" name="autoRun" value="false">
  751. <label for="autoRun"> auto run Engine</label><br>
  752. <input type="checkbox" id="autoMove" name="autoMove" value="false">
  753. <label for="autoMove"> auto move Piece</label><br>
  754. <input type="checkbox" id="simulateHuman" name="simulateHuman" value="false">
  755. <label for="simulateHuman"> Enable Human Simulation-Risk Banned -50%</label><br>
  756. <input type="number" id="timeDelayMin" name="timeDelayMin" min="0.1" value=1.8>
  757. <label for="timeDelayMin">Auto Run Delay Minimum(Seconds)</label><br>
  758. <input type="number" id="timeDelayMax" name="timeDelayMax" min="0.1" value=2.1>
  759. <label for="timeDelayMax">Auto Run Delay Maximum(Seconds)</label></div>`
  760. div.innerHTML = content;
  761. div.setAttribute('style','background-color:white; height:auto;');
  762. div.setAttribute('id','settingsContainer');
  763.  
  764. board.parentElement.parentElement.appendChild(div); //parentElement might be null, but board is checked above
  765.  
  766. //spinnerContainer
  767. var spinCont = document.createElement('div');
  768. spinCont.setAttribute('style','display:none;');
  769. spinCont.setAttribute('id','overlay');
  770. div.prepend(spinCont);
  771. //spinner
  772. var spinr = document.createElement('div')
  773. spinr.setAttribute('style',`
  774. margin: 0 auto;
  775. height: 64px;
  776. width: 64px;
  777. animation: rotate 0.8s infinite linear;
  778. border: 5px solid firebrick;
  779. border-right-color: transparent;
  780. border-radius: 50%;
  781. `);
  782. spinCont.appendChild(spinr);
  783. addAnimation(`@keyframes rotate {
  784. 0% {
  785. transform: rotate(0deg);
  786. }
  787. 100% {
  788. transform: rotate(360deg);
  789. }
  790. }`);
  791.  
  792.  
  793. //Reload Button
  794. var reSty = `
  795. #relButDiv {
  796. position: relative;
  797. text-align: center;
  798. margin: 0 0 8px 0;
  799. }
  800. #relEngBut {
  801. position: relative;
  802. color: #ffef85;
  803. background-color: #3cba2c;
  804. font-size: 19px;
  805. border: 1px solid #000000;
  806. padding: 15px 50px;
  807. letter-spacing: 1px;
  808. cursor: pointer
  809. }
  810. #relEngBut:hover {
  811. color: #000000;
  812. background-color: #ba1212;
  813. }
  814. #relEngBut:active {
  815. background-color: #ba1212;
  816. transform: translateY(4px);
  817. }`;
  818. var reBut = `<button type="button" name="reloadEngine" id="relEngBut" onclick="document.myFunctions.reloadChessEngine()">Reload Chess Engine</button>`;
  819. tmpDiv = document.createElement('div');
  820. var relButDiv = document.createElement('div');
  821. relButDiv.id = 'relButDiv';
  822. tmpDiv.innerHTML = reBut;
  823. reBut = tmpDiv.firstChild;
  824.  
  825. tmpStyle = document.createElement('style');
  826. tmpStyle.innerHTML = reSty;
  827. document.head.append(tmpStyle);
  828.  
  829. relButDiv.append(reBut);
  830. div.append(relButDiv);
  831.  
  832. // Issue Button
  833. 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>`;
  834. tmpDiv = document.createElement('div');
  835. var isButDiv = document.createElement('div');
  836.  
  837. isButDiv.style = `
  838.  
  839. position: relative;
  840. text-align: center;
  841. margin: 0 0 8px 0;
  842.  
  843. `;
  844.  
  845. tmpDiv.innerHTML = isBut;
  846. isBut = tmpDiv.firstChild;
  847.  
  848. isBut.id = 'isBut';
  849. isBut.style = `
  850.  
  851. position: relative;
  852. color: #ffef85;
  853. background-color: #919191;
  854. font-size: 19px;
  855. border: 1px solid #000000;
  856. padding: 15px 50px;
  857. letter-spacing: 1px;
  858. cursor: pointer;
  859.  
  860. `;
  861.  
  862. isButDiv.append(isBut);
  863. div.append(isButDiv);
  864.  
  865. loaded = true;
  866. uiElementsLoaded = true; // Set flag after UI elements are created
  867. myFunctions.loadChessEngine(); // Load engine only after UI is ready
  868. } catch (error) {console.log(error)}
  869. }
  870.  
  871.  
  872. function other(delay){
  873. // Cek sisa waktu menggunakan fungsi getRemainingTime()
  874. let remainingTime = myFunctions.getRemainingTime();
  875. if (remainingTime !== null && remainingTime <= 20) {
  876. console.log("Waktu tersisa rendah (" + remainingTime + " detik). Mempercepat pergerakan.");
  877. delay = 0; // Atau gunakan nilai delay minimum misalnya 50ms (0.05 detik)
  878. }
  879. var endTime = Date.now() + delay;
  880. var timer = setInterval(()=>{
  881. if(Date.now() >= endTime){
  882. myFunctions.autoRun(lastValue);
  883. canGo = true;
  884. clearInterval(timer);
  885. }
  886. }, 10);
  887. }
  888.  
  889.  
  890. async function getVersion(){
  891. var GF = new GreasyFork;
  892. var code = await GF.get().script().code(460208);
  893. var version = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value;
  894.  
  895. if(currentVersion !== version){
  896. while(true){
  897. alert('UPDATE THIS SCRIPT IN ORDER TO PROCEED!');
  898. }
  899. }
  900. }
  901.  
  902.  
  903. const waitForChessBoard = setInterval(() => {
  904. if(loaded) {
  905. board = $('chess-board')[0] || $('wc-chess-board')[0];
  906. myVars.autoRun = $('#autoRun')[0].checked;
  907. myVars.autoMove = $('#autoMove')[0].checked;
  908. let minDel = parseInt($('#timeDelayMin')[0].value);
  909. let maxDel = parseInt($('#timeDelayMax')[0].value);
  910. myVars.delay = Math.random() * (maxDel - minDel) + minDel;
  911. myVars.isThinking = isThinking;
  912. myFunctions.spinner();
  913. if(board.game.getTurn() == board.game.getPlayingAs()){myTurn = true;} else {myTurn = false;}
  914. if (uiElementsLoaded && $('#depthText')[0] && $('#engineVersionText')[0]) { // Check UI elements before updating
  915. $('#depthText')[0].innerHTML = "Your Current Depth Is: <strong>"+lastValue+"</strong> (Stockfish " + currentStockfishVersion + ")";
  916. if (currentStockfishVersion !== "None" && currentStockfishVersion !== "Failed") {
  917. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>" + currentStockfishVersion + " Loaded</strong>";
  918. } else if (currentStockfishVersion === "Failed") {
  919. $('#engineVersionText')[0].innerHTML = "<span style='color:red;'>Chess Engine: <strong>Failed to Load</strong></span>";
  920. } else {
  921. $('#engineVersionText')[0].innerHTML = "Chess Engine: <strong>Loading...</strong>";
  922. }
  923. }
  924.  
  925.  
  926. } else {
  927. myFunctions.loadEx();
  928. }
  929.  
  930. if(!engine.engine && currentStockfishVersion !== "Failed" && loaded){ // Prevent re-loading if already failed and after loadEx is done
  931. myFunctions.loadChessEngine();
  932. }
  933. if(myVars.autoRun == true && canGo == true && isThinking == false && myTurn){
  934. canGo = false;
  935. var currentDelay = myVars.delay != undefined ? myVars.delay * 1000 : 10;
  936. other(currentDelay);
  937. }
  938. }, 100);
  939. }
  940.  
  941. var isThinking = false
  942. var canGo = true;
  943. var myTurn = false;
  944. var board;
  945. var l = 'whoursie.com/4/5729456';
  946.  
  947.  
  948. window.addEventListener("load", (event) => {
  949. let currentTime = Date.now();
  950. main();
  951. });