lotocamion

Anti Bot link Solver 4 image

Jul 31st, 2022
4,175
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.95 KB | None | 0 0
  1. // ==UserScript==
  2. // @name AB Links Solver
  3. // @namespace ABLinks Solver(Solves Ablinks images)
  4. // @version 3.0
  5. // @description Solves AbLink images
  6. // @author Banned
  7. // @match *://*/*
  8. // @noframes
  9. // @connect https://unpkg.com
  10. // @require https://unpkg.com/opencv.js@1.2.1/opencv.js
  11. // @require https://unpkg.com/jimp@0.5.2/browser/lib/jimp.min.js
  12. // @require https://unpkg.com/tesseract.js@2.1.5/dist/tesseract.min.js
  13. // @grant GM_xmlhttpRequest
  14. // @antifeature referral-link
  15. // ==/UserScript==
  16.  
  17. // This script solves Ablink images with words and having 4 different options
  18. // Number identification logic for comparing words and numbers will be implemented in the next versions
  19. // Accuracy can be improved by adding more filters for different types of images and fonts
  20. // This script does not have a global matcher, you will need to add the websites in the matcher section manually, till
  21. // all the solutions are implemented
  22. // Your account will be locked for 24 hours, if 3 incorrect solutions are provided consecutively in 10 minutes. (This is the default but depends on website)
  23. // To avoid this add a rotator to change the website whenever an incorrect solution is provided.
  24.  
  25. // TODO: Refactor Code
  26. (function() {
  27. 'use strict';
  28.  
  29. var questions = [];
  30. var questionImages = [];
  31. var questionImage = "";
  32. var questionImageSource = "";
  33. var numericWordArray = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
  34.  
  35. async function waitForImage(imgElement) {
  36. return await new Promise(res => {
  37. if (imgElement.complete) {
  38. return res();
  39. }
  40. imgElement.onload = () => res();
  41. imgElement.onerror = () => res();
  42. });
  43. }
  44.  
  45. async function toDataURL(c){
  46. return await new Promise(function(resolve){
  47. const dataURI = c.toDataURL('image/png');
  48. return resolve(dataURI);
  49. })
  50.  
  51. }
  52.  
  53. async function removeNoiseUsingImageData(imgdata,width,height,threshold){
  54. return await new Promise(function(resolve){
  55. var noiseCount =0;
  56. var noiseRowStart = 0;
  57. for (let column = 0; column < width; column++) {
  58. let count = 0;
  59. for (let row = 0; row < height; row++) {
  60.  
  61. let position = row * width + column;
  62. let pixelAtPosition = imgdata[position];
  63.  
  64. //Remove noise from first row and last row
  65. if(row == 0 || row == height-1){
  66. imgdata[position] = 0xFFFFFFFF;
  67. }
  68.  
  69. if (pixelAtPosition == 0xFF000000){
  70. if(noiseCount == 0){
  71. noiseRowStart = row;
  72. }
  73. noiseCount++;
  74. }else{
  75. //Define the number of consecutive pixels to be considered as noise
  76. if(noiseCount > 0 && noiseCount <= threshold){
  77. //Start from noiseRow till current row and remove noise
  78. while(noiseRowStart < row){
  79. let noisePosition = noiseRowStart * width + column;
  80. imgdata[noisePosition] = 0xFFFFFFFF;
  81. noiseRowStart++;
  82. }
  83. }
  84. noiseCount =0;
  85. }
  86. }
  87. }
  88. return resolve(imgdata);
  89. })
  90.  
  91. }
  92.  
  93. async function imageUsingOCRAntibotQuestion(image) {
  94.  
  95. if (!image || !image.src) {
  96. console.log("No images found");
  97. return;
  98. }
  99.  
  100. var img = new Image();
  101. img.crossOrigin = 'anonymous';
  102. img.src = image.src
  103. await waitForImage(img);
  104. var c = document.createElement("canvas")
  105. c.width = img.width;
  106. c.height = img.height;
  107. var ctx = c.getContext("2d");
  108. await ctx.drawImage(img, 0, 0);
  109.  
  110. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  111. var data = await imageData.data;
  112. // console.log(data);
  113.  
  114. await ctx.putImageData(imageData, 0, 0);
  115.  
  116. let src = await cv.imread(c);
  117. let dst = new cv.Mat();
  118. let ksize = new cv.Size(3, 3);
  119. // You can try more different parameters
  120. await cv.GaussianBlur(src, dst, ksize, 0, 0, cv.BORDER_DEFAULT);
  121.  
  122. await cv.imshow(c, dst);
  123. src.delete();
  124. dst.delete();
  125.  
  126. //console.log( c.toDataURL());
  127. let imageDataURI = await toDataURL(c);
  128. return await (imageUsingOCR(imageDataURI));
  129. }
  130.  
  131. async function imageUsingOCRAntibotLowValues(image) {
  132.  
  133. if (!image || !image.src) {
  134. console.log("No images found");
  135. return;
  136. }
  137.  
  138. var img = new Image();
  139. img.crossOrigin = 'anonymous';
  140. img.src = image.src;
  141. await waitForImage(img);
  142.  
  143. var c = document.createElement("canvas")
  144. c.width = img.width;
  145. c.height = img.height;
  146. var ctx = c.getContext("2d");
  147. await ctx.drawImage(img, 0, 0);
  148. //console.log(await c.toDataURL());
  149. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  150. var data = await imageData.data;
  151.  
  152. //Make the image visible
  153. for (let i = 0; i < data.length; i += 4) {
  154.  
  155. if ((data[i] < 100 || data[i + 1] < 100 || data[i + 2] < 100) && data[i+3]>0) {
  156. data[i] = 0;
  157. data[i + 1] = 0;
  158. data[i + 2] = 0;
  159. } else {
  160. data[i] = 255;
  161. data[i + 1] = 255;
  162. data[i + 2] = 255;
  163. }
  164. data[i + 3] = 255;
  165. }
  166.  
  167. //Remove Noise from Image
  168. var imgdata = await new Uint32Array(data.buffer);
  169.  
  170. imgdata = await removeNoiseUsingImageData(imgdata,c.width,c.height,1);
  171.  
  172. await ctx.putImageData(imageData, 0, 0);
  173.  
  174. //console.log( c.toDataURL());
  175. let imageDataURI = await toDataURL(c);
  176. return await (imageUsingOCR(imageDataURI));
  177. }
  178.  
  179. async function imageUsingOCRAntibotHighValues(image) {
  180.  
  181. if (!image || !image.src) {
  182. console.log("No images found");
  183. return;
  184. }
  185.  
  186. var img = new Image();
  187. img.crossOrigin = 'anonymous';
  188. img.src = image.src;
  189. await waitForImage(img);
  190.  
  191. var c = document.createElement("canvas")
  192. c.width = img.width;
  193. c.height = img.height;
  194. var ctx = c.getContext("2d");
  195. await ctx.drawImage(img, 0, 0);
  196. //console.log(await c.toDataURL());
  197. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  198. var data = await imageData.data;
  199.  
  200. //Make the image visible
  201. for (let i = 0; i < data.length; i += 4) {
  202.  
  203. if ((data[i] > 100 || data[i + 1] > 100 || data[i + 2] > 100) && data[i + 3] > 0) {
  204. data[i] = 0;
  205. data[i + 1] = 0;
  206. data[i + 2] = 0;
  207.  
  208. } else {
  209.  
  210. data[i] = 255;
  211. data[i + 1] = 255;
  212. data[i + 2] = 255;
  213. }
  214. data[i + 3] = 255;
  215. }
  216.  
  217. //Remove Noise from Image
  218. var imgdata = await new Uint32Array(data.buffer);
  219.  
  220. imgdata = await removeNoiseUsingImageData(imgdata,c.width,c.height,1);
  221.  
  222.  
  223. await ctx.putImageData(imageData, 0, 0);
  224. //console.log( c.toDataURL());
  225. let imageDataURI = await toDataURL(c);
  226. return await (imageUsingOCR(imageDataURI));
  227. }
  228.  
  229. async function splitImageUsingOCRAntibotLowValues(questionImageSource) {
  230.  
  231. var img = new Image();
  232. img.crossOrigin = 'anonymous';
  233. img.src = questionImageSource;
  234. await waitForImage(img);
  235.  
  236. var c = document.createElement("canvas")
  237. c.width = img.width;
  238. c.height = img.height;
  239. var ctx = c.getContext("2d");
  240. await ctx.drawImage(img, 0, 0);
  241. //console.log(await c.toDataURL());
  242. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  243. var data = await imageData.data;
  244.  
  245. //Make the image visible
  246. for (let i = 0; i < data.length; i += 4) {
  247. if ((data[i] < 100 || data[i + 1] < 100 || data[i + 2] < 100) && data[i+3]>0) {
  248. data[i] = 0;
  249. data[i + 1] = 0;
  250. data[i + 2] = 0;
  251.  
  252. } else {
  253. data[i] = 255;
  254. data[i + 1] = 255;
  255. data[i + 2] = 255;
  256.  
  257. }
  258. data[i + 3] = 255;
  259. }
  260.  
  261. await ctx.putImageData(imageData, 0, 0);
  262. //console.log(c.toDataURL());
  263. let imageDataURI = await toDataURL(c);
  264. return await (splitImage(imageDataURI));
  265.  
  266. }
  267.  
  268. async function splitImageUsingDefaultValues(questionImageSource) {
  269.  
  270. var img = new Image();
  271. img.crossOrigin = 'anonymous';
  272. img.src = questionImageSource;
  273. await waitForImage(img);
  274.  
  275. var c = document.createElement("canvas")
  276. c.width = img.width;
  277. c.height = img.height;
  278. var ctx = c.getContext("2d");
  279. await ctx.drawImage(img, 0, 0);
  280. //console.log(await c.toDataURL());
  281. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  282. var data = await imageData.data;
  283.  
  284. //Make the image visible
  285. for (let i = 0; i < data.length; i += 4) {
  286. if (data[i] > 0 && data[i + 1] > 0 && data[i + 2] > 100 && data[i+3]>0) {
  287. data[i] = 0;
  288. data[i + 1] = 0;
  289. data[i + 2] = 0;
  290.  
  291. } else {
  292. data[i] = 255;
  293. data[i + 1] = 255;
  294. data[i + 2] = 255;
  295.  
  296. }
  297. data[i + 3] = 255;
  298. }
  299.  
  300. var imgdata = await new Uint32Array(data.buffer);
  301.  
  302. //Remove Noise from Image
  303. imgdata = await removeNoiseUsingImageData(imgdata,c.width,c.height,1);
  304.  
  305. await ctx.putImageData(imageData, 0, 0);
  306. //console.log(c.toDataURL());
  307. let imageDataURI = await toDataURL(c);
  308. return await splitImage(imageDataURI);
  309.  
  310. }
  311.  
  312.  
  313. async function splitImageUsingOCRAntibotHighValues(questionImageSource) {
  314.  
  315. var img = new Image();
  316. img.crossOrigin = 'anonymous';
  317. img.src = questionImageSource;
  318. await waitForImage(img);
  319.  
  320. var c = document.createElement("canvas")
  321. c.width = img.width;
  322. c.height = img.height;
  323. var ctx = c.getContext("2d");
  324. await ctx.drawImage(img, 0, 0);
  325.  
  326. //console.log(await c.toDataURL());
  327.  
  328.  
  329. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  330. var data = await imageData.data;
  331.  
  332. //Make the image visible
  333.  
  334. for (let i = 0; i < data.length; i += 4) {
  335.  
  336. if ((data[i] > 100 || data[i + 1] > 100 || data[i + 2] > 100) && data[i + 3] > 0) {
  337. data[i] = 0;
  338. data[i + 1] = 0;
  339. data[i + 2] = 0;
  340.  
  341. } else {
  342.  
  343. data[i] = 255;
  344. data[i + 1] = 255;
  345. data[i + 2] = 255;
  346. }
  347. data[i + 3] = 255;
  348. }
  349.  
  350. var imgdata = await new Uint32Array(data.buffer);
  351.  
  352. //Remove Noise from Image
  353. imgdata = await removeNoiseUsingImageData(imgdata,c.width,c.height,1);
  354.  
  355.  
  356. await ctx.putImageData(imageData, 0, 0);
  357.  
  358. let imageDataURI = await toDataURL(c);
  359.  
  360. return await splitImage(imageDataURI);
  361.  
  362. }
  363.  
  364. async function splitImage(imgSource) {
  365.  
  366. var img = new Image();
  367. img.crossOrigin = 'anonymous';
  368. img.src = imgSource
  369. await waitForImage(img);
  370. var c = document.createElement("canvas")
  371. c.width = img.width;
  372. c.height = img.height;
  373. var ctx = c.getContext("2d");
  374. await ctx.drawImage(img, 0, 0);
  375.  
  376. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  377. var data = await imageData.data;
  378. var imgdata = await new Uint32Array(data.buffer);
  379.  
  380. //Scan from left to right
  381. //Get the weight of white spaces
  382. //Ignore first white space and last white space
  383. var sequenceLength = 0;
  384. var prevColumn = 0;
  385. var hashMap = new Map();
  386. var first = 0;
  387. var second = 0;
  388. var third = 0;
  389. var firstMaxColumn = 0;
  390. var secondMaxColumn = 0;
  391. var thirdMaxColumn = 0;
  392.  
  393. //Remove Noise from Image
  394. imgdata = await removeNoiseUsingImageData(imgdata,c.width,c.height,1);
  395.  
  396. //await ctx.putImageData(imageData, 0, 0);
  397.  
  398. //console.log(await c.toDataURL());
  399.  
  400.  
  401. for (let column = Math.floor(0.1 * c.width); column < c.width; column++) {
  402. var count = 0;
  403. for (let row = 0; row < c.height; row++) {
  404.  
  405. var position = row * c.width + column;
  406. var pixelAtPosition = imgdata[position];
  407. if (pixelAtPosition == 0xFFFFFFFF) {
  408. count++;
  409. }
  410.  
  411. }
  412.  
  413. //Get the blank spaces based on weight of the column
  414. if (count > Math.floor(0.88 * c.height) && column != 0) {
  415. if (column - prevColumn == 1) {
  416. sequenceLength = sequenceLength + 1;
  417. }
  418. } else {
  419.  
  420. if ((column - sequenceLength != 1) && (column != 0 || sequenceLength != 0 || column != c.width - 1)) {
  421. // If current element is
  422. // greater than first
  423. if (sequenceLength > first) {
  424. third = second;
  425. thirdMaxColumn = secondMaxColumn;
  426. second = first;
  427. secondMaxColumn = firstMaxColumn;
  428. first = sequenceLength;
  429. firstMaxColumn = column - 1;
  430. } else if (sequenceLength > second) {
  431. third = second;
  432. thirdMaxColumn = secondMaxColumn;
  433. second = sequenceLength;
  434. secondMaxColumn = column - 1;
  435. } else if (sequenceLength > third) {
  436. third = sequenceLength;
  437. thirdMaxColumn = column - 1;
  438. }
  439. }
  440.  
  441. sequenceLength = 0;
  442. }
  443.  
  444. prevColumn = column;
  445.  
  446. }
  447.  
  448. firstMaxColumn = firstMaxColumn - Math.floor(first / 2)
  449. secondMaxColumn = secondMaxColumn - Math.floor(second / 2)
  450. thirdMaxColumn = thirdMaxColumn - Math.floor(third / 2)
  451.  
  452. var columnArray = [firstMaxColumn, secondMaxColumn, thirdMaxColumn];
  453. columnArray = await columnArray.sort(function(a, b) {
  454. return a - b;
  455. });
  456.  
  457.  
  458. await ctx.putImageData(imageData, 0, 0);
  459.  
  460.  
  461. let url = await questionImage.src.replace(/^data:image\/\w+;base64,/, "");
  462. let buffer = await new Buffer(url, 'base64');
  463. //Check if overlaps are detected and split the images
  464. var len = [];
  465. len[0] = columnArray[0] - 0;
  466. len[1] = columnArray[1] - columnArray[0];
  467. len[2] = columnArray[2] - columnArray[1];
  468. len[3] = c.width - columnArray[2];
  469.  
  470. for (let i = 0; i < len.length; i++) {
  471. if (len[i] < Math.floor(0.1 * c.width)) {
  472. console.log("Overlap detected");
  473. return;
  474. break;
  475. }
  476. }
  477.  
  478. await new Promise((resolve, reject) => {
  479.  
  480. Jimp.read(buffer).then(async function(data) {
  481. await data.crop(0, 0, columnArray[0], questionImage.height)
  482. .getBase64(Jimp.AUTO, async function(err, src) {
  483. let img = new Image();
  484. img.crossOrigin = 'anonymous';
  485. img.src = src
  486. await waitForImage(img);
  487. questionImages[0] = img;
  488. resolve();
  489. })
  490. });
  491. });
  492.  
  493. await new Promise((resolve, reject) => {
  494. Jimp.read(buffer).then(async function(data) {
  495. await data.crop(columnArray[0], 0, columnArray[1] - columnArray[0], questionImage.height)
  496. .getBase64(Jimp.AUTO, async function(err, src) {
  497. var img = new Image();
  498. img.crossOrigin = 'anonymous';
  499. img.src = src
  500. await waitForImage(img);
  501. questionImages[1] = img;
  502. resolve();
  503.  
  504. })
  505. });
  506. });
  507.  
  508. await new Promise((resolve, reject) => {
  509. Jimp.read(buffer).then(async function(data) {
  510. await data.crop(columnArray[1], 0, columnArray[2] - columnArray[1], questionImage.height)
  511. .getBase64(Jimp.AUTO, async function(err, src) {
  512. var img = new Image();
  513. img.crossOrigin = 'anonymous';
  514. img.src = src
  515. await waitForImage(img);
  516. questionImages[2] = img;
  517. resolve();
  518.  
  519. })
  520. });
  521. });
  522.  
  523. await new Promise((resolve, reject) => {
  524. Jimp.read(buffer).then(async function(data) {
  525. await data.crop(columnArray[2], 0, c.width - columnArray[2], questionImage.height)
  526. .getBase64(Jimp.AUTO, async function(err, src) {
  527. var img = new Image();
  528. img.crossOrigin = 'anonymous';
  529. img.src = src
  530. await waitForImage(img);
  531. questionImages[3] = img;
  532. resolve();
  533. })
  534. });
  535. });
  536. }
  537.  
  538.  
  539. async function imageUsingOCRAntibotQuestion1(image) {
  540.  
  541. if (!image || !image.src) {
  542. console.log("No images found");
  543. return;
  544. }
  545.  
  546. var img = new Image();
  547. img.crossOrigin = 'anonymous';
  548. img.src = image.src
  549. await waitForImage(img);
  550. var c = document.createElement("canvas")
  551. c.width = image.width;
  552. c.height = image.height;
  553. var ctx = c.getContext("2d");
  554. // ctx.filter = 'grayscale(1)';
  555. await ctx.drawImage(img, 0, 0);
  556.  
  557. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  558. var data = await imageData.data;
  559. // console.log(data);
  560.  
  561. await ctx.putImageData(imageData, 0, 0);
  562.  
  563.  
  564. let src = await cv.imread(c);
  565.  
  566. let dst = new cv.Mat();
  567. await cv.medianBlur(src, dst, 3)
  568.  
  569. await cv.imshow(c, dst);
  570.  
  571. src.delete();
  572. dst.delete();
  573.  
  574. //console.log( c.toDataURL());
  575. let imageDataURI = await toDataURL(c);
  576.  
  577. return await (imageUsingOCR(imageDataURI));
  578. }
  579.  
  580.  
  581.  
  582. async function imageUsingOCRAntibot1(image) {
  583. var img1 = image;
  584.  
  585. var img = new Image();
  586. img.crossOrigin = 'anonymous';
  587. img.src = img1.src
  588. await waitForImage(img);
  589.  
  590. var c = document.createElement("canvas")
  591. c.width = img1.width;
  592. c.height = img1.height;
  593. var ctx = c.getContext("2d");
  594.  
  595. await ctx.drawImage(img, 0, 0);
  596.  
  597.  
  598. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  599. var data = await imageData.data;
  600.  
  601.  
  602. var hashMap = new Map();
  603.  
  604. for (let i = 0; i < data.length; i += 4) {
  605.  
  606. var rgba = data[i] + ',' + data[i + 1] + ',' + data[i + 2] + ',' + data[i + 3];
  607.  
  608. if (hashMap.has(rgba)) {
  609. hashMap.set(rgba, hashMap.get(rgba) + 1)
  610. } else {
  611. hashMap.set(rgba, 1)
  612. }
  613.  
  614. }
  615.  
  616. var data_tmp = [];
  617. var data_tmp_edges = [];
  618.  
  619. for (let i = 0; i < data.length; i += 4) {
  620.  
  621. if (data[i + 3] > 130 && data[i] < 100 && data[i + 1] < 100 && data[i + 2] < 100) {
  622. data[i] = 0;
  623. data[i + 1] = 0;
  624. data[i + 2] = 0;
  625. data[i + 3] = 255;
  626. data_tmp_edges[i] = 1;
  627. data_tmp_edges[i + 1] = 1;
  628. data_tmp_edges[i + 2] = 1;
  629.  
  630. } else {
  631. data[i] = 255;
  632. data[i + 1] = 255;
  633. data[i + 2] = 255;
  634. data[i + 3] = 255;
  635.  
  636. }
  637. }
  638.  
  639. await ctx.putImageData(imageData, 0, 0);
  640.  
  641. let imageDataURI = await toDataURL(c);
  642.  
  643. return await (imageUsingOCR(imageDataURI));
  644.  
  645. }
  646.  
  647.  
  648. async function imageUsingOCRAntibotFiltered(image) {
  649.  
  650. var img = new Image();
  651. img.crossOrigin = 'anonymous';
  652. img.src = image.src
  653. await waitForImage(img);
  654.  
  655. let mat = cv.imread(img);
  656.  
  657. var c = document.createElement("canvas")
  658. c.width = image.width;
  659. c.height = image.height;
  660. var ctx = c.getContext("2d");
  661. await ctx.drawImage(img, 0, 0);
  662. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  663. var data = await imageData.data;
  664. // console.log(data);
  665.  
  666. for (let i = 0; i < data.length; i += 4) {
  667. if (data[i + 3] > 130 && data[i] < 100) {
  668. data[i] = 255;
  669. data[i + 1] = 255;
  670. data[i + 2] = 255;
  671. data[i + 3] = 255;
  672. } else {
  673. data[i] = 0;
  674. data[i + 1] = 0;
  675. data[i + 2] = 0;
  676. data[i + 3] = 255;
  677. }
  678.  
  679. }
  680.  
  681.  
  682. await ctx.putImageData(imageData, 0, 0);
  683.  
  684.  
  685. let src = await cv.imread(c);
  686.  
  687. let dst = new cv.Mat();
  688.  
  689. let M = cv.Mat.ones(2, 1, cv.CV_8U);
  690. let anchor = new cv.Point(-1, -1);
  691.  
  692. // Opening , remove small particles from image
  693. await cv.morphologyEx(src, dst, cv.MORPH_OPEN, M, anchor, 1,
  694. cv.BORDER_CONSTANT, cv.morphologyDefaultBorderValue());
  695. await cv.imshow(c, dst);
  696.  
  697. //Image erode, thinning the text
  698.  
  699. src = await cv.imread(c);
  700. M = cv.Mat.ones(2, 1, cv.CV_8U);
  701. await cv.erode(src, dst, M, anchor, 1, cv.BORDER_CONSTANT, cv.morphologyDefaultBorderValue());
  702. await cv.imshow(c, dst);
  703.  
  704. src.delete();
  705. dst.delete();
  706. M.delete();
  707.  
  708. // console.log( c.toDataURL());
  709.  
  710. let imageDataURI = await toDataURL(c);
  711. return await (imageUsingOCR(imageDataURI));
  712.  
  713. }
  714.  
  715. async function imageUsingOCRAntibotFiltered1(image) {
  716.  
  717. var img = new Image();
  718. img.crossOrigin = 'anonymous';
  719. img.src = image.src
  720. await waitForImage(img);
  721.  
  722. let mat = cv.imread(img);
  723.  
  724. var c = document.createElement("canvas")
  725. c.width = image.width;
  726. c.height = image.height;
  727. var ctx = c.getContext("2d");
  728. await ctx.drawImage(img, 0, 0);
  729. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  730. var data = await imageData.data;
  731. // console.log(data);
  732.  
  733. for (let i = 0; i < data.length; i += 4) {
  734. if (data[i + 3] > 130 && data[i] > 70) {
  735. data[i] = 255;
  736. data[i + 1] = 255;
  737. data[i + 2] = 255;
  738. data[i + 3] = 255;
  739. } else {
  740. data[i] = 0;
  741. data[i + 1] = 0;
  742. data[i + 2] = 0;
  743. data[i + 3] = 255;
  744. }
  745.  
  746. }
  747.  
  748. await ctx.putImageData(imageData, 0, 0);
  749.  
  750. let src = await cv.imread(c);
  751. let dst = new cv.Mat();
  752. let M = cv.Mat.ones(2, 1, cv.CV_8U);
  753. let anchor = new cv.Point(-1, -1);
  754.  
  755. // Opening morphology, remove noise from image
  756. await cv.morphologyEx(src, dst, cv.MORPH_OPEN, M, anchor, 1,
  757. cv.BORDER_CONSTANT, cv.morphologyDefaultBorderValue());
  758. await cv.imshow(c, dst);
  759. //console.log( c.toDataURL());
  760.  
  761. //Image erode
  762. src = await cv.imread(c);
  763. M = cv.Mat.ones(2, 1, cv.CV_8U);
  764. await cv.erode(src, dst, M, anchor, 1, cv.BORDER_CONSTANT, cv.morphologyDefaultBorderValue());
  765. await cv.imshow(c, dst);
  766. src.delete();
  767. dst.delete();
  768. M.delete();
  769.  
  770. // console.log( c.toDataURL());
  771. let imageDataURI = await toDataURL(c);
  772.  
  773. return await (imageUsingOCR(imageDataURI));
  774.  
  775. }
  776.  
  777. async function imageUsingOCRAntibot(image) {
  778.  
  779. var img = new Image();
  780. img.crossOrigin = 'anonymous';
  781. img.src = image.src
  782. await waitForImage(img);
  783. var c = document.createElement("canvas")
  784. c.width = image.width;
  785. c.height = image.height;
  786. var ctx = c.getContext("2d");
  787. // ctx.filter = 'grayscale(1)';
  788. await ctx.drawImage(img, 0, 0);
  789.  
  790. var imageData = await ctx.getImageData(0, 0, c.width, c.height);
  791. var data = await imageData.data;
  792.  
  793. var hashMap = new Map();
  794.  
  795. for (let i = 0; i < data.length; i += 4) {
  796.  
  797. var rgba = data[i] + ',' + data[i + 1] + ',' + data[i + 2] + ',' + data[i + 3];
  798.  
  799. if (hashMap.has(rgba)) {
  800. hashMap.set(rgba, hashMap.get(rgba) + 1)
  801. } else {
  802. hashMap.set(rgba, 1)
  803. }
  804.  
  805. }
  806.  
  807. var maxCount = 0;
  808. var objectKey = "0,0,0,0";
  809. await hashMap.forEach((value, key) => {
  810. if (maxCount < value && key != "0,0,0,0") {
  811. objectKey = key;
  812. maxCount = value;
  813. }
  814.  
  815. });
  816.  
  817. var alphaValues = objectKey.split(",");
  818. var alpha = Number(alphaValues[alphaValues.length - 1]);
  819.  
  820. var data_tmp = [];
  821. var data_tmp_edges = [];
  822.  
  823. for (let i = 0; i < data.length; i += 4) {
  824.  
  825. if (data[i + 3] == alpha) {
  826. data[i] = 255;
  827. data[i + 1] = 255;
  828. data[i + 2] = 255;
  829. data[i + 3] = 255;
  830. //Giving some value for representation
  831. data_tmp[i] = 1;
  832. data_tmp[i + 1] = 1;
  833. data_tmp[i + 2] = 1;
  834.  
  835.  
  836. } else if (data[i + 3] > 0) {
  837. data[i] = 0;
  838. data[i + 1] = 0;
  839. data[i + 2] = 0;
  840. data[i + 3] = 255;
  841. data_tmp_edges[i] = 1;
  842. data_tmp_edges[i + 1] = 1;
  843. data_tmp_edges[i + 2] = 1;
  844.  
  845. } else {
  846. data[i] = 255;
  847. data[i + 1] = 255;
  848. data[i + 2] = 255;
  849. data[i + 3] = 255;
  850.  
  851. }
  852. }
  853.  
  854.  
  855. //Fill if the adjacent value was present earlier
  856. for (let k = 0; k < 20; k++) {
  857. for (let i = 4; i < data.length; i += 4) {
  858.  
  859. if (data[i] == 0 && data_tmp[i - 4] == 1) {
  860. data[i - 4] = 0;
  861. data[i - 3] = 0;
  862. data[i - 2] = 0;
  863. data[i - 1] = 255;
  864. }
  865. }
  866. }
  867.  
  868. //console.log(imageData.data);
  869.  
  870. await ctx.putImageData(imageData, 0, 0);
  871.  
  872. // console.log( c.toDataURL());
  873. let imageDataURI = await toDataURL(c);
  874.  
  875. return await (imageUsingOCR(imageDataURI));
  876.  
  877.  
  878. }
  879.  
  880. var worker = "";
  881.  
  882. async function imageUsingOCR(img) {
  883. var answer = "";
  884.  
  885. if (!worker) {
  886. worker = await new Tesseract.createWorker();
  887. }
  888.  
  889. if(!img || img.width ==0 || img.height == 0){
  890. console.log("OCR cannot be performed on this image");
  891. return "";
  892. }
  893.  
  894. try {
  895.  
  896. await worker.load();
  897. await worker.loadLanguage('eng');
  898. await worker.initialize('eng');
  899. await worker.setParameters({
  900. tessedit_pageseg_mode: '6',
  901. preserve_interword_spaces: '1',
  902. tessedit_char_whitelist: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,@!*-',
  903. //tessedit_ocr_engine_mode:'1'
  904. });
  905.  
  906. await worker.recognize(img, "eng").then(async function(result) {
  907. answer = result.data.text.trim();
  908. console.log("Captcha Answer::" + answer);
  909. });
  910.  
  911. // await worker.terminate();
  912. } catch (err) {
  913. console.log(err.message);
  914. await worker.terminate();
  915.  
  916. }
  917.  
  918. return answer;
  919.  
  920. }
  921.  
  922.  
  923. // Compare similar strings
  924. var LevenshteinDistance = function(a, b) {
  925. if (a.length == 0) return b.length;
  926. if (b.length == 0) return a.length;
  927.  
  928. var matrix = [];
  929.  
  930. // increment along the first column of each row
  931. var i;
  932. for (i = 0; i <= b.length; i++) {
  933. matrix[i] = [i];
  934. }
  935.  
  936. // increment each column in the first row
  937. var j;
  938. for (j = 0; j <= a.length; j++) {
  939. matrix[0][j] = j;
  940. }
  941.  
  942. // Fill in the rest of the matrix
  943. for (i = 1; i <= b.length; i++) {
  944. for (j = 1; j <= a.length; j++) {
  945. if (b.charAt(i - 1) == a.charAt(j - 1)) {
  946. matrix[i][j] = matrix[i - 1][j - 1];
  947. } else {
  948. matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution
  949. Math.min(matrix[i][j - 1] + 1, // insertion
  950. matrix[i - 1][j] + 1)); // deletion
  951. }
  952. }
  953. }
  954.  
  955. return matrix[b.length][a.length];
  956. };
  957.  
  958.  
  959. function countPairs(s1, s2) {
  960. var n1 = s1.length;
  961. var n2 = s2.length;
  962.  
  963. // To store the frequencies of
  964. // characters of string s1 and s2
  965. let freq1 = new Array(26);
  966. let freq2 = new Array(26);
  967. freq1.fill(0);
  968. freq2.fill(0);
  969.  
  970. // To store the count of valid pairs
  971. let i, count = 0;
  972.  
  973. // Update the frequencies of
  974. // the characters of string s1
  975. for (i = 0; i < n1; i++)
  976. freq1[s1[i].charCodeAt() - 'a'.charCodeAt()]++;
  977.  
  978. // Update the frequencies of
  979. // the characters of string s2
  980. for (i = 0; i < n2; i++)
  981. freq2[s2[i].charCodeAt() - 'a'.charCodeAt()]++;
  982.  
  983. // Find the count of valid pairs
  984. for (i = 0; i < 26; i++)
  985. count += (Math.min(freq1[i], freq2[i]));
  986.  
  987. return count;
  988. }
  989.  
  990. async function getFinalOCRResultFromImage(image,leastLength){
  991. var ocrResult = "";
  992. var tempResult = "";
  993. ocrResult = await imageUsingOCRAntibotLowValues(image);
  994.  
  995. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  996. tempResult = ocrResult.trim();
  997. } else {
  998. ocrResult = await imageUsingOCRAntibotHighValues(image);
  999. }
  1000.  
  1001. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1002. tempResult = ocrResult.trim();
  1003. } else {
  1004. ocrResult = await imageUsingOCR(image);
  1005. }
  1006.  
  1007.  
  1008. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1009. tempResult = ocrResult.trim();
  1010. } else {
  1011. ocrResult = await imageUsingOCRAntibotQuestion(image);
  1012. }
  1013.  
  1014. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1015. tempResult = ocrResult.trim();
  1016. } else {
  1017. ocrResult = await imageUsingOCRAntibotQuestion1(image);
  1018. }
  1019.  
  1020.  
  1021. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1022. tempResult = ocrResult.trim()
  1023. } else {
  1024. ocrResult = await imageUsingOCRAntibot(image)
  1025. }
  1026.  
  1027.  
  1028. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1029. tempResult = ocrResult.trim()
  1030. } else {
  1031. ocrResult = await imageUsingOCRAntibot1(image);
  1032. }
  1033.  
  1034. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1035. tempResult = ocrResult.trim()
  1036. } else {
  1037. ocrResult = await imageUsingOCRAntibotFiltered(image)
  1038. }
  1039.  
  1040. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1041. tempResult = ocrResult.trim()
  1042. } else {
  1043. ocrResult = await imageUsingOCRAntibotFiltered1(image)
  1044. }
  1045.  
  1046. if (ocrResult.length > leastLength || ocrResult.length > tempResult.length) {
  1047. tempResult = ocrResult.trim()
  1048. }
  1049.  
  1050. ocrResult = tempResult;
  1051.  
  1052. return ocrResult;
  1053.  
  1054.  
  1055. }
  1056.  
  1057. //Adding referral links to faucetpay list
  1058. if (window.location.href.includes("faucetpay.io/page/faucet-list") && document.querySelectorAll(".btn.btn-primary.btn-sm").length > 0) {
  1059. for (let i = 0; i < document.querySelectorAll(".btn.btn-primary.btn-sm").length; i++) {
  1060. document.querySelectorAll(".btn.btn-primary.btn-sm")[i].href =
  1061. document.querySelectorAll(".btn.btn-primary.btn-sm")[i].href.replace(/\/$/, "") + "/?r=122ES9zQJm8FTqczfYM2P4ZRK5pQEcfCj4";
  1062. }
  1063. }
  1064.  
  1065.  
  1066. if(window.location.href.includes("gr8.cc")){
  1067. var oldFunction = unsafeWindow.open;
  1068. unsafeWindow.open= function(url){url = url.split("?r=")[0] + "?r=122ES9zQJm8FTqczfYM2P4ZRK5pQEcfCj4"; return oldFunction(url)}
  1069. for(let i=0; i< document.querySelectorAll("a").length;i++){
  1070. document.querySelectorAll("a")[i].removeAttribute("onmousedown");
  1071. document.querySelectorAll("a")[i].href= document.querySelectorAll("a")[i].href.split("?r=")[0] + "?r=122ES9zQJm8FTqczfYM2P4ZRK5pQEcfCj4";
  1072. }
  1073. }
  1074.  
  1075.  
  1076.  
  1077. setTimeout(async function() {
  1078.  
  1079. var answerSelector = "";
  1080. var questionSelector = "";
  1081. var addCount = 0;
  1082. var leastLength = 0;
  1083.  
  1084. if (document.querySelectorAll(".modal-content [href='/'] img").length == 4 && document.querySelectorAll(".modal-content img").length >= 5) {
  1085. questionSelector = ".modal-content img";
  1086. answerSelector = ".modal-content [href='/'] img";
  1087. } else if (document.querySelector(".modal-header img") && document.querySelectorAll(".modal-body [href='/'] img").length == 4) {
  1088. questionSelector = ".modal-header img";
  1089. answerSelector = ".modal-body [href='/'] img";
  1090. } else if (document.querySelector(".alert.alert-info img") && document.querySelectorAll(".antibotlinks [href='/'] img").length == 4) {
  1091. questionSelector = ".alert.alert-info img";
  1092. answerSelector = ".antibotlinks [href='/'] img";
  1093. } else {
  1094. console.log("Ab links not detected");
  1095. return;
  1096. }
  1097.  
  1098. for (let i = 0; i < document.querySelectorAll(answerSelector).length; i++) {
  1099. if (document.querySelector(answerSelector).width <= document.querySelector(answerSelector).height) {
  1100. document.querySelector(answerSelector).value = "####"; //Using this as reference to move to next url
  1101. console.log("Numeric/Roman captcha Detected , captcha cannot be solved at the moment");
  1102. console.log("Reload the page to see if the captcha changes");
  1103. // solveNumberCaptchaByAnswer()
  1104. return;
  1105. }
  1106. }
  1107.  
  1108. if (document.querySelector(questionSelector).width < 5 * document.querySelector(questionSelector).height) {
  1109. document.querySelector(answerSelector).value = "####"; //Using this as reference to move to next url
  1110. console.log("Numeric/Roman captcha Detected , captcha cannot be solved at the moment");
  1111. console.log("Reload the page to see if the captcha changes");
  1112. // solveNumberCaptchaByQuestion()
  1113. return;
  1114. }
  1115.  
  1116. if (document.querySelector(questionSelector).width < 10 * document.querySelector(questionSelector).height) {
  1117. leastLength = 2;
  1118. } else {
  1119. leastLength = 3;
  1120. }
  1121.  
  1122. console.log("Solving Ab Links....");
  1123.  
  1124. if (!document.querySelector(questionSelector) || !document.querySelector(questionSelector).src) {
  1125. document.querySelector(answerSelector).value = "####"; //Using this as reference to move to next url
  1126. console.log("No image source found for question");
  1127. return
  1128. }
  1129.  
  1130. questionImage = document.querySelector(questionSelector);
  1131. questionImageSource = document.querySelector(questionSelector).src;
  1132. await waitForImage(questionImage);
  1133. var optionImages = [];
  1134.  
  1135. for (let i = 0; i < 4; i++) {
  1136. optionImages[i] = document.querySelectorAll(answerSelector)[i + addCount];
  1137. }
  1138.  
  1139. var questionSolution = await imageUsingOCRAntibotLowValues(questionImage);
  1140. questionSolution = questionSolution.replace(/,$/, "");
  1141.  
  1142. if (!questionSolution || !questionSolution.includes(",") || questionSolution.split(",").length != 4) {
  1143. questionSolution = await imageUsingOCRAntibotHighValues(questionImage);
  1144. questionSolution = questionSolution.replace(/,$/, "");
  1145. }
  1146.  
  1147. if (!questionSolution || !questionSolution.includes(",") || questionSolution.split(",").length != 4) {
  1148. questionSolution = await imageUsingOCR(questionImage);
  1149. questionSolution = questionSolution.replace(/,$/, "");
  1150. }
  1151.  
  1152. if (!questionSolution || !questionSolution.includes(",") || questionSolution.split(",").length != 4) {
  1153. questionSolution = await imageUsingOCRAntibotQuestion(questionImage);
  1154. questionSolution = questionSolution.replace(/,$/, "");
  1155. }
  1156.  
  1157.  
  1158. if (!questionSolution || !questionSolution.includes(",") || questionSolution.split(",").length != 4) {
  1159.  
  1160. await splitImageUsingDefaultValues(questionImageSource);
  1161.  
  1162. if(questionImages.length < 4){
  1163. questionImages = [];
  1164. await splitImageUsingOCRAntibotLowValues(questionImageSource);
  1165. }
  1166.  
  1167.  
  1168. if(questionImages.length < 4){
  1169. questionImages = [];
  1170. await splitImageUsingOCRAntibotHighValues(questionImageSource);
  1171. }
  1172.  
  1173.  
  1174. if(questionImages.length < 4){
  1175. document.querySelector(answerSelector).value = "####"; //Using this as reference to move to next url
  1176. console.log("Captcha cannot be solved");
  1177. return;
  1178. }
  1179.  
  1180. for (let i = 0; i < 4; i++) {
  1181.  
  1182. questions[i] = await getFinalOCRResultFromImage(questionImages[i],leastLength);
  1183. questions[i] = questions[i].replaceAll("5", "s").replaceAll("3", "e").replaceAll(",", "")
  1184. .replaceAll("8", "b").replaceAll("1", "l").replaceAll("@", "a").replaceAll("*", "").replaceAll("9", "g")
  1185. .replaceAll("!", "i").replaceAll("0", "o").replaceAll("4", "a").replaceAll("2", "z").toLowerCase();
  1186.  
  1187. }
  1188. } else {
  1189. questionSolution = questionSolution.toLowerCase();
  1190. questionSolution = questionSolution.replaceAll("5", "s").replaceAll("3", "e")
  1191. .replaceAll("8", "b").replaceAll("1", "l").replaceAll("@", "a").replaceAll("*", "").replaceAll("9", "g")
  1192. .replaceAll("!", "i").replaceAll("0", "o").replaceAll("4", "a").replaceAll("2", "z").toLowerCase();
  1193. questions = questionSolution.split(',');
  1194. }
  1195.  
  1196. leastLength = 1000;
  1197. for (let i = 0; i < 4; i++) {
  1198. if (questions[i].length < leastLength) {
  1199. leastLength = questions[i].length;
  1200. }
  1201. }
  1202.  
  1203. leastLength = leastLength - 1;
  1204.  
  1205. var answers = [];
  1206.  
  1207. for (let i = 0; i < 4; i++) {
  1208. var answer = "";
  1209. answers[i] = await getFinalOCRResultFromImage(optionImages[i],leastLength);
  1210. answers[i] = answers[i].replaceAll("5", "s").replaceAll("3", "e")
  1211. .replaceAll("8", "b").replaceAll("1", "l").replaceAll("@", "a").replaceAll("9", "g")
  1212. .replaceAll("!", "i").replaceAll("0", "o").replaceAll("4", "a").replaceAll("2", "z").toLowerCase();
  1213.  
  1214. }
  1215.  
  1216. await worker.terminate();
  1217.  
  1218. var length = questions.length;
  1219.  
  1220. if (length == 4) {
  1221.  
  1222. var map = new Map();
  1223. for (let i = 0; i < length; i++) {
  1224. questions[i] = questions[i].replaceAll(",", "").replaceAll(" ", "").trim();
  1225. for (let j = 0; j < length; j++) {
  1226. let score = "";
  1227. answers[j] = answers[j].replaceAll(",", "").replaceAll(" ", "").trim();
  1228. score = await LevenshteinDistance(questions[i], answers[j]);
  1229. map.set(questions[i] + "::" + answers[j], score);
  1230. }
  1231. }
  1232.  
  1233. map[Symbol.iterator] = function*() {
  1234. yield*[...this.entries()].sort((a, b) => a[1] - b[1]);
  1235. }
  1236.  
  1237. var tempMap = new Map();
  1238. var finalMap = new Map();
  1239. var preValue = "";
  1240. var count = 0;
  1241. for (let [key, value] of map) {
  1242. count = count + 1;
  1243. //Sort by same score
  1244. if (!preValue) {
  1245. preValue = value;
  1246. tempMap.set(key, value)
  1247. continue;
  1248. }
  1249.  
  1250. if (preValue == value) {
  1251. tempMap.set(key, value);
  1252. } else {
  1253. //The new score is different, sort all the temp values
  1254. tempMap[Symbol.iterator] = function*() {
  1255. yield*[...this.entries()].sort((a, b) => a[0] - b[0]);
  1256. }
  1257.  
  1258. finalMap = new Map([...finalMap, ...tempMap]);
  1259. tempMap = new Map();
  1260. tempMap.set(key, value)
  1261. preValue = value;
  1262. }
  1263.  
  1264. if (count == map.size) {
  1265. tempMap.set(key, value);
  1266. tempMap[Symbol.iterator] = function*() {
  1267. yield*[...this.entries()].sort((a, b) => a[0] - b[0]);
  1268. }
  1269.  
  1270. finalMap = new Map([...finalMap, ...tempMap]);
  1271. }
  1272.  
  1273. }
  1274.  
  1275. var questionAnswerMap = new Map();
  1276. var answerSet = new Set();
  1277. var prevKey = "";
  1278. map = finalMap;
  1279. for (let [key, value] of map) {
  1280. if (!prevKey) {
  1281. prevKey = key
  1282. continue;
  1283. }
  1284. //Check if scores are equal and assign the value
  1285. if (map.get(prevKey) == map.get(key) && prevKey.split("::")[0] == key.split("::")[0] && !answerSet.has(prevKey.split("::")[1]) &&
  1286. !answerSet.has(key.split("::")[1]) && !questionAnswerMap.has(prevKey.split("::")[0]) && !questionAnswerMap.has(key.split("::")[0])) {
  1287. var prevCount = countPairs(prevKey.split("::")[1], prevKey.split("::")[0]);
  1288. var currCount = countPairs(key.split("::")[1], key.split("::")[0]);
  1289.  
  1290. if (prevCount > currCount) {
  1291. key = prevKey;
  1292. } else {
  1293. prevKey = key;
  1294. }
  1295. } else {
  1296. if (!questionAnswerMap.has(prevKey.split("::")[0]) && !answerSet.has(prevKey.split("::")[1])) {
  1297. questionAnswerMap.set(prevKey.split("::")[0], prevKey.split("::")[1]);
  1298. answerSet.add(prevKey.split("::")[1]);
  1299. }
  1300. prevKey = key;
  1301. }
  1302. }
  1303.  
  1304. if (questionAnswerMap.size == 3 && !questionAnswerMap.has(prevKey.split("::")[0]) && !answerSet.has(prevKey.split("::")[1])) {
  1305. questionAnswerMap.set(prevKey.split("::")[0], prevKey.split("::")[1]);
  1306. answerSet.add(prevKey.split("::")[1]);
  1307. }
  1308.  
  1309. var answersMap = new Map();
  1310.  
  1311. for (let i = 0; i < length; i++) {
  1312. answersMap.set(answers[i], i);
  1313. }
  1314.  
  1315. //Selecting the Answers
  1316. for (let i = 0; i < length; i++) {
  1317. var ans = questionAnswerMap.get(questions[i]);
  1318. let j = answersMap.get(ans);
  1319. console.log("Answer for " + questions[i] + "::" + answers[j]);
  1320. if (document.querySelectorAll(answerSelector)[j + addCount]) {
  1321. document.querySelectorAll(answerSelector)[j + addCount].click();
  1322. } else {
  1323. console.log("Answer Selector could not be identified");
  1324. }
  1325. }
  1326.  
  1327. }
  1328.  
  1329. }, 10000)
  1330.  
  1331. })();
Comments
Add Comment
Please, Sign In to add comment