TLAPhrases/docs/index.html

173 lines
5.8 KiB
HTML
Raw Permalink Normal View History

2018-12-08 22:54:47 +00:00
<html>
<head>
<title>Guess the video!</title>
2018-12-09 17:51:06 +00:00
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style>
2018-12-08 22:54:47 +00:00
body {
background-color: #68caff;
}
2018-12-09 17:51:06 +00:00
/*button {
background-color: #4C5FAA;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}*/
</style>
<meta charset="UTF-8"/>
2018-12-09 17:57:22 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Cache-Control" content="no-store" />
2018-12-09 17:51:06 +00:00
<script type="text/javascript">
2018-12-08 22:54:47 +00:00
async function getFile(reader){
let response = await fetch(document.URL.substr(0,document.URL.lastIndexOf('/'))+'/phrases.tsv');
2018-12-08 22:54:47 +00:00
let data = await response.blob();
reader.readAsText(data);
}
2018-12-08 22:54:47 +00:00
function getPhrase() {
good=Math.floor(Math.random() * data.length);
document.getElementById("phrase").innerText="\""+data[good][0]+"\"";
makeOptions();
}
2018-12-08 22:54:47 +00:00
var data=[];
var good=-1;
var loaded=false; //Because of caching, previously loaded videos are kept so loading takes some time - no longer the case
2018-12-09 22:44:57 +00:00
function doLoad() {
if(loaded) return;
if(document.getElementById("response")==null
|| document.getElementById("phrase")==null) return;
2018-12-09 22:44:57 +00:00
loaded=true;
var reader = new FileReader();
reader.onload = function(progressEvent){
// By lines
var lines = this.result.split('\n');
for(var i = 0; i < lines.length; i++){
var line = lines[i];
data[i] = line.split('\t');
for(var j = 0; j < data[i].length; j++)
data[i][j] = data[i][j].replace(/\\"/g, "\"");
2018-12-09 22:44:57 +00:00
if(data[i].length<3) data.splice(i, 1);
}
2018-12-09 22:44:57 +00:00
getPhrase();
};
getFile(reader);
}
window.onload = ()=>doLoad();
doLoad(); //So let's try loading ASAP, and if that fails then wait for the load event
/**
* Creates iframe and displays container div.
* @param videoID YouTube video ID
* @param blockID Container div ID
* @param iframeID Created Iframe ID
*/
function createIframe(videoID, blockID, iframeID) { //Create iframes each time so it's not recorded in history
const ifr = document.createElement("iframe"); //Create dynamically to prevent caching
ifr.id=iframeID;
ifr.width=496;
ifr.height=279;
ifr.frameborder=0;
ifr.allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture";
ifr.allowfullscreen=true;
ifr.src="https://www.youtube.com/embed/"+videoID;
const block=document.getElementById(blockID);
block.appendChild(ifr);
block.style.display="block";
}
2018-12-08 22:54:47 +00:00
function checkResp() {
const val = document.getElementById("response").value;
2018-12-08 22:54:47 +00:00
if(val<0) return;
console.log(data[val]);
createIframe(data[val][2], "respBlock", "respyt");
let res;
if(Number(val)===good) {
res=document.getElementById("resultH");
2018-12-08 22:54:47 +00:00
res.innerText="Correct!";
res.style.color="#00AA00";
2018-12-08 22:54:47 +00:00
res=document.getElementById("resultP");
2018-12-09 00:17:50 +00:00
res.innerHTML="Your answer is correct!<br>You can watch the video below:";
res.style.color="#00AA00";
2018-12-09 00:17:50 +00:00
document.getElementById("score").innerText++;
document.getElementById("score").innerText++;
document.getElementById("score").innerText++;
document.getElementById("score").innerText++; //Heh - fixes casting problems
2018-12-08 22:54:47 +00:00
}
else {
res=document.getElementById("resultH");
2018-12-08 22:54:47 +00:00
res.innerText="Wrong!";
res.style.color="#AA0000";
2018-12-08 22:54:47 +00:00
res=document.getElementById("resultP");
2018-12-09 00:17:50 +00:00
res.innerHTML="The correct answer is: \""+data[good][1]+"\"<br>"
+ "You can watch both of the videos below:";
res.style.color="#AA0000";
createIframe(data[good][2], "goodBlock", "goodyt");
2018-12-09 00:17:50 +00:00
document.getElementById("score").innerText--;
document.getElementById("score").innerText--;
2018-12-08 22:54:47 +00:00
}
document.getElementById("sendbtn").style.display="none";
document.getElementById("anotherbtn").style.cssText="";
2018-12-08 22:54:47 +00:00
}
2018-12-08 22:54:47 +00:00
function reset() {
document.getElementById("response").innerHTML='<option value="-1" default>-- Choose a video --</option>';
document.getElementById("goodBlock").style.display="none";
document.getElementById("respBlock").style.display="none";
document.getElementById("respyt").remove();
const goodyt=document.getElementById("goodyt");
if(goodyt)
goodyt.remove();
document.getElementById("sendbtn").style.cssText="";
document.getElementById("anotherbtn").style.cssText="display: none";
2018-12-08 22:54:47 +00:00
getPhrase();
}
2018-12-08 22:54:47 +00:00
function makeOptions() {
for(var i = (good>=2?good-2:0); i < data.length&&i<good+2; i++) {
var opt=document.createElement("option");
opt.value=i;
opt.text=data[i][1];
var resp=document.getElementById("response");
resp.insertBefore(opt, resp.children[Math.floor(Math.random() * resp.children.length)]);
}
}
</script>
2018-12-08 22:54:47 +00:00
</head>
<body>
<div style="max-width: 500px; margin: auto">
<h1>Guess the video!</h1>
<p>So you know those "info sections" in most of Tiffany's videos? Here you can see a word, phrase or sometimes a
sentence to comment on one of the videos. Can you guess which video it belongs to?</p>
<h4>Score: <span id="score">20</span></h4>
2019-09-23 09:00:35 +00:00
<h3 id="phrase">Loading...</h3>
<noscript><h3>Please enable JavaScript - it's needed for this game to work.</h3></noscript>
<select id="response" style="max-width: 500px">
<option value="-1" default>-- Choose a video --</option>
</select>
<br>
<button onclick="checkResp()" id="sendbtn">Send</button>
<button onclick="reset()" id="anotherbtn" style="display: none">Another one</button>
<div id="respBlock" style="display: none">
<h3 id="resultH"></h3>
<p id="resultP"></p>
<p>Your response:</p>
</div>
<div id="goodBlock" style="display: none">
<p>Correct video:</p>
</div>
2018-12-08 22:54:47 +00:00
</div>
</body>
</html>