diff --git a/scripts/images/07pruu.png b/scripts/images/07pruu.png new file mode 100755 index 0000000..3827d9a Binary files /dev/null and b/scripts/images/07pruu.png differ diff --git a/scripts/images/0yce8w.png b/scripts/images/0yce8w.png new file mode 100644 index 0000000..66ad525 Binary files /dev/null and b/scripts/images/0yce8w.png differ diff --git a/scripts/images/3f4kx6.png b/scripts/images/3f4kx6.png new file mode 100644 index 0000000..c56b93d Binary files /dev/null and b/scripts/images/3f4kx6.png differ diff --git a/scripts/images/3m0y55.png b/scripts/images/3m0y55.png new file mode 100644 index 0000000..8f0c7c6 Binary files /dev/null and b/scripts/images/3m0y55.png differ diff --git a/scripts/images/4thho3.png b/scripts/images/4thho3.png new file mode 100755 index 0000000..2de531b Binary files /dev/null and b/scripts/images/4thho3.png differ diff --git a/scripts/images/53bajm b/scripts/images/53bajm deleted file mode 100644 index 4a681be..0000000 Binary files a/scripts/images/53bajm and /dev/null differ diff --git a/scripts/images/58omry b/scripts/images/58omry deleted file mode 100644 index ad0b2fa..0000000 Binary files a/scripts/images/58omry and /dev/null differ diff --git a/scripts/images/5uo4v2.png b/scripts/images/5uo4v2.png new file mode 100644 index 0000000..e7d7a80 Binary files /dev/null and b/scripts/images/5uo4v2.png differ diff --git a/scripts/images/7cphau b/scripts/images/7cphau deleted file mode 100644 index 94d36fb..0000000 Binary files a/scripts/images/7cphau and /dev/null differ diff --git a/scripts/images/8yhn5j.png b/scripts/images/8yhn5j.png new file mode 100644 index 0000000..65f311b Binary files /dev/null and b/scripts/images/8yhn5j.png differ diff --git a/scripts/images/90r68s b/scripts/images/90r68s deleted file mode 100644 index f830ffd..0000000 Binary files a/scripts/images/90r68s and /dev/null differ diff --git a/scripts/images/98qvx4.png b/scripts/images/98qvx4.png new file mode 100755 index 0000000..4ae249d Binary files /dev/null and b/scripts/images/98qvx4.png differ diff --git a/scripts/images/c4mq1e.png b/scripts/images/c4mq1e.png new file mode 100644 index 0000000..687a102 Binary files /dev/null and b/scripts/images/c4mq1e.png differ diff --git a/scripts/images/coj1g8.png b/scripts/images/coj1g8.png new file mode 100644 index 0000000..6781c46 Binary files /dev/null and b/scripts/images/coj1g8.png differ diff --git a/scripts/images/d0s7b7.png b/scripts/images/d0s7b7.png new file mode 100644 index 0000000..b6f4ed9 Binary files /dev/null and b/scripts/images/d0s7b7.png differ diff --git a/scripts/images/dypcre.png b/scripts/images/dypcre.png new file mode 100644 index 0000000..2d2fdd9 Binary files /dev/null and b/scripts/images/dypcre.png differ diff --git a/scripts/images/ebuxw9 b/scripts/images/ebuxw9 deleted file mode 100644 index 014f3a4..0000000 Binary files a/scripts/images/ebuxw9 and /dev/null differ diff --git a/scripts/images/g4pqnh.png b/scripts/images/g4pqnh.png new file mode 100755 index 0000000..844ff9a Binary files /dev/null and b/scripts/images/g4pqnh.png differ diff --git a/scripts/images/gewxcn.png b/scripts/images/gewxcn.png new file mode 100755 index 0000000..d459f8a Binary files /dev/null and b/scripts/images/gewxcn.png differ diff --git a/scripts/images/gmypjq.png b/scripts/images/gmypjq.png new file mode 100644 index 0000000..004dc07 Binary files /dev/null and b/scripts/images/gmypjq.png differ diff --git a/scripts/images/hmq57a.png b/scripts/images/hmq57a.png new file mode 100644 index 0000000..cf00c06 Binary files /dev/null and b/scripts/images/hmq57a.png differ diff --git a/scripts/images/hqextb b/scripts/images/hqextb deleted file mode 100644 index 0e88f32..0000000 Binary files a/scripts/images/hqextb and /dev/null differ diff --git a/scripts/images/j3yjiv b/scripts/images/j3yjiv deleted file mode 100644 index 393465b..0000000 Binary files a/scripts/images/j3yjiv and /dev/null differ diff --git a/scripts/images/ki2y2u.png b/scripts/images/ki2y2u.png new file mode 100644 index 0000000..3106263 Binary files /dev/null and b/scripts/images/ki2y2u.png differ diff --git a/scripts/images/kj64tw b/scripts/images/kj64tw deleted file mode 100644 index 134e9a0..0000000 Binary files a/scripts/images/kj64tw and /dev/null differ diff --git a/scripts/images/ns7gvg b/scripts/images/ns7gvg deleted file mode 100644 index 1702813..0000000 Binary files a/scripts/images/ns7gvg and /dev/null differ diff --git a/scripts/images/o1kqtu.png b/scripts/images/o1kqtu.png new file mode 100755 index 0000000..d7479d8 Binary files /dev/null and b/scripts/images/o1kqtu.png differ diff --git a/scripts/images/ohx30s.png b/scripts/images/ohx30s.png new file mode 100755 index 0000000..1a3e805 Binary files /dev/null and b/scripts/images/ohx30s.png differ diff --git a/scripts/images/ph1rav.png b/scripts/images/ph1rav.png new file mode 100755 index 0000000..15248de Binary files /dev/null and b/scripts/images/ph1rav.png differ diff --git a/scripts/images/pq0bf1 b/scripts/images/pq0bf1 deleted file mode 100644 index 0baaa01..0000000 Binary files a/scripts/images/pq0bf1 and /dev/null differ diff --git a/scripts/images/pv42m7 b/scripts/images/pv42m7 deleted file mode 100644 index fa14268..0000000 Binary files a/scripts/images/pv42m7 and /dev/null differ diff --git a/scripts/images/qcenjg.png b/scripts/images/qcenjg.png new file mode 100644 index 0000000..14505c5 Binary files /dev/null and b/scripts/images/qcenjg.png differ diff --git a/scripts/images/r3oemy.png b/scripts/images/r3oemy.png new file mode 100644 index 0000000..b44a083 Binary files /dev/null and b/scripts/images/r3oemy.png differ diff --git a/scripts/images/r99xiv b/scripts/images/r99xiv deleted file mode 100644 index 10b3fd3..0000000 Binary files a/scripts/images/r99xiv and /dev/null differ diff --git a/scripts/images/rmpvgd.png b/scripts/images/rmpvgd.png new file mode 100644 index 0000000..d7e3fe8 Binary files /dev/null and b/scripts/images/rmpvgd.png differ diff --git a/scripts/images/t6dk52.png b/scripts/images/t6dk52.png new file mode 100644 index 0000000..dab62e6 Binary files /dev/null and b/scripts/images/t6dk52.png differ diff --git a/scripts/images/uoy1oe b/scripts/images/uoy1oe deleted file mode 100644 index 575e3d8..0000000 Binary files a/scripts/images/uoy1oe and /dev/null differ diff --git a/scripts/images/uq3n51.png b/scripts/images/uq3n51.png new file mode 100644 index 0000000..80fe856 Binary files /dev/null and b/scripts/images/uq3n51.png differ diff --git a/scripts/images/vqx1dt b/scripts/images/vqx1dt deleted file mode 100644 index 2f49941..0000000 Binary files a/scripts/images/vqx1dt and /dev/null differ diff --git a/scripts/images/x2g0yn.png b/scripts/images/x2g0yn.png new file mode 100644 index 0000000..5408ed0 Binary files /dev/null and b/scripts/images/x2g0yn.png differ diff --git a/scripts/images/x3qvbg.png b/scripts/images/x3qvbg.png new file mode 100755 index 0000000..f362eaa Binary files /dev/null and b/scripts/images/x3qvbg.png differ diff --git a/src/content-script.ts b/src/content-script.ts index 82174d4..66c9459 100644 --- a/src/content-script.ts +++ b/src/content-script.ts @@ -3,9 +3,9 @@ import {Image} from "image-js"; import data from "./data.json"; import {evaluate_captcha} from "./evaluate"; -let factors = [ 1, 3, 2, 8, 3 ]; +const FACTORS = [ 1, 3, 2, 8, 3 ]; -let reload_limit = 15; +const RELOAD_LIMIT = 15; let old_urls: Array = new Array(); @@ -21,14 +21,16 @@ async function async_sleep(time: number) { } function reload_captcha() { - document?.querySelector('[aria-label="Reload captcha"]') - ?.dispatchEvent(new Event("click")); + setTimeout(() => { + document?.querySelector('[aria-label="Reload captcha"]') + ?.dispatchEvent(new Event("click")); + }, 100); } document?.querySelector('[aria-label="Reload captcha"]') ?.addEventListener("click", async () => { reload_counter++; - if (reload_counter < reload_limit) { + if (reload_counter < RELOAD_LIMIT) { while (old_urls.includes( document.getElementsByClassName("captcha-image-dimension")[0] .getAttribute("src"))) { @@ -53,34 +55,41 @@ async function solve_captcha() { let captcha_img = await Image.load(captcha_blob_url); captcha_value = await evaluate_captcha(captcha_img); - if (captcha_value.length == 6) { - let captcha = ""; - captcha_value.map((item) => { - let sim: Array<[ string, number ]> = Object.entries(data).map((item2) => { - let absSum = 0; - item.map((indvItem, index) => { - absSum += factors[index] * Math.abs(item2[1][index] - indvItem); - }); - return [ item2[0], absSum ]; + let captcha = ""; + captcha_value.map((item) => { + let sim: Array<[ string, number ]> = Object.entries(data).map((item2) => { + let absSum = 0; + item.map((indvItem, index) => { + absSum += FACTORS[index] * Math.abs(item2[1][index] - indvItem); }); + return [ item2[0], absSum ]; + }); - let sorted_values = sim.sort((a, b) => a[1] - b[1]); + let sorted_values = sim.sort((a, b) => a[1] - b[1]); - if (sorted_values[0][1] > 60 || - sorted_values[1][1] - sorted_values[0][1] < 5) { - reload_captcha(); - return false; - } - captcha += sorted_values[0][0]; - }); + if (sorted_values[0][1] > 60 || + sorted_values[1][1] - sorted_values[0][1] < 5) { + console.log(`Confidence is low! Got value '${captcha}'. Reloading!`); + reload_captcha(); + return false; + } + captcha += sorted_values[0][0]; + }); - console.log(captcha); + if (captcha_value.length == 6) { + let captcha_field = + document?.getElementById("captchaEnter") as HTMLInputElement; + + captcha_field.value = captcha; - document?.getElementById("captchaEnter")?.setAttribute("value", captcha); - document?.getElementById("captchaEnter")?.dispatchEvent(new Event("input")); + captcha_field?.dispatchEvent(new Event("input")); return true; } else { + console.log( + `Failed to solve! Length < 6. Obtained value '${captcha}'. Reloading!`, + ); + await async_sleep(100); reload_captcha(); return false; } diff --git a/src/data.json b/src/data.json index ea66b94..5da5565 100644 --- a/src/data.json +++ b/src/data.json @@ -1 +1 @@ -{"0":[133.4765625,69.228515625,83.671875,49.8046875,15],"1":[84.66796875,56.11328125,46.15234375,38.515625,11],"2":[112.55859375,56.77734375,57.7734375,54.78515625,14],"3":[105.087890625,38.84765625,66.240234375,38.84765625,13],"4":[115.048828125,39.84375,67.236328125,47.8125,15],"5":[112.55859375,54.78515625,75.703125,36.85546875,13],"6":[129.4921875,73.212890625,81.181640625,48.310546875,15],"7":[84.66796875,48.4765625,62.75390625,21.9140625,13],"8":[155.390625,79.6875,98.61328125,56.77734375,15],"9":[129.4921875,62.0068359375,94.62890625,34.86328125,15],"b":[133.7255859375,86.4111328125,78.193359375,55.5322265625,14],"a":[107.080078125,53.7890625,41.8359375,65.244140625,14],"j":[80.68359375,9.9609375,31.875,48.80859375,9],"m":[163.359375,92.138671875,93.134765625,70.224609375,21],"r":[58.76953125,50.80078125,35.361328125,23.408203125,9],"s":[80.185546875,44.326171875,40.341796875,39.84375,11],"c":[62.75390625,43.828125,30.87890625,31.875,11],"p":[130.48828125,83.33984375,57.109375,73.37890625,14],"h":[125.5078125,76.201171875,78.69140625,46.81640625,13],"u":[106.25,51.46484375,46.15234375,60.09765625,13],"q":[131.81640625,54.12109375,55.1171875,76.69921875,14],"e":[94.62890625,55.44921875,60.09765625,34.53125,13],"x":[74.70703125,41.5869140625,36.357421875,38.349609375,14],"t":[68.73046875,56.4453125,42.16796875,26.5625,8],"y":[88.65234375,58.76953125,39.84375,48.80859375,16],"i":[56.77734375,37.8515625,32.87109375,23.90625,3],"v":[74.90625,46.01953125,40.04296875,34.86328125,15],"w":[151.904296875,79.6875,78.193359375,73.7109375,23],"n":[105.5859375,54.78515625,58.76953125,46.81640625,13],"g":[146.923828125,69.228515625,56.279296875,90.64453125,14],"k":[106.58203125,85.6640625,59.765625,46.81640625,15],"f":[82.67578125,67.734375,61.7578125,20.91796875,11],"d":[138.45703125,56.77734375,78.69140625,59.765625,14],"o":[95.625,51.796875,47.314453125,48.310546875,14]} \ No newline at end of file +{"0":[149.580078125,77.03125,97.451171875,52.12890625,15],"1":[107.9765625,71.91796875,57.97265625,50.00390625,13],"2":[132.6796875,68.33203125,76.69921875,55.98046875,14],"3":[123.37332589285714,55.21205357142857,76.13002232142857,47.24330357142857,14],"4":[133.974609375,55.283203125,87.98828125,45.986328125,16],"5":[136.18024553571428,78.12220982142857,91.21372767857143,44.966517857142854,14],"6":[158.876953125,88.154296875,107.080078125,51.796875,15],"7":[98.3642578125,50.302734375,75.9521484375,22.412109375,14],"8":[167.841796875,89.6484375,110.56640625,57.275390625,15],"9":[158.37890625,78.69140625,114.55078125,43.828125,15],"y":[117.91259765625,78.81591796875,56.90185546875,61.0107421875,15.875],"c":[90.64453125,55.78125,47.48046875,43.1640625,13],"e":[135.80078125,74.375,90.478515625,45.322265625,15],"w":[153.896484375,82.177734375,91.640625,62.255859375,22],"p":[147.421875,92.802734375,70.72265625,76.69921875,15],"r":[64.1484375,52.79296875,43.23046875,20.91796875,10],"u":[110.234375,56.4453125,52.12890625,58.10546875,14],"m":[169.169921875,94.9609375,107.24609375,61.923828125,23],"o":[114.384765625,60.263671875,62.08984375,52.294921875,15],"v":[94.03125,51.3984375,54.984375,39.046875,16],"t":[98.9453125,69.7265625,62.75390625,36.19140625,11],"h":[131.62667410714286,80.96819196428571,90.50223214285714,41.124441964285715,14],"f":[98.61328125,70.72265625,77.6953125,20.91796875,11],"k":[133.2275390625,98.61328125,84.9169921875,48.310546875,14],"x":[106.58203125,57.939453125,55.947265625,50.634765625,16],"q":[146.97916666666666,60.540364583333336,70.27994791666667,76.69921875,15],"n":[110.56640625,59.931640625,69.7265625,40.83984375,14],"j":[76.69921875,32.87109375,34.86328125,41.8359375,6],"g":[166.47216796875,76.69921875,68.73046875,97.74169921875,15],"d":[147.919921875,59.765625,89.8974609375,58.0224609375,15],"s":[100.107421875,59.267578125,57.7734375,42.333984375,12],"b":[146.923828125,92.63671875,89.6484375,57.275390625,15],"i":[54.78515625,36.85546875,33.8671875,20.91796875,3],"a":[133.974609375,68.232421875,74.70703125,59.267578125,14]} \ No newline at end of file diff --git a/src/evaluate.ts b/src/evaluate.ts index 66632e6..881fe72 100644 --- a/src/evaluate.ts +++ b/src/evaluate.ts @@ -1,25 +1,32 @@ import {Image} from "image-js"; -let SAMPLE_J = "assets/sample-j.png"; let EMPTY = "assets/empty.jpg"; if (typeof window === "object") { - SAMPLE_J = chrome.runtime.getURL(SAMPLE_J); EMPTY = chrome.runtime.getURL(EMPTY); } else { - SAMPLE_J = `./src/${SAMPLE_J}`; EMPTY = `./src/${EMPTY}`; } +/* +Image is first splitted into individual characters by finding empty line between +characters. + +Then each character is evalauated based on 5 factors: + - Average Pixel Value + - Horizontal Length of Image + - Average Pixel of Vertical Left Half of Image + - Average Pixel of Horizontal Top Half of Image + - Average Pixel of Horizontal Bottom Half of Image +*/ async function evaluate_captcha(img: Image): Promise>> { - let jd = (await Image.load(SAMPLE_J)).grey(); - let cleaned = await clean_image(img); let counter = 0; let matrix = []; let matrix_list = []; + // Splitting images by characters for (let i = 0; i < 130; i++) { let columnEmpty = true; for (let j = 0; j < 35; j++) { @@ -53,38 +60,13 @@ async function evaluate_captcha(img: Image): Promise>> { let hAvg = htopavg(temp_img); let hbtAvg = hbotavg(temp_img); - if (average > 165) { - let clean_char = to_image(cutoff_j(char_mat)).rotateRight().flipX(); - - let clean_char_sum_avg = - clean_char.getSum().reduce((acc, val) => {return acc + val}) / 256; - - averages.push([ - clean_char_sum_avg, - vavg(clean_char), - htopavg(clean_char), - hbotavg(clean_char), - clean_char.width, - ]); - - let jd_char_sum_avg = - jd.getSum().reduce((acc, val) => {return acc + val}) / 256; - - averages.push([ - jd_char_sum_avg, - vavg(jd), - htopavg(jd), - hbotavg(jd), - jd.width, - ]); - } else { - averages.push([ average, vAvg, hAvg, hbtAvg, char_mat.length / 35 ]); - } + averages.push([ average, vAvg, hAvg, hbtAvg, char_mat.length / 35 ]); }); return averages; } +// Pixel array to Image function to_image(matrix: Array, width = 35) { let image = new Image(width, matrix.length / width).grey(); @@ -97,6 +79,7 @@ function to_image(matrix: Array, width = 35) { return image; } +// Subtract the background noise image async function clean_image(img: Image) { let empty = (await Image.load(EMPTY)).grey(); let data = img.grey(); @@ -115,33 +98,7 @@ async function clean_image(img: Image) { return cleaned; } -function cutoff_j(matrix: Array) { - matrix.splice(matrix.length - 105, 105); - for (let i = 0; i <= 5; i++) { - for (let j = 0; j <= 6; j++) { - matrix[matrix.length - 35 * j - i - 1] = 0; - } - } - - let col_counter = 0; - for (let i = 0; i < matrix.length / 35; i++) { - let columnEmpty = true; - for (let j = 0; j < 35; j++) { - if (matrix[matrix.length - i * 35 - j - 1]) { - columnEmpty = false; - break; - } - } - if (!columnEmpty) { - break; - } - col_counter++; - } - - matrix.splice(matrix.length - col_counter * 35, col_counter * 35); - return matrix; -} - +// Average pixel value of horizontal top half function htopavg(char_img: Image) { let temp_img = char_img.crop({ y : 0, @@ -153,6 +110,7 @@ function htopavg(char_img: Image) { return (temp_img.getSum().reduce((acc, val) => acc + val) / 256); } +// Average pixel value of horizontal bottom half function hbotavg(char_img: Image) { let temp_img = char_img.crop({ y : Math.ceil(char_img.height / 2 + 1), @@ -164,6 +122,7 @@ function hbotavg(char_img: Image) { return (temp_img.getSum().reduce((acc, val) => acc + val) / 256); } +// Average pixel value of vertical half function vavg(char_img: Image) { let transformed_image = char_img.rotateRight();