Created
February 28, 2018 18:39
-
-
Save ACPixel/36fd3fa97df5b8e9f0311ef8a82cded6 to your computer and use it in GitHub Desktop.
Captcha finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doesClassExist = (c)=>{ | |
let item = document.getElementsByClassName(c); | |
if (item.length > 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
const detectCaptcha = ()=>{ | |
return new Promise((resolve, reject)=>{ | |
let res = false | |
let t1 = doesClassExist("recaptcha"); | |
let t2 = doesClassExist("coinhive-captcha"); | |
let t3 = doesClassExist("BDC_CaptchaDiv"); | |
let t4 = doesClassExist("tdImage_captchaImage"); | |
if (t1 === true || t2 === true || t3 === true || t4 === true) { | |
res = true; | |
} else { | |
let cCount = 0; | |
var word = "captcha", | |
queue = [document.body], | |
curr; | |
while (curr = queue.pop()) { | |
if (!curr.textContent.match(word)) continue; | |
for (var i = 0; i < curr.childNodes.length; ++i) { | |
switch (curr.childNodes[i].nodeType) { | |
case Node.TEXT_NODE : | |
if (curr.childNodes[i].textContent.match(word)) { | |
cCount++; | |
} | |
break; | |
case Node.ELEMENT_NODE : | |
queue.push(curr.childNodes[i]); | |
break; | |
} | |
} | |
} | |
if (cCount > 1) { | |
res = true; | |
} | |
} | |
resolve(res); | |
}) | |
} | |
// Example: | |
function documentReady(callback){ | |
// in case the document is already rendered | |
if (document.readyState!='loading') callback(); | |
// modern browsers | |
else if (document.addEventListener) document.addEventListener('DOMContentLoaded', callback); | |
// IE <= 8 | |
else document.attachEvent('onreadystatechange', function(){ | |
if (document.readyState=='complete') callback(); | |
}); | |
} | |
documentReady(() => { | |
detectCaptcha().then(res=>{ | |
if (res) { | |
console.log("Found a captcha, fill info but don't submit login form.") | |
} else { | |
console.log("Found no captcha. Continue with login automatically.") | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment