<html>
<head>
<title>Find the Words Highlighting Game - RJM Programming - March, 2024</title>
<style>
* {
font-family: Courier New;
margin: 0 0 0 0;
padding: 0 0 0 0;
}

body {
background-color: yellow;
}

textarea {
background-color: rgb(250,250,250);
}

#results {
background-color: pink;
}
</style>
<script type='text/javascript'>
var thesel='', showsel=false, lastsel='', lesssel='';
var linesarr=[], colsarr=[], ilines=0, icols=0;
var complines=[], diagl=0;
var twowordstocheck=['',''];
var tworesults=['',''];
var xzhr=null, rhzx=null, curri=0, score=0, goes=0;
var sofar=';', documenttitle='';

function changedState() {
if (rhzx.readyState == 4) {
if (rhzx.status == 200) {
//alert(rhzx.response);
//document.getElementById('results').innerHTML+=rhzx.response.replace(/\</g, '<').replace(/\>/g, '>') + ' ... <p>' + twowordstocheck[curri] + '</p>';
if ((rhzx.response.indexOf(twowordstocheck[curri].toLowerCase()) == 0 || rhzx.response.indexOf('<p>' + twowordstocheck[curri].toLowerCase() + '</p>') != -1) && twowordstocheck[curri].trim() != '' && rhzx.response.trim() != '') {
tworesults[curri]=twowordstocheck[curri];
score+=eval('' + twowordstocheck[curri].length);
document.getElementById('score').innerHTML='&nbsp;Score: ' + score + '/' + goes;
document.getElementById('results').innerHTML+='&nbsp;Well done ' + ' ... found English word ' + twowordstocheck[curri].toLowerCase() + ' ... worth ' + eval('' + twowordstocheck[curri].length) + '<br>';
}
if (curri == 0) {
curri++;
rhzx = new XMLHttpRequest();
rhzx.onreadystatechange=stateChanged;
rhzx.open('get','/PHP/surprise.php?iswordthere=' + twowordstocheck[curri].toLowerCase() + '&youllneverfindthis=y',true);
rhzx.send(null);
} else {
document.getElementById('score').innerHTML='&nbsp;Score: ' + score + '/' + goes;
document.getElementById('myta').style.cursor='pointer';
document.getElementById('results').innerHTML+='<br><br>&nbsp;Ready for your next try!';
lastsel='';
}
}
}
}

function stateChanged() {
if (xzhr.readyState == 4) {
if (xzhr.status == 200) {
//alert(xzhr.response);
//document.getElementById('results').innerHTML+=xzhr.response.replace(/\</g, '<').replace(/\>/g, '>') + ' ... <p>' + twowordstocheck[curri] + '</p>';
if ((xzhr.response.indexOf(twowordstocheck[curri].toLowerCase()) == 0 || xzhr.response.indexOf('<p>' + twowordstocheck[curri].toLowerCase() + '</p>') != -1) && twowordstocheck[curri].trim() != '' && xzhr.response.trim() != '') {
tworesults[curri]=twowordstocheck[curri];
score+=eval('' + twowordstocheck[curri].length);
document.getElementById('score').innerHTML='&nbsp;Score: ' + score + '/' + goes;
document.getElementById('results').innerHTML+='&nbsp;Well done ' + ' ... found English word ' + twowordstocheck[curri].toLowerCase() + ' ... worth ' + eval('' + twowordstocheck[curri].length) + '<br>';
}
if (curri == 0) {
curri++;
rhzx = new XMLHttpRequest();
rhzx.onreadystatechange=changedState;
rhzx.open('get','/PHP/surprise.php?iswordthere=' + twowordstocheck[curri].toLowerCase() + '&youllneverfindthis=y',true);
rhzx.send(null);
} else {
document.getElementById('score').innerHTML='&nbsp;Score: ' + score + '/' + goes;
document.getElementById('myta').style.cursor='pointer';
document.getElementById('results').innerHTML+='<br><br>&nbsp;Ready for your next try!';
lastsel='';
}
}
}
}

function pickletters() {
var valis='', randval=eval(Math.floor(Math.random() * 26) % 26), ihis='';
for (var ir=1; ir<=40; ir++) {
for (var ic=1; ic<=80; ic++) {
valis+=String.fromCharCode(eval(randval + 'A'.charCodeAt(0)));
if (eval(linesarr.length) < ir) {
linesarr.push(valis.slice(-1));
} else {
linesarr[eval(-1 + ir)]+=valis.slice(-1);
}
if (eval(colsarr.length) < ic) {
colsarr.push(valis.slice(-1));
} else {
colsarr[eval(-1 + ic)]+=valis.slice(-1);
}
ihis+=String.fromCharCode(eval(randval + 'A'.charCodeAt(0)));
randval=eval(Math.floor(Math.random() * 26) % 26);
}
if (ir < 50) {
valis+=String.fromCharCode(10);
ihis+='<br>';
}
}
//alert(valis);
document.getElementById('myta').value=valis;
}

function showthesel() {
var uwords=[], iuw=1, ils=0;
if (showsel) {
document.getElementById('results').innerHTML=documenttitle + '<br><br>';
document.title='Find the Words Highlighting Game - RJM Programming - March, 2024';
document.getElementById('myta').style.cursor='progress';
//document.getElementById('myta').setAttribute('disabled', true);
showsel=false;
if (lastsel != thesel) {
lastsel=thesel;
thesel='';
}
if (lastsel != '' && thesel == '') {
curri=0;
goes++;
xzhr = new XMLHttpRequest();
xzhr.onreadystatechange=stateChanged;
xzhr.open('get','/PHP/surprise.php?iswordthere=' + twowordstocheck[0].toLowerCase() + '&youllneverfindthis=y',true);
xzhr.send(null);
}
}
}

function handleSelection() { // thanks to https://stackoverflow.com/questions/46651479/reacting-to-selection-changes-in-an-html-textarea
const activeElement = document.activeElement;

// Make sure this is your textarea
if (activeElement && activeElement.outerHTML.indexOf('<textarea') == 0) {
const range = {
start: activeElement.selectionStart,
end: activeElement.selectionEnd
};
// Do something with your range
if (eval('' + range.end) > eval('' + range.start)) {
thesel=(activeElement.value.substring(range.start).substring(0, eval(eval('' + range.end) - eval('' + range.start) )));
lesssel=thesel;
while (lesssel.indexOf(String.fromCharCode(10)) != -1) {
lesssel=lesssel.replace(String.fromCharCode(10), '');
}
complines=thesel.split(String.fromCharCode(10));
//diagl=eval('' + complines.length);
//diagl+=eval(eval(-1 + eval('' + complines.length)) * 80);
//document.title='' + eval('' + lesssel.length) + ' vs ' + eval(eval(eval(-1 + eval('' + complines.length)) * 80) + eval(2 - eval('' + complines.length)));
if (sofar.indexOf(';' + thesel + ';') != -1) {
document.title='Repeat selection ...';
} else if (sofar.indexOf(';' + thesel + ';') == -1 && eval('' + complines.length) >= 3 && eval('' + lesssel.length) == eval(eval(eval('' + complines.length) + eval(eval(-1 + eval('' + complines.length)) * 80)))) {
// 3 goes with 163 (2x80 + 3) or 159 (2x80 - 1)
// 4 goes with 244 (3x80 + 4) or 238 (3x80 - 2)
// 5 goes with 325 (4x80 + 5) or 317 (4x80 - 3)
icols=0;
twowordstocheck=[lesssel.substring(icols).substring(0,1), lesssel.substring(icols).substring(0,1)];
tworesults=['',''];
for (ilines=1; ilines<eval('' + complines.length); ilines++) {
icols+=81;
twowordstocheck[0]+=lesssel.substring(icols).substring(0,1);
twowordstocheck[1]=lesssel.substring(icols).substring(0,1) + twowordstocheck[1];
}
document.title='Left Diagonal words ' + twowordstocheck[0] + ' and ' + twowordstocheck[1] + ' being checked ...';
documenttitle='&nbsp;' + document.title;
document.getElementById('results').innerHTML=documenttitle;
sofar+=thesel + ';';
//document.getElementById('myta').style.cursor='progress';
if (!showsel) { setTimeout(showthesel, 5000); }
showsel=true;
} else if (sofar.indexOf(';' + thesel + ';') == -1 && eval('' + complines.length) >= 3 && eval('' + lesssel.length) == eval(eval(eval(-1 + eval('' + complines.length)) * 80) + eval(2 - eval('' + complines.length)))) {
// 3 goes with 163 (2x80 + 3) or 159 (2x80 - 1)
// 4 goes with 244 (3x80 + 4) or 238 (3x80 - 2)
// 5 goes with 325 (4x80 + 5) or 317 (4x80 - 3)
icols=0;
twowordstocheck=[lesssel.substring(icols).substring(0,1), lesssel.substring(icols).substring(0,1)];
tworesults=['',''];
sofar+=thesel + ';';
for (ilines=1; ilines<eval('' + complines.length); ilines++) {
icols+=79;
twowordstocheck[0]+=lesssel.substring(icols).substring(0,1);
twowordstocheck[1]=lesssel.substring(icols).substring(0,1) + twowordstocheck[1];
}
document.title='Right Diagonal words ' + twowordstocheck[0] + ' and ' + twowordstocheck[1] + ' being checked ...';
documenttitle='&nbsp;' + document.title;
document.getElementById('results').innerHTML=documenttitle;
//document.getElementById('myta').style.cursor='progress';
if (!showsel) { setTimeout(showthesel, 5000); }
showsel=true;
} else if (sofar.indexOf(';' + thesel + ';') == -1 && eval('' + complines.length) >= 3 && eval(-1 + eval('' + lesssel.length)) == eval(eval(eval(-1 + eval('' + complines.length)) * 80) + eval(0 * eval('' + complines.length)))) {
// 6 goes with 401
// 4 goes with 241
icols=0;
twowordstocheck=[lesssel.substring(icols).substring(0,1), lesssel.substring(icols).substring(0,1)];
tworesults=['',''];
sofar+=thesel + ';';
for (ilines=1; ilines<eval('' + complines.length); ilines++) {
icols+=80;
twowordstocheck[0]+=lesssel.substring(icols).substring(0,1);
twowordstocheck[1]=lesssel.substring(icols).substring(0,1) + twowordstocheck[1];
}
document.title='Down words ' + twowordstocheck[0] + ' and ' + twowordstocheck[1] + ' being checked ...';
documenttitle='&nbsp;' + document.title;
document.getElementById('results').innerHTML=documenttitle;
//document.getElementById('myta').style.cursor='progress';
if (!showsel) { setTimeout(showthesel, 5000); }
showsel=true;
} else if (sofar.indexOf(';' + thesel + ';') == -1 && thesel.indexOf(String.fromCharCode(10)) == -1 && eval('' + thesel.length) >= 3) {
//alert('Horizontal word ' + eval('' + thesel.length) + ' ... ' + thesel);
twowordstocheck=[lesssel, lesssel.split('').reverse().join('')];
tworesults=['',''];
sofar+=thesel + ';';
document.title='Horizontal words ' + twowordstocheck[0] + ' and ' + twowordstocheck[1] + ' being checked ...';
documenttitle='&nbsp;' + document.title;
document.getElementById('results').innerHTML=documenttitle;
//document.getElementById('myta').style.cursor='progress';
if (!showsel) { setTimeout(showthesel, 5000); }
showsel=true;
} else {
document.title='Find the Words Highlighting Game - RJM Programming - March, 2024';
}
}
}
}

document.addEventListener('selectionchange', handleSelection);


</script>
</head>
<body onload='pickletters();'>
<table id=mytable><tr><td>
<textarea style='overflow:hidden;font-size:14px;' cols=80 rows=40 id=myta></textarea>
</td><td>
<h1>&nbsp;Find the English Words <br>&nbsp;Highlighting Game</h1><br>
<h2>&nbsp;Horizontally, Vertically, Diagonally ... Reversed</h2><br>
<h3>&nbsp;RJM Programming - March, 2024</h3><br><br>
<h4 id=score>&nbsp;Score: 0/1</h4><br><br>
<div id=results></div>
</body>
</html>