<!doctype html>
<html>
<head>
<title>Absolute URL Gmail Style Linker - RJM Programming - June, 2019</title>
<style>
.uptop { vertical-align: top; }
</style>
<script type='text/javascript'>
// Thanks to https://stackoverflow.com/questions/41306338/match-any-group-of-characters-before-a-line-break-sign
// Thanks to https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression

var gmail_linker_prefix=" <a target=_blank class='gmail_style_link' title='Gmail style link' href='";
var gmail_linker_middle="'>";
var gmail_linker_suffix="</a> ";
var lastlinks=[], lastcontents=[], lasturls=[], urlstotry=[], iurls=0;
var zhr=null, am_sending=false;
var elem=null, context;
var sofar='~';

// RegExp.quote = function(str) {
// return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
// };

function showStuff(evt) {
var huhs=[];
if (zhr.readyState == 4) {
if (zhr.status == 200) {
//alert(zhr.responseText);
if (document.getElementById('wikiopt').value.indexOf('5') != -1) {
if (('~' + zhr.responseText + '~').indexOf('~<img ') != -1 && ('~' + zhr.responseText + '~').indexOf('</img>~') != -1) {
lastcontents[iurls]=zhr.responseText;
document.getElementById('rightp').innerHTML=document.getElementById('rightp').innerHTML.replace(lasturls[iurls] + '</a>', zhr.responseText + lasturls[iurls] + '</a>');
}
}
huhs=sofar.split('~' + lasturls[iurls] + ';');
if (huhs.length > 1) {
document.getElementById('rightp').innerHTML=document.getElementById('rightp').innerHTML.replace(lasturls[iurls] + '</a>', huhs[1].split('~')[0] + '</a>');
}
am_sending=false;
zhr=null;
if (urlstotry.length > iurls) {
ajaxit(urlstotry[iurls]);
iurls++;
} else {
urlstotry=[];
}
}
}
}



function ajaxit(urltosend) {
if (urltosend.indexOf('wikipedia.org') != -1) {
if (!am_sending) {
am_sending=true;
zhr = new XMLHttpRequest();
var form=new FormData();
form.append('inurl', urltosend);
lasturls.push(urltosend);
lastcontents.push("");
zhr.open('post', '//www.rjmprogramming.com.au/PHP/fgc/', true);
zhr.onreadystatechange = showStuff;
zhr.send(form);
} else {
urlstotry.push(urltosend);
}
}
}


function futuremore(inw) {
var parts=inw.split(gmail_linker_prefix), lastlink='';
lastlinks=[];
iurls=0;
urlstotry=[];
for (var ij=1; ij<parts.length; ij++) {
if (parts[ij].indexOf(gmail_linker_middle) != -1 && parts[ij].indexOf(gmail_linker_suffix) != -1) {
if (lastlink != parts[ij].split(gmail_linker_middle)[0]) {
lastlink=parts[ij].split(gmail_linker_middle)[0];
lastlinks.push(lastlink);
if (document.getElementById('wikiopt').value != "") { ajaxit(lastlink); }
//alert(lastlink);
}
}
}
return inw;
}

function tostr(what) {
return gmail_linker_prefix + what + gmail_linker_middle + what + gmail_linker_suffix;
}

function preg_replace_http(ions) {
var aions=[], ij=0, aurl='';
if (document.getElementById('wikiopt').value.replace('2','3').indexOf('3') != -1) {
aions=ions.split("`");
for (ij=1; ij<aions.length; ij+=2) {
aurl=aions[ij].split("`")[0];
ions=ions.replace('`' + aurl + '`', "http://en.wikipedia.org/wiki/" + encodeURIComponent(aurl));
sofar+="http://en.wikipedia.org/wiki/" + encodeURIComponent(aurl) + ";" + aurl + "~";
}
}
return futuremore(ions.replace(/\ [hH][tT][tT][pP]([^\s]+)/g, tostr("\$&")).replace(/^[hH][tT][tT][pP]([^\n]+)/g, tostr("\$&") + String.fromCharCode(10)).replace(/\n[hH][tT][tT][pP]([^\n]+)/g, String.fromCharCode(10) + tostr("\$&") + "").replace(/\'\n[hH][tT][tT][pP]/g, "'http").replace(/\"\n[hH][tT][tT][pP]/g, '"http').replace(/\>\n[hH][tT][tT][pP]/g, '>http').replace(/\ [hH][tT][tT][pP]/g, "http"));
}

function conl() {
elem=document.getElementById('canvasid');
context=elem.getContext('2d');
}

function imgl(ioisi) {
if (ioisi.src != '') {
}
}

</script>
</head>
<body onload="conl();">
<h1>Absolute URL Gmail <select id=wikiopt style='display:inline-block;'><option value="53"> and Wikipedia (URLs and ` ` delimiting with first image)</option><option value="52"> and Wikipedia (` ` delimiting with first image)</option><option value="51"> and Wikipedia (URLs with first image)</option><option value="3"> and Wikipedia (URLs and ` ` delimiting)</option><option value="2"> and Wikipedia (` ` delimiting)</option><option value="1"> and Wikipedia (URLs)</option><option value=""></option></select> Style Linker</h1>
<h3>RJM Programming - June, 2019</h3>

<table border=5 cellpadding=5 cellspacing=5>
<tr><th>As if in Gmail Body Section (feel free to add Absolute URLs into text)</th><th></th><th>Linked Result (as if reading that Gmail message)</th></tr>
<tr><td class=uptop><textarea rows=30 cols=90 id=leftta></textarea></td><td><button style="background-color:yellow;" onclick="document.getElementById('rightp').innerHTML=preg_replace_http(document.getElementById('leftta').value).split(String.fromCharCode(10)).join('<br>');"><- Link - ></button></td><td class=uptop><p id=rightp></p></td></tr>
</table>
<input type=text style='position:absolute;left:-200px;top:-200px;' value=''></input>
<canvas id=canvasid style='display:none;'></canvas>
<img onload=-'imgl(this);' id=imgid style='display:none;' src=''></img>
</body>
</html>