forked from Deyvid777/dozenvalues
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.html
1 lines (1 loc) · 2.4 KB
/
quiz.html
1
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Dozenvalues</title><link rel="shortcut icon" href="./assets/icon.png" type="image/x-icon"><link href="./assets/icon.png" type="image/x-icon"><meta property="og:title" content="Dozenvalues"><meta property="og:image" content="https://quark88.github.io/dozenvalues/assets/icon.png"><meta property="og:url" content="https://quark88.github.io/dozenvalues"><meta property="og:type" content="Political test"><meta property="og:locale" content="en_US"><meta property="og:description" content="DozenValues is a political test that aims to map differing political perspectives onto six axes."><link rel="stylesheet" href="./dist/style.css"></head><body><h1 id="title"></h1><h2 id="question_number"></h2><p id="questiontext"></p><div id="buttonholder"></div><button id="back_button"></button><script type="module">import{getJson as t,getLanguage as e}from"./dist/common.js";const n=new URLSearchParams(document.location.search);let o=n.get("lang")??"en";const c=e(o);o=c.lang??o;const r="true"===n.get("rand"),l=t("questions-"+o);for(const t of Object.keys(c.quiztext.text))document.getElementById(t).textContent=c.quiztext.text[t];document.title=c.quiztext.text.title;const a=document.getElementById("buttonholder"),i=document.getElementById("questiontext"),d=document.getElementById("question_number");for(const[t,e]of c.quiztext.buttons.entries()){const n=document.createElement("button");n.textContent=e.text,n.style.backgroundColor=e.color,n.addEventListener("click",(()=>m(t))),a.appendChild(n)}document.getElementById("back_button").addEventListener("click",(()=>(u--,void(l[u]?h():window.history.back()))));const f=new Array(l.length),s=new Array(l[0].effect.length).fill(0);for(const t of l)t.effect.forEach(((t,e)=>s[e]+=Math.abs(t)));r&&(l.forEach(((t,e)=>t.ogIndex=e)),l.sort((()=>.5-Math.random())));let u=0;function m(t){f[u]=t,u++,l[u]?h():function(){const t=new Array(l[0].effect.length).fill(0),e=new Array(l[0].effect.length).fill(0),n=[1,.5,0,-.5,-1];let c=new Array(f.length);void 0!==l[0]?.ogIndex&&l.forEach(((t,e)=>c[t.ogIndex]=f[e]));f.forEach(((e,o)=>l[o].effect.forEach(((o,c)=>t[c]+=n[e]*o)))),s.forEach(((n,o)=>e[o]=Math.round((n+t[o])/(2*n)*1e3)/10)),window.location.href="results.html?lang="+o+"&score="+e.map((t=>t.toFixed(1))).join(",")}()}function h(){i.textContent=l[u].text,d.textContent=`${c.quiztext.question} ${u+1} ${c.quiztext.of} ${l.length}`}h();</script></body></html>