-
Notifications
You must be signed in to change notification settings - Fork 5
/
quiz.html
1 lines (1 loc) · 3.52 KB
/
quiz.html
1
<!DOCTYPE html><html lang="en-US"><head><title>LiberationValues</title><link href="./dist/style.css" rel="stylesheet" type="text/css"><link rel="icon" type="x-icon" href="./assets/icon.png"><link rel="shortcut icon" type="x-icon" href="./assets/icon.png"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="theme-color" content="#000000" data-react-helmet="true"><meta property="og:ttl" content="60"><meta property="og:title" content="LiberationValues"><meta property="og:type" content="website"><meta property="og:site_name" content="LiberationValues"><meta property="og:url" content="https://liberationvalues.github.io/"><meta property="og:description" content="LibertationValues is a political quiz aimed at anti-authoritarian leftists"><meta property="og:image" content="https://liberationvalues.github.io/assets/previcon.png"><meta property="og:image:width" content="1024"><meta property="og:image:height" content="1024"></head><body><label class="switch" for="theme-toggle"><input type="checkbox" id="theme-toggle" name="theme-toggle"><div class="slider"></div></label><h1>LiberationValues</h1><hr><h2 id="question-number"></h2><p class="question" id="question-text" title="Click to toggle between fixed and variable height"></p><button style="background-color: #1b5e20" id="button-0">Strongly Agree</button><button style="background-color: #4caf50" id="button-1">Agree</button><button style="background-color: #7de381" id="button-2">Partially Agree</button><button style="background-color: #bbbbbb" id="button-3">Neutral/Unsure</button><button style="background-color: #eb847c" id="button-4">Partially Disagree</button><button style="background-color: #f44336" id="button-5">Disagree</button><button style="background-color: #b71c1c" id="button-6">Strongly Disagree</button><button class="small-button" id="back-button">Back</button><script type="module">import{themeChange as t}from"./dist/common.js";function e(t,e){const n={};for(const[s,i]of e)n[s]=i+(t[s]??0);return n}t("theme-toggle");const n=await(await fetch("./dist/questions.json")).json(),s=new class{questions;_index=0;weights=[];constructor(t){this.questions=t}get index(){return this._index+1}get size(){return this.questions.length}get text(){return this.questions[this._index].question}nextQuestion(t){return this.weights[this._index]=t,this._index<this.questions.length-1?this.questions[++this._index].question:null}previousQuestion(){return this._index>0?this.questions[--this._index].question:null}calculateScores(){const t=this.questions.map(((t,e)=>{const n=Array.from(Object.entries(t.effect)),s=this.weights[e];return n.map((t=>[t[0],t[1]*s]))})).reduce(e,{}),n=this.questions.map(((t,e)=>Array.from(Object.entries(t.effect)).map((t=>[t[0],Math.abs(t[1])])))).reduce(e,{}),s={};for(const[e,i]of Object.entries(t)){const t=n[e],o=100*(t+i)/(2*t);s[e]=o.toFixed(1)}return"results.html?"+new URLSearchParams(s).toString()}}(n),i=document.getElementById("question-text"),o=document.getElementById("question-number");function r(t){i.textContent=t,o.textContent=`Question ${s.index} of ${s.size}`}for(let t=0;t<7;t++){const e=document.getElementById("button-"+t.toString());if(!e)continue;const n=1-1/3*t;e.addEventListener("click",(()=>{const t=s.nextQuestion(n);t?r(t):location.href=s.calculateScores()}))}document.getElementById("back-button")?.addEventListener("click",(()=>{const t=s.previousQuestion();t?r(t):window.history.back()})),i.addEventListener("click",(()=>{const t="255pt"===i.style.minHeight?"150pt":"255pt";i.style.minHeight=t})),r(s.text);</script></body></html>