// pattern_test.js // Help out HTML like pattern_test.htm // RJM Programming - February, 2021 // To suit validation on an input type=text for a comma separated list of positive integers var thisejajs=''; var spareejajs=''; if (typeof ejs !== 'undefined') { if (ejs.length == 0) { var ejajs=''; var ejpattern=''; var ejsuffix='0'; thisejajs=location.search.split("theelementid=")[1] ? decodeURIComponent(location.search.split("theelementid=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; ejajs=thisejajs; ejpattern=location.search.split("pattern=")[1] ? decodeURIComponent(location.search.split("pattern=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; } else { ejsuffix='' + eval(1 + eval('' + ejsuffix)); } ejajs=thisejajs; ejpattern=''; console.log(ejsuffix); setTimeout(preats, 0); } else { var ejs=[]; var ejajs=''; var ejpattern=''; var ejsuffix='0'; console.log('here'); thisejajs=location.search.split("theelementid=")[1] ? decodeURIComponent(location.search.split("theelementid=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; ejajs=thisejajs; ejpattern=location.search.split("pattern=")[1] ? decodeURIComponent(location.search.split("pattern=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; setTimeout(preats, 0); } //thisejajs=location.search.split("theelementid=")[1] ? decodeURIComponent(location.search.split("theelementid=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; //ejajs=thisejajs; //ejpattern=location.search.split("pattern=")[1] ? decodeURIComponent(location.search.split("pattern=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; spareejajs=thisejajs; //document.getElementById(thisejajs).onclick = //function ats(event) { function preats() { if (ejs.length > 0) { ejsuffix='' + eval(0 + eval('' + ejs.length)); } console.log('2:' + eval(1 + eval(ejsuffix))); if (thisejajs.trim() == '') { console.log('5:' + document.head.innerHTML.split('pattern_test.js?theelementid=').length); if (document.head.innerHTML.split('pattern_test.js?theelementid=').length >= eval(1 + eval(ejsuffix))) { if (ejs.length == 0) { ejsuffix='0'; } console.log('' + eval(1 + eval(ejsuffix))); if (ejpattern.trim() == '' && document.head.innerHTML.indexOf('&pattern=') != -1) { ejpattern=decodeURIComponent(document.head.innerHTML.split('&pattern=')[eval(1 + eval(ejsuffix))].split('&')[0].split("'")[0].split('"')[0].split('>')[0]); } thisejajs=document.head.innerHTML.split("pattern_test.js?theelementid=")[eval(1 + eval(ejsuffix))] ? decodeURIComponent(document.head.innerHTML.split("pattern_test.js?theelementid=")[eval(1 + eval(ejsuffix))].split('&')[0].split('>')[0].split('"')[0].split("'")[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; console.log('Thisejajs=' + thisejajs + ' via ' + document.head.innerHTML.split("pattern_test.js?theelementid=")[eval(1 + eval(ejsuffix))].substring(0,200)); } else if (document.body.innerHTML.split('?theelementid=').length >= eval(1 + eval(ejsuffix))) { if (ejpattern.trim() == '' && document.body.innerHTML.indexOf('&pattern=') != -1) { ejpattern=decodeURIComponent(document.body.innerHTML.split('&pattern=')[eval(1 + eval(ejsuffix))].split('&')[0].split("'")[0].split('"')[0].split('>')[0]); } thisejajs=document.body.innerHTML.split("?theelementid=")[eval(1 + eval(ejsuffix))] ? decodeURIComponent(document.body.innerHTML.split("?theelementid=")[eval(1 + eval(ejsuffix))].split('&')[0].split('>')[0].split('"')[0].split("'")[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; } else if (document.body.innerHTML.split('&theelementid=').length >= eval(1 + eval(ejsuffix))) { if (ejpattern.trim() == '' && document.body.innerHTML.indexOf('?pattern=') != -1) { ejpattern=decodeURIComponent(document.body.innerHTML.split('?pattern=')[eval(1 + eval(ejsuffix))].split('&')[0].split("'")[0].split('"')[0].split('>')[0]); } thisejajs=document.body.innerHTML.split("&theelementid=")[eval(1 + eval(ejsuffix))] ? decodeURIComponent(document.body.innerHTML.split("&theelementid=")[eval(1 + eval(ejsuffix))].split('&')[0].split('>')[0].split('"')[0].split("'")[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; } spareejajs=thisejajs; } ejs.push(thisejajs); console.log('.log=' + ejs.length); console.log('thisejajs=' + thisejajs); //console.log('.log=' + ejs.length); if (ejpattern == '') { ejpattern='[0-9,]*'; } document.getElementById(thisejajs).setAttribute('data-efsuffix', ejsuffix); document.getElementById(thisejajs).setAttribute('data-efpattern', ejpattern); document.getElementById(spareejajs).onclick = function ats(event) { var thestyle='', thescript=''; var ejsuff=event.target.getAttribute('data-ejsuffix'); //ejsuffix; var ejsuff=ejsuffix; var xejs=[]; for (var iio=0; iio "; thestyle+=String.fromCharCode(10) + "#" + xejs[eval('' + ejsuffix)] + " { "; thestyle+=String.fromCharCode(10) + " position: relative; "; thestyle+=String.fromCharCode(10) + " width: 90%; border-color: none; border-style: solid; "; thestyle+=String.fromCharCode(10) + "} "; thestyle+=String.fromCharCode(10) + "#" + xejs[eval('' + ejsuffix)] + ":invalid { "; thestyle+=String.fromCharCode(10) + " border-color: red; border-style: dashed; "; thestyle+=String.fromCharCode(10) + "} "; thestyle+=String.fromCharCode(10) + "#" + xejs[eval('' + ejsuffix)] + ":invalid::after { "; thestyle+=String.fromCharCode(10) + " content: '' attr(title) ''; "; thestyle+=String.fromCharCode(10) + " color: #FFF; "; thestyle+=String.fromCharCode(10) + " position: absolute; "; thestyle+=String.fromCharCode(10) + " left: 40%; "; thestyle+=String.fromCharCode(10) + " top: 0px; "; thestyle+=String.fromCharCode(10) + "} "; thestyle+=String.fromCharCode(10) + "#" + xejs[eval('' + ejsuffix)] + ":focus-within::after { "; thestyle+=String.fromCharCode(10) + " content: '' attr(title) ''; "; thestyle+=String.fromCharCode(10) + " color: #FFF; "; thestyle+=String.fromCharCode(10) + " position: absolute; "; thestyle+=String.fromCharCode(10) + " right: 550px; "; thestyle+=String.fromCharCode(10) + " top: 20px; "; thestyle+=String.fromCharCode(10) + "} "; thestyle+=String.fromCharCode(10) + " " + String.fromCharCode(10); //alert(thestyle); document.body.innerHTML+=thestyle; var ejtag = document.createElement('script'); ejtag.type='text/javascript'; thescript+=String.fromCharCode(10) + " var ejsajs" + ejsuffix + "='" + xejs[eval('' + ejsuffix)] + "'; "; thescript+=String.fromCharCode(10) + " var ejpattern" + ejsuffix + "='" + ejpattern + "'; "; thescript+=String.fromCharCode(10) + " var ejprev" + ejsuffix + "=''; "; thescript+=String.fromCharCode(10) + " var ejretval=''; "; thescript+=String.fromCharCode(10) + " var ejvalidilist=''; "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejpostonl" + ejsuffix + "() { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').setCustomValidity(''); "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejreval" + ejsuffix + "() { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').value=ejprev" + ejsuffix + "; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejonl" + ejsuffix + "() { "; thescript+=String.fromCharCode(10) + " if (('' + location.hash) != '') { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title='Regarding your invalid entry of ' + decodeURIComponent('' + location.hash).replace('#','') + ', ' + ('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder).substring(0,1).toLowerCase() + (document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder + ' ').substring(1); "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " ejprev" + ejsuffix + " = location.search.split('" + xejs[eval('' + ejsuffix)] + "=')[1] ? decodeURIComponent(location.search.split('" + xejs[eval('' + ejsuffix)] + "=')[1].split('&')[0]) : ''; "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + xejs[eval('' + ejsuffix)] + "').outerHTML.indexOf(' pattern=') == -1) { document.getElementById('" + xejs[eval('' + ejsuffix)] + "').pattern=ejpattern" + ejsuffix + "; } "; thescript+=String.fromCharCode(10) + " if (('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder) == '' && ('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title) != '') { document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder=document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title; } "; thescript+=String.fromCharCode(10) + " else if (('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder) != '' && ('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title) == '') { document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title=document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder; } "; thescript+=String.fromCharCode(10) + " else if (('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder) == '' && ('' + document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title) == '') { document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder='Please enter a comma separated positive integer list (where red dashed border flags invalid entry)'; document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title=document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder; } "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title = location.search.split('" + xejs[eval('' + ejsuffix)] + "=')[1] ? ('Thanks for entering the valid " + '"' + "' + decodeURIComponent(location.search.split('" + xejs[eval('' + ejsuffix)] + "=')[1].split('&')[0]) + '" + '"' + "').replace('Thanks for entering the valid " + '""' + "', document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder) : document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder; "; thescript+=String.fromCharCode(10) + " var theforms=document.getElementsByTagName('form'), thefid='myform'; "; thescript+=String.fromCharCode(10) + " if (ejprev" + ejsuffix + " != '') { setTimeout(ejreval" + ejsuffix + ",3000); } "; thescript+=String.fromCharCode(10) + " if (theforms.length > 0) { for (var theformslength=1; theformslength<=theforms.length; theformslength++) { if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' id=" + '"' + xejs[eval('' + ejsuffix)] + '"' + "') != -1) { "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + xejs[eval('' + ejsuffix)] + "').outerHTML.indexOf(' name=') == -1 && document.getElementById('" + xejs[eval('' + ejsuffix)] + "').outerHTML.indexOf(' id=') != -1) { document.getElementById('" + xejs[eval('' + ejsuffix)] + "').name=document.getElementById('" + xejs[eval('' + ejsuffix)] + "').id; } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' id=') == -1) { "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].id='myform'; "; thescript+=String.fromCharCode(10) + " } else { "; thescript+=String.fromCharCode(10) + " thefid=theforms[eval(-1 + theformslength)].id; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' action=') == -1) { "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].action=document.URL.split('#')[0].split('?')[0]; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' method=') == -1) { "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].method='GET'; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' onsubmit=') == -1) { console.log(67); "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].onsubmit = function(event) { return ejosb" + ejsuffix + "(event.target); }; "; thescript+=String.fromCharCode(10) + " } else { console.log(theforms[eval(-1 + theformslength)].outerHTML); } "; thescript+=String.fromCharCode(10) + " } } } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').oninvalid = function(event) { "; thescript+=String.fromCharCode(10) + " ejretval=event.target.value; "; thescript+=String.fromCharCode(10) + " if (event.target.title.indexOf(', ') != -1) { "; thescript+=String.fromCharCode(10) + " event.target.title=document.event.target.placeholder; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " event.target.setCustomValidity('Regarding your invalid entry of " + '"' + "' + ejretval + '" + '"' + ", ' + ('' + event.target.title).substring(0,1).toLowerCase() + (event.target.title + ' ').substring(1)); "; thescript+=String.fromCharCode(10) + " event.target.title=('Regarding your invalid entry of " + '"' + "' + ejretval + '" + '"' + ", ' + ('' + event.target.title).substring(0,1).toLowerCase() + (event.target.title + ' ').substring(1)); "; thescript+=String.fromCharCode(10) + " event.target.value=''; "; thescript+=String.fromCharCode(10) + " setTimeout(ejpostonl" + ejsuffix + ", 5000); "; thescript+=String.fromCharCode(10) + " }; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejosb" + ejsuffix + "(fois) { console.log(0); "; thescript+=String.fromCharCode(10) + " if (ejretval != '') { console.log(1); "; thescript+=String.fromCharCode(10) + " fois.action='#' + decodeURIComponent(ejretval); "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title.indexOf(', ') != -1) { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').title=document.getElementById('" + xejs[eval('' + ejsuffix)] + "').placeholder; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " ejretval=''; "; thescript+=String.fromCharCode(10) + " return false; "; thescript+=String.fromCharCode(10) + " } else { console.log(2); "; thescript+=String.fromCharCode(10) + " document.getElementById('" + xejs[eval('' + ejsuffix)] + "').setCustomValidity(''); "; thescript+=String.fromCharCode(10) + " ejvalidilist=document.getElementById('" + xejs[eval('' + ejsuffix)] + "').value; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " return true; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " if (ejsajs" + ejsuffix + ".trim() != '') { setTimeout(ejonl" + ejsuffix + ",2000); } " + String.fromCharCode(10); console.log(thescript); ejtag.src='data:text/javascript;base64,' + btoa(thescript); //alert(thescript.slice(-450)); document.head.appendChild(ejtag); ejsajs=''; } }; document.getElementById(spareejajs).click(); thisejajs=''; } //setTimeout(ats, eval(3000 + eval(1000 * ejsuffix)));