<!DOCTYPE html>
<html>
<head>
<title>🕺 Disco Videos - Dynamic Javascript and the YouTube API - Thanks to https://developers.google.com/youtube/iframe_api_reference ... RJM Programming - May, 2018</title>
<meta charset="UTF-8">
<style>
details > summary::before {
content: '\01f57a';
}

span.curmark {
background-color: rgba(230,230,230,0.5);
color: black;
font-weight: bold;
}

span.oldmark {
background-color: rgba(230,230,230,0.5);
color: blue;
font-weight: normal;
}

#dd {
background-color: rgba(230,230,230,0.5);
}
</style>
</head>
<body><details title='🕺 Disco Videos - Dynamic Javascript and the YouTube API - Thanks to https://developers.google.com/youtube/iframe_api_reference ... RJM Programming - May, 2018' style=display:inline-block; id=dprex><summary id=prex></summary><div id="dd"></div></details><span id=zshuffle><a onclick="location.href='#dshuffle';" id=ashuffle title=Shuffles style='display:inline-block;font-size:8px;cursor:pointer;text-decoration:none;visibility:hidden;'>🔀</a></span>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<table title="Double click for full Disco Video list random play set of 9" ondblclick="location.href=document.URL.split('#')[0].split('?')[0];" onclick="dbck++; setTimeout(nodbck, 2000); if (dbck >= 2) { location.href=document.URL.split('#')[0].split('?')[0]; } if (fclick) { fclick=false; allok=0; }" id=mytable border=1 style=width:100%;height:100vh; title='🕺 Disco Videos - Dynamic Javascript and the YouTube API - Thanks to https://developers.google.com/youtube/iframe_api_reference ... RJM Programming - May, 2018'>
<tr><td id="vplayer1"></td><td id="vplayer2"></td><td id="vplayer3"></td></tr>
<tr><td id="vplayer4"></td><td id="vplayer5"></td><td id="vplayer6"></td></tr>
<tr><td id="vplayer7"></td><td id="vplayer8"></td><td id="vplayer9"></td></tr>
<tr style=display:none;><td id="vplayer10"></td><td id="vplayer11"></td><td id="vplayer12"></td></tr>
<tr style=display:none;><td id="vplayer13"></td><td id="vplayer14"></td><td id="vplayer15"></td></tr>
<tr style=display:none;><td id="vplayer16"></td><td id="vplayer17"></td><td id="vplayer18"></td></tr>
<tr style=display:none;><td id="vplayer19"></td><td id="vplayer20"></td><td id="vplayer21"></td></tr>
<tr style=display:none;><td id="vplayer22"></td><td id="vplayer23"></td><td id="vplayer24"></td></tr>
</table>
<div id=dshuffle style=visibility:hidden;display:inline-block;><a onclick="location.href='#ashuffle';" id=zshuffle title=Top style='display:inline-block;font-size:8px;cursor:pointer;text-decoration:none;visibility:hidden;'>🎥</a><br><select onclick=" noclick=true; document.getElementById('bshuffle').value='Shuffle'; " id=sshuffle style=display:inline-block; multiple><option onclick=gmlistit(this); value=''>Single selections shuffle with your choice first played (for up to 9 slots available), below ...</option></select> <input onclick=process(this); type=button id=bshuffle style=display:inline-block;background-color:yellow; value=Shuffle></input></div>
<script>
var numsleeps=700000;
var ix=0;
var mh='';
var wasdc='';
var fo=null;
var setu=false;
var scheck=true;
var d=new Date();
var marks=[new Date(), new Date()];
var imark=0;
var fclick=true;
var bigwhich=-1;
var oktomarkit=false;
var whichone=0;
var dbck=0;
var allok=0;
var eventtargetid='';
var lastallok='';
var noclick=false;
var cfrom=location.search.split('from=')[1] ? decodeURIComponent(location.search.split('from=')[1].split('&')[0]) : ' ';
var cto=location.search.split('to=')[1] ? decodeURIComponent(location.search.split('to=')[1].split('&')[0]).replace(cfrom,'') : ' ';
var ctitle=location.search.split('title=')[1] ? decodeURIComponent(location.search.split('title=')[1].split('&')[0]) : '';
var ajaxits=[];
var lastplay='';
var lastplaytwo='';
var sixt=1000; //6000;
var firstonly='';
var gmlist='';
var scoo='disco_yt_list';
var sbut='<span id="sd"><a href="#dshuffle" title="Shuffle">🔀</a> <a onclick="askvs();" title=Videos>❓</a></span> ';
if (cookieAVal(scoo) != '') { sbut=sbut.replace('</span>', ' <a onclick="recall();" title="Recall ' + cookieAVal(scoo) + '">🍪</a></span>'); }
var xsbut=sbut;


if (!String.fromCodePoint) { // thanks to http://xahlee.info/js/js_unicode_code_point.html
// ES6 Unicode Shims 0.1 , © 2012 Steven Levithan , MIT License
String.fromCodePoint = function fromCodePoint () {
var chars = [], point, offset, units, i;
for (i = 0; i < arguments.length; ++i) {
point = arguments[i];
offset = point - 0x10000;
units = point > 0xFFFF ? [0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF)] : [point];
chars.push(String.fromCharCode.apply(null, units));
}
return chars.join("");
}
}

function nodbck() {
dbck=0;
}

function getsd() {
if (document.getElementById('sd')) {
return document.getElementById('sd').outerHTML;
}
return 'youllneverfindthis';
}

function cookieAVal(cName) {
if (document.cookie != '') {
var tCookie=document.cookie.split("; ");
for (var j=0; j<tCookie.length; j++) {
if (cName == tCookie[j].split("=")[0]) {
return decodeURIComponent(tCookie[j].split("=")[1]);
}
}
}
return '';
}

function recall() {
var uvbit=cookieAVal(scoo);
if (uvbit != '') {
location.href=document.URL.split('#')[0].split('?')[0] + '?mustbeone=' + encodeURIComponent(uvbit.split(',')[0]) + '&videolist=' + encodeURIComponent(uvbit);
}
}

function deleteACookie(goodname) {
var expireDate = new Date();
expireDate.setDate(expireDate.getDate()-1);
document.cookie = goodname + "=; expires=" + expireDate.toGMTString();
}

function setACookie(gname, qyst) {
if (cookieAVal(gname) != '') { deleteACookie(gname); }
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth()+6);
document.cookie = gname + "=" + encodeURIComponent(qyst) + "; expires=" + expireDate.toGMTString();
}

function gmlistit(invlo) {
var invl=invlo.value;
if (invl == '') { return ''; }
var isvalid=false;
var morethanone=0;
if (('' + invl).indexOf('|') != -1) {
if (gmlist.indexOf(invl.split('|')[0]) == -1) {
isvalid=true;
if (gmlist == '') {
gmlist=invl.split('|')[0];
} else {
gmlist+=',' + invl.split('|')[0];
}
}
// alert('gmlist=' + gmlist);
}

var sin=document.getElementById('sshuffle');
for (var ii=1; ii<sin.options.length; ii++) {
if (sin.options[ii].selected) {
morethanone++;
}
}

if (morethanone > 1) {
gmlist='';
isvalid=false;
}

for (var i=1; i<sin.options.length; i++) {
if (sin.options[i].selected) {
if (sin.options[i].innerText.indexOf(String.fromCodePoint(10004)) == -1) {
sin.options[i].innerText+=' ' + String.fromCodePoint(10004);
} else if (morethanone > 1) {
sin.options[i].innerText=sin.options[i].innerText.split(String.fromCodePoint(10004))[0] + String.fromCodePoint(10004);
}
if (sin.options[i].value.indexOf('|') != -1) {
if (gmlist.indexOf(sin.options[i].value.split('|')[0]) == -1) {
if (gmlist == '') {
gmlist=sin.options[i].value.split('|')[0];
} else {
gmlist+=',' + sin.options[i].value.split('|')[0];
}
sin.options[i].innerText+=' ' + gmlist.split(',').length;
}
}
} else if (morethanone > 1) {
if (sin.options[i].innerText.indexOf(String.fromCodePoint(10004)) != -1) {
sin.options[i].innerText=sin.options[i].innerText.split(String.fromCodePoint(10004))[0];
sin.options[i].style.backgroundColor='white';
}
}
}

if (isvalid) {
invlo.style.backgroundColor='rgb(230,230,230)';
invlo.innerText+=' ' + gmlist.split(',').length;
}
}

function askvs() {
var oldlist=(location.search.split('videolist=')[1] ? decodeURIComponent(location.search.split('videolist=')[1].split('&')[0]).replace(/\'/g,'').replace(/\"/g,'').replace(/\;/g,',') : 'h2r59-Xmge4,yT1iDKkZNYU,S-u6qdeaPoE,Nm-ISatLDG0,Gs069dndIYk,dwxjpIJm9JM,8iwBM_YB1sE,CS9OO0S5w2k,I_izvAbhExY,xFrGuyw1V8s,piIJk0CFjUo,gQ8O9SidZbs,_QNEf9oGw8o,1ff29VSvP_s,4-Vz6tNfV1Y,Zi_XLOBDo_Y,xfmZRiePkEM,iPUmE-tne5U,m5y2GaW0MZA,yioNn7XS-bw,XKuJUxGntRI,vsBak0oCgdY,eBpYgpF1bqQ,DVDCNmdi7QI');
var newlist=prompt('Please enter comma separated YouTube video ID list. Start with a space to save and be able to recall in cookies.', oldlist);
if (newlist != null) {
if (('~@!' + newlist).replace('~@! ','') != ('~@!' + newlist)) {
setACookie(scoo, ('~@!' + newlist).replace('~@! ','').replace(/\'/g,'').replace(/\"/g,'').replace(/\;/g,','));
newlist=('~@!' + newlist).replace('~@! ','');
if (oldlist == newlist.trim() && oldlist != 'h2r59-Xmge4,yT1iDKkZNYU,S-u6qdeaPoE,Nm-ISatLDG0,Gs069dndIYk,dwxjpIJm9JM,8iwBM_YB1sE,CS9OO0S5w2k,I_izvAbhExY,xFrGuyw1V8s,piIJk0CFjUo,gQ8O9SidZbs,_QNEf9oGw8o,1ff29VSvP_s,4-Vz6tNfV1Y,Zi_XLOBDo_Y,xfmZRiePkEM,iPUmE-tne5U,m5y2GaW0MZA,yioNn7XS-bw,XKuJUxGntRI,vsBak0oCgdY,eBpYgpF1bqQ,DVDCNmdi7QI') {
return '';
}
}
location.href=document.URL.split('#')[0].split('?')[0] + '?videolist=' + encodeURIComponent(newlist.replace(/\'/g,'').replace(/\"/g,'').replace(/\;/g,','));
}
}

function ajaxit(badurl, badtitle, ccit) {
var zhr = new XMLHttpRequest();
var zform=new FormData();
var pbl='';
zform.append('inline', '');
zform.append('to', 'rmetcalfe@rjmprogramming.com.au');
if (('' + ccit).indexOf('@') != -1) {
zform.append('cc', ccit);
pbl='public ';
}
zform.append('bcc', 'rmetcalfe15@gmail.com');
zform.append('subj', ('Video ' + badurl + ' unavailable ... ').replace(' ','') + pbl + ' disco moderation ... ' + badtitle);
var bigstr='';
var aform='';
if (cfrom.trim() != '' && cto.trim() != cfrom.trim() && ctitle != '') {
aform='<br><br><p>YouTube Video unavailable URL: <a target=_blank href=' + badurl + '>' + badurl + '</a></p><br><p>Video title (as known): ' + ctitle + '</p><br><p>Proposed Better YouTube URL: <a target=_blank href=' + cto + '>' + cto + '</a></p>';
bigstr='<bo' + 'dy><h1>Video ' + badurl + ' unavailable ... ' + pbl + ' disco moderation ... ' + badtitle + '</h1><a target=_blank title="?" href="//www.youtube.com/results?search_query=' + encodeURIComponent(badtitle) + '">Try this YouTube search</a>' + aform + '</body>';
} else if (cfrom.trim() != '' && cto.trim() != cfrom.trim()) {
aform='<br><br><p>YouTube Video unavailable URL: <a target=_blank href=' + badurl + '>' + badurl + '</a></p><br><p>Video title (as known): ' + badtitle + '</p><br><p>Proposed Better YouTube URL: <a target=_blank href=' + cto + '>' + cto + '</a></p>';
bigstr='<bo' + 'dy><h1>Video ' + badurl + ' unavailable ... ' + pbl + ' disco moderation ... ' + badtitle + '</h1><a target=_blank title="?" href="//www.youtube.com/results?search_query=' + encodeURIComponent(badtitle) + '">Try this YouTube search</a>' + aform + '</body>';
} else {
aform='<br><br><form target=_blank action=http://www.rjmprogramming.com.au/HTMLCSS/dynamic_js.htm method=GET><input type=hidden name=from value="' + badurl + '"></input><input type=hidden name=title value="' + badtitle + '"></input><br><br>New YouTube URL: <input style=width:350px; name=to type=text value="' + badurl + '"></input><br><br><input type=submit value=Moderate></input></form>';
bigstr='<bo' + 'dy><h1>Video ' + badurl + ' unavailable ... ' + pbl + ' disco moderation ... ' + badtitle + '</h1><a target=_blank title="?" href="//www.youtube.com/results?search_query=' + encodeURIComponent(badtitle) + '">Try this YouTube search</a>' + aform + '</body>';
}
zform.append('tdhuhta', bigstr);
zhr.open('post', '//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php', true);
console.log('badtitle=' + badtitle + ' and badurl='+ badurl);
zhr.send(zform);
}

function process(bsin) {
var jj=0, mbo='', mlist='', mdelim='';
var ajx=0;
var sin=document.getElementById(bsin.id.replace('b','s'));
for (var i=0; i<sin.options.length; i++) {
if (sin.options[i].selected) {
if (sin.options[i].value != '') {
ajx=1;
jj++;
if (mbo == '') { mbo=sin.options[i].value.split('|')[0]; }
mlist+=mdelim + sin.options[i].value.split('|')[0];
mdelim=',';
}
}
}
if (gmlist.indexOf(',') != -1) { // && mlist.indexOf(',') != -1) {
if (gmlist != mlist) {
if (eval('' + gmlist.split(',').length) >= eval('' + mlist.split(',').length)) {
jj=eval('-' + gmlist.split(',').length);
mlist=gmlist;
mbo=gmlist.split(',')[0];
}
}
}
gmlist='';
if (jj == 1) {
location.href=(document.URL.split('#')[0].replace('mustbeone=','mustxxxbeone=') + '&mustbeone=' + encodeURIComponent(mbo)).replace('.html&','.html?').replace('.htm&','.htm?').replace('.php&','.php?').replace('/&','/?');
} else if (jj > 1) {
location.href=(document.URL.split('#')[0].replace('mustbeone=','mustxxxbeone=').replace('videolist=','videoxxxlist=') + '&videolist=' + encodeURIComponent(mlist)).replace('.html&','.html?').replace('.htm&','.htm?').replace('.php&','.php?').replace('/&','/?');
} else if (jj < 0) {
location.href=document.URL.split('#')[0].split('?')[0] + '?mustbeone=' + encodeURIComponent(mbo) + '&videolist=' + encodeURIComponent(mlist);
}
if (jj == 0 && ajx == 0) {
if (ajaxits.length > 0) {
var ep=prompt('Email moderation form to?', '');
if (ep != null) { //ep=''; }
for (var iep=0; iep<ajaxits.length; iep++) {
//alert(ajaxits[iep].replace("'')", "'" + ep + "')"));
eval(ajaxits[iep].replace("'')", "'" + ep + "')"));
}
ajaxits=[];
}
} else {
ajaxit(cfrom, cto, prompt('Email moderation form to?', ''));
}
}
}

function ajaxitcheck() {
document.getElementById('mytable').click();
if (ajaxits.length > 0) {
for (var iep=0; iep<ajaxits.length; iep++) {
eval(ajaxits[iep]);
}
ajaxits=[];
}
}

function shuffle(array) { // thanks to https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
var currentIndex = array.length, temporaryValue, randomIndex;

// While there remain elements to shuffle...
while (0 !== currentIndex) {

// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}

return array;
}

var scont='<option value="">Single selections shuffle with your choice first played (for up to 9 slots available), below ...</option>';
var splaycnt=0;
var accountedFor=0;
var clickscore=[];
var isoks=[];
var vplayer=[];
var yid=['zPv0S1-ETdI','qYf35nBq8Oo','Se3kxManWUY','i7hk-TupE5g','LnK0tnaNUag','dbH4Amzn-Rk','BL-Jg7CyqLQ','0v7Ea7kg2gA','NRjWEE0hmjQ'];
yid=['ARt9HV9T0w8#GG','OAfxs0IDeMs#Heart','huavJMGUbiI#BB'];
yid=location.search.split('videolist=')[1] ? eval("['" + decodeURIComponent(location.search.split('videolist=')[1].split('&')[0]).replace(/\,/g,"','") + "']") : shuffle(['h2r59-Xmge4','yT1iDKkZNYU','S-u6qdeaPoE','Nm-ISatLDG0','Gs069dndIYk','dwxjpIJm9JM','8iwBM_YB1sE','CS9OO0S5w2k','I_izvAbhExY','xFrGuyw1V8s','piIJk0CFjUo','gQ8O9SidZbs','_QNEf9oGw8o','1ff29VSvP_s','4-Vz6tNfV1Y','Zi_XLOBDo_Y','xfmZRiePkEM','iPUmE-tne5U','m5y2GaW0MZA','yioNn7XS-bw','XKuJUxGntRI','vsBak0oCgdY','eBpYgpF1bqQ','DVDCNmdi7QI']); // T6fVDAjs9f0 Q8xuUdI1an0']); // https://www.youtube.com/watch?v=DVDCNmdi7QI
var mbo=location.search.split('mustbeone=')[1] ? decodeURIComponent(location.search.split('mustbeone=')[1].split('&')[0]) : '';

if (mbo != '') {
var oyid=[mbo];
for (var iu=0; iu<yid.length; iu++) {
if (yid[iu] != mbo) {
oyid.push(yid[iu]);
}
}
yid=oyid;
}

var dostop=true;
var done=[];
var stopthese=[];
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
//var vplayer1, vplayer2;
function onYouTubeIframeAPIReady() {
document.body.style.cursor='progress';
firstonly="playerVars: { 'autoplay': 1 },";
if (document.URL.replace('?mustJUNKbeone=','#mustJUNKbeone=').replace('?videolist=','#videolist=').replace('?from=','#from=').indexOf('?') == -1) {
firstonly='';
} else if (1 == 1) {
document.getElementById('prex').innerHTML='Click first video now ' + sbut + ' ...';
document.getElementById('mytable').click();
}
var thisfirstonly=firstonly;
if (thisfirstonly == '') { thisfirstonly="playerVars: { 'mute': 1 },"; }
for (var ii=1; ii<=yid.length; ii++) {
done.push(false);
if (eval('' + clickscore.length) <= eval(-1 + ii)) {
clickscore.push(0);
isoks.push(false);
}
vplayer.push(eval("new YT.Player('vplayer" + ii + "', { height: '240', width: '33%', videoId: '" + yid[-1 + ii] + "', " + thisfirstonly + " events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange, 'onError': onPlayerError }})"));
//vplayer[eval(-1 + eval('' + vplayer.length))].addEventListener('onError', onPlayerError);
thisfirstonly="playerVars: { 'mute': 1 },";
}
}

// pre-4. Are we being supervised.
function onClickReady(event, whichone) {
console.log('at onClickReady with ' + whichone);
if (oktomarkit) { clickscore[eval('' + whichone)]++; }
bigwhich=whichone;
if (oktomarkit) { markit(); }
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
var dis, cti, gvd, uri, jis, prv='', iyi=0, huht='';
uri=event.target.getVideoUrl();
jis=yid.indexOf(uri.split('=')[1].split('&')[0]);
dis=event.target.getDuration();
cti=event.target.getCurrentTime();
gvd=event.target.getVideoData().title;
yid[jis]+='|' + dis + '|' + cti + '|' + gvd;
//alert(yid[jis]);
splaycnt++;
if (splaycnt > 9) {
if (scont.indexOf(yid[jis]) == -1) {
prv=scont;
scont=prv.split('</option>')[0] + '</option><option onclick=gmlistit(this); value="' + yid[jis] + '">' + gvd + '</option>' + prv.replace(prv.split('</option>')[0] + '</option>','');
}
} else {
scont+='<option onclick=gmlistit(this); value="' + yid[jis] + '">' + gvd + '</option>';
if (splaycnt == 9 && yid.length > 9) {
for (iyi=0; iyi<yid.length; iyi++) {
if (scont.indexOf(yid[iyi]) == -1) {
try {
huht=yplayer[splaycnt].getVideoData().title;
prv=scont;
scont=prv.split('</option>')[0] + '</option><option onclick=gmlistit(this); value="' + yid[iyi] + '">' + gvd + '</option>' + prv.replace(prv.split('</option>')[0] + '</option>','');
} catch(rtde) {
}
}
}
}
}
// vplayer[eval(-1 + eval(0 + event.target.id))].addEventListener('onError', onPlayerError);
if (('' + dis) != '0') { isoks[eval(-1 + eval('' + event.target.id))]=true; } else if (1 == 1) { if (document.getElementById('bshuffle').value == 'Shuffle') { document.getElementById('bshuffle').value='Help Moderate Unavailable Videos or Shuffle'; } ajaxits.push("ajaxit('" + uri + "', '" + gvd + "', '');"); } else if (1 == 3) { alert('video ' + eval(-1 + eval('' + event.target.id)) + ' isunavailable'); }
try {
if (firstonly != '' && firstonly.trim() == firstonly && firstonly.indexOf(' ') == -1) {
firstonly=firstonly.replace(' ',' ');
//event.target.setVolume(70);
event.target.playVideo();
//alert('we did try');
} else {
event.target.playVideo();
}
if (!setu) { setu=true; setTimeout(undostop, 9000); }
} catch(gfdhg) { }
if (1 == 4) {
if (document.title.substring(0,1) > '9') {
document.title='' + eval(-1 + eval('' + event.target.id)) + ':' + dis;
} else {
document.title+=' ' + eval(-1 + eval('' + event.target.id)) + ':' + dis;
}
}
accountedFor++;
}


function onPlayerError(e) {
//alert('oops');
if (oktomarkit) {
//alert('allok=' + allok + ' and errorCode=' + ('' + e.data));
if (('' + e.data) == '100') {
//play next video
//alert('allok=' + allok);
if (allok <= 0) { vplayer[eval(-1 + eval(1 + eventtargetid) % eval('9'))].playVideo(); }
}
}
}

function markith(thed, theid, themid, addmode) {
var sofar='';
var ouremoji=String.fromCodePoint(128378);
var dprexc=document.getElementById('dprex').innerHTML.split('<div id="dd">')[0].split('</div>')[0];
dprexc=document.getElementById('dd').innerHTML; //.split('<div id="dd">')[0].split('</div>')[0];
var idp=false;
wasdc='';
while (dprexc.indexOf(ouremoji) != -1) {
dprexc=dprexc.replace(ouremoji,'');
idp=true;
}
if (idp) {
var blines=dprexc.split('<br>');
var newdc=blines[0] + '<br>';
sofar+=blines[0].split(' ... ')[0];
for (var inew=1; inew<blines.length; inew++) {
if (blines[inew].split(' ... ')[0] != blines[eval(-1 + inew)].split(' ... ')[0] && sofar.indexOf(blines[inew].split(' ... ')[0]) == -1) {
newdc+=blines[inew] + '<br>';
sofar+=blines[inew].split(' ... ')[0];
}
}
if (newdc != dprexc) {
dprexc=newdc;
}
wasdc=dprexc;
document.getElementById('dd').innerHTML=dprexc;
}
var mks=document.getElementsByTagName('span');
for (var imks=0; imks<mks.length; imks++) {
if (('' + mks[imks].id) == ('mark' + themid + theid)) {
mks[imks].className="curmark";
if (mks[imks].innerHTML.length != ('' + thed).length) { mks[imks].innerHTML=mks[imks].innerHTML.slice(eval('-' + ('' + thed).length)); }
} else if (('' + mks[imks].id).indexOf('mark') == 0) {
mks[imks].className="oldmark";
if (mks[imks].innerHTML.length != ('' + thed).length) { mks[imks].innerHTML=mks[imks].innerHTML.slice(eval('-' + ('' + thed).length)); }
}
}
if (document.getElementById('mark' + themid + theid) && addmode == 0) {
document.getElementById('mark' + themid + theid).innerHTML=ouremoji + thed;
return '';
}
if (addmode == 2) {
document.getElementById('dd').innerHTML=prexc + '<span class=curmask id=mark' + themid + theid + '>' + ouremoji + thed + '</span>';
return '';
} else if (addmode == 1) {
return ouremoji + thed;
} else if (addmode == 0) {
return '<span class=curmask id=mark' + themid + theid + '>' + ouremoji + thed + '</span>';
}
}


// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
function onPlayerStateChange(event) { //, whichone) {
//alert('event.target.id=' + event.target.id);
eventtargetid='' + event.target.id;
whichone=eval(-1 + eval('' + event.target.id));
if (oktomarkit || (!fo && event.data == YT.PlayerState.PLAYING && firstonly != '' && firstonly.trim() == firstonly && firstonly.indexOf(' ') == -1)) {
if (fo == null) { fo=event.target; }
}
//console.log('at onClickReady with ' + whichone + ':' + event.data + ' vs ' + YT.PlayerState.PLAYING + ' enjoy watching and listening to ' + event.target.getVideoData().title);
if (oktomarkit || (event.target == fo && event.data == YT.PlayerState.PLAYING && firstonly != '' && firstonly.trim() == firstonly && firstonly.indexOf(' ') == -1)) {
if (event.data == YT.PlayerState.PLAYING) {
if (oktomarkit && ('' + lastallok) != ('' + event.target.id) && eval(('' + event.target.id)) <= 9) {
allok++;
if (oktomarkit) { lastallok=('' + event.target.id); }
}
if (!scheck && oktomarkit && stopthese.length == 0) {
document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML.replace('</summary>', '</summary>' + '<div id="dd">' + '</div>');
scheck=true;
}
if (document.getElementById('prex').innerHTML.replace(getsd(), '').replace(/Click\ first\ video\ now\ /g,'').trim().replace(/\./g,'') == '') {
allok=1;
lastallok=('' + event.target.id);
document.getElementById('dprex').style.position='fixed';
document.getElementById('dprex').style.backgroundColor='yellow';
document.getElementById('dprex').style.border='1px dotted red';
document.getElementById('dprex').style.opacity='0.7';
document.getElementById('dprex').style.fontColor='blue';
document.getElementById('dprex').style.fontSize='16px';
document.getElementById('dprex').style.top='36%';
document.getElementById('dprex').style.left='0px';
document.getElementById('dprex').style.zIndex='20';
//} else {
// alert(document.getElementById('prex').innerHTML.trim().replace(/\./g,''));
}
if (oktomarkit && document.getElementById('prex').innerHTML.indexOf('Enjoy watching and ') == -1) {
//if (allok == 0) { allok=1; }
document.getElementById('prex').innerHTML='Enjoy watching and listening to ' + event.target.getVideoData().title + ' ... ' + sbut + d;
if (document.getElementById('markp' + event.target.id)) {
markith(d, event.target.id, 'p', 0);
} else {
mh=markith(d, event.target.id, 'p', 1);
if (wasdc != '') {
document.getElementById('dd').innerHTML='Enjoy watching and listening to ' + event.target.getVideoData().title + ' ... ' + mh + '<br>' + wasdc;
} else {
document.getElementById('dd').innerHTML+='Enjoy watching and listening to ' + event.target.getVideoData().title + ' ... ' + mh + '<br>';
}
}
}
event.target.setVolume(70); //event.target.unMute();
event.target.unMute();
} else if (document.getElementById('prex').innerHTML.replace(getsd(), '').replace(/Click\ first\ video\ now\ /g,'').trim().replace(/\./g,'') != '' && event.data == YT.PlayerState.PAUSED) {
if (oktomarkit && eval('' + allok) > 0) {
allok--;
}
if (oktomarkit) {
document.getElementById('prex').innerHTML='So long ' + event.target.getVideoData().title + ' ... ' + sbut + d;
if (eval('' + stopthese.length) == 0 && 1 == 9) {
//document.getElementById('dprex').innerHTML+='So long ' + event.target.getVideoData().title + ' ... ' + d + '<br>';
document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML.replace('</summary>', '</summary>' + '<div id="dd">' + '</div>');
}
}
} else if (document.getElementById('prex').innerHTML.replace(getsd(), '').replace(/Click\ first\ video\ now\ /g,'').trim().replace(/\./g,'') != '' && event.data == YT.PlayerState.ENDED) {
if (oktomarkit && eval('' + allok) > 0) {
allok--;
}
if (oktomarkit) {
document.getElementById('prex').innerHTML='So long sweet ' + '' + event.target.getVideoData().title + ' ... ' + sbut + d;
if (eval('' + stopthese.length) == 0) {
if (document.getElementById('marks' + event.target.id)) {
markith(d, event.target.id, 's', 0);
} else {
mh=markith(d, event.target.id, 's', 1);
if (wasdc != '') {
//alert('mh=' + mh + ' and ' + wasdc);
document.getElementById('dd').innerHTML='So long sweet ' + event.target.getVideoData().title + ' ... ' + mh + '<br>' + wasdc;
} else {
document.getElementById('dd').innerHTML+='So long sweet ' + event.target.getVideoData().title + ' ... ' + mh + '<br>';
}
}
}
}
if (allok <= 0) {
var ione=1;
eventtargetid='' + eval(eval(-1 + eval(ione + eval('' + event.target.id))) % eval('9'));
if (('' + eventtargetid).indexOf('-') != -1) { eventtargetid='0'; }
while (!isoks[eval('' + eventtargetid)]) {
ione++;
eventtargetid='' + eval(eval(-1 + eval(ione + eval('' + event.target.id))) % eval('9'));
if (('' + eventtargetid).indexOf('-') != -1) { eventtargetid='0'; }
//alert('moving onto ' + eventtargetid);
}
lastplay="vplayer[" + eventtargetid + "].playVideo();";
vplayer[eval('' + eventtargetid)].playVideo();
ione++;
eventtargetid='' + eval(eval(-1 + eval(ione + eval('' + event.target.id))) % eval('9'));
if (('' + eventtargetid).indexOf('-') != -1) { eventtargetid='0'; }
lastplaytwo="vplayer[" + eval('' + eventtargetid) + "].playVideo();";
}
}
clickscore[eval('' + whichone)]++;
}
bigwhich=whichone;
if (oktomarkit) { markit(); }
if (event.data == YT.PlayerState.PLAYING) { // && !done) {
document.getElementById('vplayer' + event.target.id).title=event.target.getVideoData().title;
if (fo == null) { fo=event.target; }
if (dostop) {
if (fo == null) { fo=event.target; }
stopthese.push(event.target);
//alert('here');
setTimeout(stopVideoH, sixt);
sixt+=100;
}
//done = true;
}
}

function undostop() {
if (cookieAVal(scoo) != '' && document.getElementById('dshuffle').innerHTML.indexOf('Recall') == -1) {
document.getElementById('dshuffle').innerHTML+=' <a style=display:inline-block; onclick="recall();" title="Recall ' + cookieAVal(scoo) + '">🍪</a>';
}
if (yid.length > 9 || 1 == 1) {
document.getElementById('ashuffle').style.visibility='visible';
document.getElementById('zshuffle').style.visibility='visible';
document.getElementById('sshuffle').size=eval(-1 + eval('' + scont.split('</option>').length));
document.getElementById('sshuffle').innerHTML=scont;
document.getElementById('dshuffle').style.visibility='visible';
document.body.style.cursor='pointer';
if (yid.length > 9) { setTimeout(oktomarkittrue, 9000); }
}
dostop=false;
if (1 == 1 && firstonly != '' && document.getElementById('prex').innerHTML.replace(getsd(), '').replace(/Click\ first\ video\ now\ /g,'').trim().replace(/\./g,'') == '') {
firstonly='';
//alert('About to try ' + stopthese.length);
//vplayer[0].playVideo();
}
if (eval('' + accountedFor) >= eval('' + yid.length)) { setTimeout(oktomarkittrue, 9000); }
allok=1;
//alert('Ouch');
//oktomarkit=true;
}

function stopVideoH() {
if (firstonly != '' && firstonly.trim() == firstonly) {
firstonly+=' ';
//alert('Not stopping ');
} else {
if (stopthese[0] != fo) { stopthese[0].stopVideo(); if (1 == 4) { stopthese[0].setVolume(70); } document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML.replace('</summary>', '</summary>' + '<div id="dd">' + '</div>'); }
}
stopthese.shift();
//if (stopthese.length == 0) { scheck=false; document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML; }
if (eval('' + stopthese.length) == 0 && firstonly != '' && document.getElementById('prex').innerHTML.replace(getsd(), '').replace(/Click\ first\ video\ now\ /g,'').trim().replace(/\./g,'') == '') {
firstonly='';
//alert('About To try');
//vplayer[0].playVideo();
}
if (eval('' + stopthese.length) == 0) {
scheck=false;
document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML.replace('</summary>', '</summary>' + '<div id="dd">' + '</div>');
}
document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML.replace('</summary>', '</summary>' + '<div id="dd">' + '</div>');
}

function agoit() {
if (lastplaytwo != '' && document.getElementById('prex').innerHTML.indexOf('....') != -1 && document.getElementById('prex').innerHTML.indexOf('So long ') == 0) {
eval(lastplaytwo);
}
lastplaytwo="";
}

function oktomarkittrue() {
//alert('ouch');
document.getElementById('dprex').innerHTML=document.getElementById('prex').outerHTML.replace('</summary>', '</summary>' + '<div id="dd">' + '</div>');
oktomarkit=true;
//document.body.style.cursor='pointer';
}

function sleep(ms) { // thanks to https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
return new Promise(resolve => setTimeout(resolve, ms));
}

async function demo() {
//console.log(numsleeps + ' Taking a break...' + d);
await sleep(2000);
d=new Date();
if (allok <= 1 && document.getElementById('prex')) {
if (cookieAVal(scoo) != '' && document.getElementById('zshuffle').innerHTML.indexOf('Recall') == -1) {
document.getElementById('zshuffle').innerHTML+=' <a style=display:inline-block; onclick="recall();" title="Recall ' + cookieAVal(scoo) + '">🍪</a>';
}
var ynft='youllneverfindthis';
if (document.getElementById('sd')) {
ynft=document.getElementById('sd').outerHTML;
}
if (document.getElementById('prex').innerHTML.replace(ynft, '').replace(/Click\ first\ video\ now\ /g,'').trim().replace(/\./g,'') != '') {
if (lastplay != '' && document.getElementById('prex').innerHTML.indexOf('....') != -1 && document.getElementById('prex').innerHTML.indexOf('So long ') == 0) {
//document.getElementById('prex').innerHTML+='.';
eval(lastplay);
lastplay="";
if (lastplaytwo != '') {
setTimeout(agoit, 2000);
}
} else {
document.getElementById('prex').innerHTML+='.';
}
}
}
//console.log(numsleeps + ' Two seconds later, showing sleep in a loop...' + d);

// Sleep in loop
for (let i = 0; i < 5; i++) {
if (i === 3) {
await sleep(2000);
d=new Date();
//console.log(numsleeps + ' ' + d);

}
}
numsleeps--;
if (('' + numsleeps) != '0' && ('' + numsleeps).indexOf('-') == -1) { setTimeout(demo, 1); }
}

function betw() {
var seconds = (marks[1].getTime() - marks[0].getTime()) / 1000;
//document.title+=' ' + 'It took ' + seconds + ' seconds (from ' + marks[0] + ' to ' + marks[1] + ') between clicks.';
//numsleeps=0;
}

function markit() {
d=new Date();
marks[imark]=d;
imark++;
console.log('mark ' + imark + ': ' + d);
if (imark == 2) { setTimeout(betw, 800); imark=0; }
}

demo();

//setTimeout(undostop, 9000);

if (cfrom.trim() != '' && cto.trim() != cfrom.trim()) {
ajaxit(cfrom, ctitle, '');
}

setTimeout(ajaxitcheck, 120000);

</script>
<div id=thecss></div>
</body>
</html>