<html>
<head>
<title>Web Share API Usage - RJM Programming - July, 2022 ... thanks to https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share</title>
<script type='text/javascript'>
var twos=[], itwos=-1, woq=null;
var mexts = [".wav",".wav",".ram",".m3u",".aiff",".mp3",".rmi",
".snd",".ogg",".movie",".avi",".mov",".mp3",".m4v",".mpeg",
".lsx",".ogv",".webm",".m4a", ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif"];
var sofar='';

function eatatjoes() {
if (itwos == 0) {
if (document.getElementById('shareurl').value == '') {
document.getElementById('shareurl').placeholder=document.getElementById('shareurl').placeholder.replace(twos[0], twos[1]).replace(' PDF#', ' PDF Book#');
document.getElementById('sbut').value=document.getElementById('sbut').value.replace('Share URL Link', 'Share PDF Book Link');
document.getElementById('sbut').title='Double clicking textbox to right will try PDF Book in a new popup window';
}
itwos=1;
} else if (itwos == 1) {
if (document.getElementById('shareurl').value == '') {
document.getElementById('shareurl').placeholder=document.getElementById('shareurl').placeholder.replace(twos[1], twos[0]).replace(' PDF Book#', ' PDF#');
document.getElementById('sbut').value=document.getElementById('sbut').value.replace('Share PDF Book Link', 'Share URL Link');
document.getElementById('sbut').title='Double clicking textbox to right will make its placeholder the default textbox value';
}
itwos=0;
}
}

function changeu(inu) {
if (inu.indexOf('-0.pdf') != -1) {
trythis(inu);
}
}

function setupanimate(wsug, wsugzero, wsugthree) {
twos.push(wsugzero);
itwos=0;
twos.push(wsugthree);
setInterval(eatatjoes, 5000);
return wsug.replace('#' + wsugthree, '');
}

function doit(tv) {
document.getElementById('aag').href=document.getElementById('aag').href.split('&')[0] + '&delay=' + ('' + tv).replace('-','');
}

function basebit(inuis) {
if (inuis.indexOf('//') != -1) {
if (inuis.split('//')[1].indexOf('/') != -1) {
return inuis.replace(inuis.split('//')[0] + '//' + inuis.split('//')[1].split('/')[0] + '/','');
}
}
return inuis;
}

function trythis(inpdfidea) {
var andvideo='', videoand='';
if (('' + location.hash).indexOf('ffmpeg') != -1) { andvideo=' and Video'; videoand='Video and '; }
if (inpdfidea.toLowerCase().indexOf('-0.pdf') != -1) {
if (sofar.indexOf(' /pdfimageplustext.php?showpdf=' + encodeURIComponent(inpdfidea.split('#')[0])) == -1) {
sofar+=' /pdfimageplustext.php?showpdf=' + encodeURIComponent(inpdfidea.split('#')[0]);
woq=window.open('/pdfimageplustext.php?showpdf=' + encodeURIComponent(inpdfidea.split('#')[0]), '_blank', 'top=50,left=50,width=800,height=800'); // woq=window.open(inpdfidea.split('#')[0], '_blank', 'top=50,left=50,width=800,height=800');
if (document.getElementById('adown').innerHTML.indexOf(('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)]) == -1) {
document.getElementById('adown').innerHTML+=' <a style="text-decoration:none;cursor:pointer;background-color:yellow;border:2px solid red;margin: 13px 13px 13px 13px;" target=_blank title="Download ' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)] + ' PDF Book" href="' + inpdfidea.split('#')[0] + '" download>' + ' Download <font size=1>' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)] + '</font> PDF Book </a> <a style="text-decoration:none;cursor:pointer;background-color:pink;border:2px solid blue;margin: 13px 13px 13px 13px;" target=_blank title="Create ' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)].replace('-0.pdf','-ag.gif') + ' Animated GIF' + andvideo + '" href="/pdfimageplustext.php?first=' + encodeURIComponent(basebit(inpdfidea).split('#')[0].replace('-0.pdf','-0.jpg')) + '&delay=500' + '" id=aag>' + ' Create <font size=1>' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)].replace('-0.pdf','-ag.gif') + '</font> ' + videoand + 'Animated GIF Delay  </a> <input onchange=doit(this.value); type=number style=display:inline-block;background-color:pink; value=500 min=1 step=1 id=iag></input>';
}
}
}
return inpdfidea;
}

function downloadmaybe() {
var inpdfidea=document.getElementById('shareurl').value;
var ina=false;
if (inpdfidea.indexOf('.') != -1 && inpdfidea != '') {
var testext='.' + inpdfidea.split('#')[0].split('.')[eval(-1 + inpdfidea.split('#')[0].split('.').length)].toLowerCase();
ina=mexts.indexOf(testext);
}
if (inpdfidea.toLowerCase().indexOf('.pdf') != -1 || ina) {
if (sofar.indexOf(' /pdfimageplustext.php?showpdf=' + encodeURIComponent(inpdfidea.split('#')[0])) == -1) {
sofar+=' /pdfimageplustext.php?showpdf=' + encodeURIComponent(inpdfidea.split('#')[0]);
woq=window.open('/pdfimageplustext.php?showpdf=' + encodeURIComponent(inpdfidea.split('#')[0]), '_blank', 'top=50,left=50,width=800,height=800'); // woq=window.open(inpdfidea.split('#')[0], '_blank', 'top=50,left=50,width=800,height=800');
if (document.getElementById('adown').indexOf(inpdfidea.split('#')[0]) == -1) {
if (ina) {
document.getElementById('adown').innerHTML+=' <a style="text-decoration:none;cursor:pointer;background-color:yellow;border:2px solid red;margin: 13px 13px 13px 13px;" target=_blank title="Download ' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)] + '" href="' + inpdfidea.split('#')[0] + '" download>' + ' Download <font size=1>' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)] + '</font> </a>';
} else {
document.getElementById('adown').innerHTML+=' <a style="text-decoration:none;cursor:pointer;background-color:yellow;border:2px solid red;margin: 13px 13px 13px 13px;" target=_blank title="Download ' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)] + ' PDF" href="' + inpdfidea.split('#')[0] + '" download>' + ' Download <font size=1>' + ('/' + inpdfidea.split('#')[0]).split('/')[eval(-1 + ('/' + inpdfidea.split('#')[0]).split('/').length)] + '</font> PDF </a>';
}
}
}
}
return inpdfidea;
}


if (document.URL.indexOf('emojize=') != -1) {
setTimeout(function() {
document.getElementById('share').style.position='fixed';
document.getElementById('share').style.top='0px';
document.getElementById('share').style.left='0px';
document.getElementById('share').title='Share link via ...';
document.getElementById('share').style.backgroundColor='rgba(255,255,255,0.5)';
document.getElementById('share').innerHTML='&#' + decodeURIComponent(document.URL.split('emojize=')[1].split('&')[0].split('#')[0]).replace(/\&\#/g,'').replace(/\;/g,'').replace(/\./g,';&#') + ';';
document.getElementsByTagName('h2')[0].style.visibility='hidden';
document.getElementsByTagName('h3')[0].style.visibility='hidden';
document.getElementsByTagName('h4')[0].style.visibility='hidden';
document.getElementsByTagName('div')[0].style.visibility='hidden';
}, 2000);

}

</script>
</head>
<body onload="var suggestion=location.search.split('suggestion=')[1] ? decodeURIComponent(location.search.split('suggestion=')[1].split('&')[0]).replace(/\+/g,' ') : ''; if (suggestion != '') { var sugs=suggestion.split('#'); if (sugs.length >= 4) { suggestion=setupanimate(suggestion, sugs[0], sugs[3]); } document.getElementById('shareurl').placeholder=suggestion; document.getElementById('sbut').value+=' to content as below'; document.body.innerHTML+='<br><br><iframe style=width:100%;height:900px; src=/pdfimageplustext.php?pdffile=' + encodeURIComponent(suggestion.split('#')[0]) + '></iframe>'; }">
<style>
input { background-color: yellow; }
input[type=button] { background-color: orange; }
button { background-color: lightgreen; }
</style>
<h2>Web Share API Usage <span id=adown></span></h2>
<h3>RJM Programming - July, 2022</h3>
<h4>Thanks to <a target=_blank title='https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share' href='//developer.mozilla.org/en-US/docs/Web/API/Navigator/share'>https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share</a></h4><br>
<!--p><button>Share MDN!</button></p>
<p class="result"></p>
<script type='text/javascript'>

const shareData = {
title: 'MDN',
text: 'Learn web development on MDN!',
url: 'https://developer.mozilla.org'
}

const btn = document.querySelector('button');
const resultPara = document.querySelector('.result');

// Share must be triggered by "user activation"
btn.addEventListener('click', async () => {
try {
await navigator.share(shareData)
resultPara.textContent = 'MDN shared successfully'
} catch(err) {
resultPara.textContent = 'Error: ' + err
}
});
</script-->

<div>
<label for="shareurl"><input type=button onclick='downloadmaybe(); shareurl();' id='sbut' value="Share URL Link"></input>: </label>
<input onblur=changeu(this.value); title='Suffix by hashtag 1 is text and hashtag 2 is title' style='width:45%;' type=url value='' placeholder='https://www.rjmprogramming.com.au/ITblog/#RJM Programming Blog#IT Blog' id=shareurl ondblclick="this.value=trythis(this.placeholder);"></input><br><br><span> ... and/or ... </span><br><br>
<label for="files"><input type=button onclick="document.getElementById('share').click();" value="Share media or document files"></input>: </label>
<input id="files" type="file" accept="image/*,video/*,audio/*,application/*,text/*" multiple>
</div><br><br>
<button id="share" type="button">Share your media or documents or link!</button>
<output id="output"></output>
<script type='text/javascript' src='/web_share_api_test.js' defer></script>
</body>
</html>