// colour_code_captcha.js
// RJM Programming
// May, 2024
// Use via
// Thanks to Mondrian and Pixabay at https://pixabay.com/illustrations/mondrian-red-blue-yellow-1504681/
var formelemofinterest=null, canvascaptcha=null, imgcaptcha=null, spancaptcha=null, submitcaptcha=null, iandcwidth=0, iandcheight=0, canvascaptchacontext=null;
var mcollist=['#000000', '#ffffff', '#ffff00', '#0000ff', '#f20d0d'], mcolrand=-1;
function ccc_rgbToHex(r, g, b) { // thanks to https://stackoverflow.com/questions/6735470/get-pixel-color-from-canvas-on-mousemove
if (r > 255 || g > 255 || b > 255)
throw 'Invalid color component';
return ((r << 16) | (g << 8) | b).toString(16);
}
function checkcaptcha(ev) {
var ccc_pos3=-1, ccc_pos4=-1;
ev.stopPropagation();
if (ev.touches) {
if (ev.touches[0].pageX) {
ccc_pos3 = ev.touches[0].pageX;
ccc_pos4 = ev.touches[0].pageY;
} else {
ccc_pos3 = ev.touches[0].clientX;
ccc_pos4 = ev.touches[0].clientY;
}
//console.log('ccc_pos3 = ' + ccc_pos3 + ',ccc_pos4 = ' + ccc_pos4);
} else if (ev.clientX || ev.clientY) {
ccc_pos3 = ev.clientX;
ccc_pos4 = ev.clientY;
//console.log('ccc_pos3 = ' + ccc_pos3 + ' ,ccc_pos4 = ' + ccc_pos4);
} else {
ccc_pos3 = ev.pageX;
ccc_pos4 = ev.pageY;
//console.log('ccc_pos3 = ' + ccc_pos3 + ', ccc_pos4 = ' + ccc_pos4);
}
if (canvascaptchacontext) {
var ccc_ctyqrect=ev.target.getBoundingClientRect();
//document.title=('x=' + eval(ccc_pos3 - ctyqrect.left) + ' and y=' + eval(ccc_pos4 - ctyqrect.top));
var myp = canvascaptchacontext.getImageData(Math.round(eval(ccc_pos3 - ccc_ctyqrect.left)), Math.round(eval(ccc_pos4 - ccc_ctyqrect.top)), 1, 1).data;
var myhex = ('#' + ('000000' + ccc_rgbToHex(myp[0], myp[1], myp[2])).slice(-6)).toLowerCase();
imgcaptcha.setAttribute('data-clickedcol', '' + myhex);
//alert('here clicking ' + submitcaptcha.outerHTML + imgcaptcha.getAttribute('data-clickedcol') + ' vs ' + mcollist[eval('' + formelemofinterest.getAttribute('data-need'))]);
if (('' + imgcaptcha.getAttribute('data-clickedcol')).replace('#','').toLowerCase() == mcollist[eval('' + formelemofinterest.getAttribute('data-need'))].replace('#','').toLowerCase()) {
submitcaptcha.style.display='block';
spancaptcha.style.display='none';
imgcaptcha.style.display='none';
}
submitcaptcha.click(); //formelemofinterest.submit();
}
}
function realonsubmitreturn() {
return onsubmitreturn();
}
function onsubmitreturn(arguin) {
var farris=[], vscanvasoh='', ifarris=0, newcimgis=null;
if (imgcaptcha && submitcaptcha && spancaptcha && canvascaptcha && formelemofinterest) {
if (('' + arguin).replace('null','').replace('undefined','') == '') {
arguin=imgcaptcha.getAttribute('data-clickedcol');
}
spancaptcha.style.display='inline';
imgcaptcha.style.display='block';
//alert('' + arguin + ' vs ' + mcollist[eval('' + formelemofinterest.getAttribute('data-need'))]);
if (('' + arguin).replace('#','').toLowerCase() == mcollist[eval('' + formelemofinterest.getAttribute('data-need'))].replace('#','').toLowerCase()) {
//alert('yay');
formelemofinterest.submit();
return true;
} else {
return false;
}
} //else {
//if (!imgcaptcha) { alert('no img'); }
//if (!spancaptcha) { alert('no span'); }
//if (!canvascaptcha) { alert('no canvas'); }
//if (!formelemofinterest) { alert('no form'); }
//}
if (!canvascaptcha) {
if (document.getElementById('canvascaptcha')) {
canvascaptcha=document.getElementById('canvascaptcha');
}
if (!formelemofinterest) {
if (('' + arguin).replace('null','').replace('undefined','') == '') {
farris=document.getElementsByTagName('form');
if (eval('' + farris.length) > 0) {
formelemofinterest=farris[0];
if (formelemofinterest.innerHTML.indexOf('';
canvascaptcha=document.getElementById('canvascaptcha');
}
if (!canvascaptcha) { return false; }
if (('' + canvascaptcha.getAttribute('data-initialized')).replace('null','').replace('undefined','') == '') {
newcimgis=new Image();
newcimgis.onload=function(e){
var osbit='';
iandcwidth=newcimgis.width;
iandcheight=newcimgis.height;
if (iandcwidth > 800) {
canvascaptcha.width=iandcwidth;
canvascaptcha.height=iandcheight;
} else {
canvascaptcha.width=800;
canvascaptcha.height=Math.round(newcimgis.height * 800 / newcimgis.width);
}
canvascaptchacontext=canvascaptcha.getContext('2d');
canvascaptchacontext.drawImage(newcimgis, 0, 0, newcimgis.width, newcimgis.height, 0, 0, canvascaptcha.width, canvascaptcha.height);
canvascaptcha.setAttribute('data-initialized', 'y');
mcolrand=eval(1 + Math.floor(Math.random() * eval(-1 + eval('' + mcollist.length))));
if (formelemofinterest.innerHTML.replace(/\"/g,'').replace(/\'/g,'').indexOf(' type=submit') == -1) {
formelemofinterest.innerHTML+='
Click below on same colour as background of this text. On success image disappears and you can retry.
';
submitcaptcha=document.getElementById('subcaptcha');
} else {
if (formelemofinterest.innerHTML.indexOf(' type="submit"') != -1) {
vscanvasoh='')[0] + '>';
farris=document.getElementsByTagName('input');
for (ifrarris=0; ifarris')[0] + '>';
farris=document.getElementsByTagName('input');
for (ifrarris=0; ifarris')[0] + '>';
farris=document.getElementsByTagName('input');
for (ifrarris=0; ifarris Click below on same colour as background of this text. On success image disappears and you can retry.