summaryrefslogtreecommitdiff
path: root/blog/data
diff options
context:
space:
mode:
Diffstat (limited to 'blog/data')
-rw-r--r--blog/data/applefan.json526
-rw-r--r--blog/data/poll.js171
2 files changed, 0 insertions, 697 deletions
diff --git a/blog/data/applefan.json b/blog/data/applefan.json
deleted file mode 100644
index e8e09f9..0000000
--- a/blog/data/applefan.json
+++ /dev/null
@@ -1,526 +0,0 @@
-{
- "title":"Are you an Apple fanboy/fangirl?",
- "question":[
- {
- "initialization":[
- {
- "c":"",
- "s":"have_ios = + 0"
- },
- {
- "c":"",
- "s":"have_iph = + 0"
- },
- {
- "c":"",
- "s":"airpods_sane = + 0"
- }
- ],
- "precond":"",
- "type":"multi",
- "caption":"I have an/a...",
- "choice":[
- {
- "caption":"iPod (original/Photo/Classic)/iPod mini/iPod Nano (1G~5G)/iPod Shuffle",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"iPod Nano (6G, 7G)/iPod touch",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 1.5"
- }
- ],
- "setn":[]
- },
- {
- "caption":"iPhone",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 1.5"
- },
- {
- "c":"",
- "s":"have_ios = + 1"
- },
- {
- "c":"",
- "s":"have_iph = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"iPhone X",
- "setp":[
- {
- "c":"| have_iph gt 0",
- "s":"score = + score + 2"
- },
- {
- "c":"| have_iph lt 1",
- "s":"score = + score + 3.5"
- },
- {
- "c":"",
- "s":"have_ios = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"iPad original/Mini/Air",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2"
- },
- {
- "c":"",
- "s":"have_ios = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"iPad Pro",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2.5"
- },
- {
- "c":"",
- "s":"have_ios = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"Apple Watch",
- "setp":[
- {
- "c":"| have_ios gt 0",
- "s":"score = + score + 5"
- },
- {
- "c":"| have_ios lt 1",
- "s":"score = + score + 105"
- },
- {
- "c":"",
- "s":"airpods_sane = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"Macintosh before 1998",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 2"
- }
- ],
- "setn":[]
- },
- {
- "caption":"PowerBook or Power Mac",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 0"
- }
- ],
- "setn":[]
- },
- {
- "caption":"MacBook",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2"
- },
- {
- "c":"",
- "s":"airpods_sane = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"MacBook Air/Pro",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 1.5"
- },
- {
- "c":"",
- "s":"airpods_sane = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"iMac",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2"
- },
- {
- "c":"",
- "s":"airpods_sane = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"Mac Pro",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2.5"
- },
- {
- "c":"",
- "s":"airpods_sane = + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"Air Pods",
- "setp":[
- {
- "c":"| airpods_sane gt 0",
- "s":"score = + score + 10"
- },
- {
- "c":"| airpods_sane lt 1",
- "s":"score = + score + 110"
- }
- ],
- "setn":[]
- },
- {
- "caption":"HomePod",
- "setp":[
- {
- "c":"| have_ios gt 0",
- "s":"score = + score + 7"
- },
- {
- "c":"| have_ios lt 1",
- "s":"score = + score + 107"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I use Apple products because I am so dumb that I don't know how to use products from other vendors",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 10"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 0"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I use Apple products because they are far more superior than any other vendors' products",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 8"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 0"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I think Apple's products are worth all that money",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 5"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 1"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"Apple products suck, I have to use them for my work however",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 7.5"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 0"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I think Apple respects my freedom and privacy",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 10"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 2"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I bought refurbished Apple products because...",
- "choice":[
- {
- "caption":"I can't afford a normal Apple product but I really want one",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2"
- }
- ],
- "setn":[]
- },
- {
- "caption":"Finally there's an Apple product that falls into my affordable range. I took it into consideration.",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 2"
- }
- ],
- "setn":[]
- },
- {
- "caption":"I do not.",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 0"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"Keyboard on a MacBook (late 2016 and onward) is reliable and satisfying",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"I've never tried that",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 0"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I think that Apple products are more secure and resistant to malware attacks.",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 2"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 2"
- }
- ],
- "setn":[]
- }
- ]
- },
- {
- "initialization":[],
- "precond":"",
- "type":"single",
- "caption":"I am an Apple fanboy/fangirl.",
- "choice":[
- {
- "caption":"yes",
- "setp":[
- {
- "c":"",
- "s":"score = + score + 1"
- }
- ],
- "setn":[]
- },
- {
- "caption":"no",
- "setp":[
- {
- "c":"",
- "s":"score = + score - 1"
- }
- ],
- "setn":[]
- }
- ]
- }
- ],
- "verdict":[
- {
- "caption":"<h2>Apple Hater.</h2><p>This world needs more sanity like you.</p>",
- "precond":"| score lt -4"
- },
- {
- "caption":"<h2>What Apple?</h2><p>Just stay this way.</p>",
- "precond":"| score geq -4 & score lt 4"
- },
- {
- "caption":"<h2>Apple Adorer.</h2><p>No.</p>",
- "precond":"| score geq 4 & score lt 7"
- },
- {
- "caption":"<h2>Apple Fan.</h2><p>Stop it. Get some help.</p><p><a href=\"https://youtu.be/fkkDvKGcNSo?t=1081\">https://youtu.be/fkkDvKGcNSo?t=1081</a></p>",
- "precond":"| score geq 7 & score lt 20"
- },
- {
- "caption":"<h2>Incurable Apple Fan.</h2><p>Fuck off. Nothing will help.</p>",
- "precond":"| score geq 20"
- }
- ]
-}
diff --git a/blog/data/poll.js b/blog/data/poll.js
deleted file mode 100644
index 55b4e22..0000000
--- a/blog/data/poll.js
+++ /dev/null
@@ -1,171 +0,0 @@
-//By Chris Xiong, 2018
-//License: Expat
-let p=null;
-let Caption;
-let Choices;
-let Score;
-let Next;
-let values=[];
-let curq;
-function evalexpr(e)
-{
- let ret=0;
- let op=function(a,o,b){
- switch(o){
- case '+':return a+b;
- case '-':return a-b;
- case '*':return a*b;
- case '/':return a/b;
- }
- };
- for(let p=e.match(/[+\-*\/]/);p;p=e.match(/[+\-*\/]/))
- {
- let vp=e.match(/[A-Za-z]\w*/);
- if(vp)
- {
- const v=vp[0];
- if(values[v]===undefined)throw 'shit';
- ret=op(ret,p[0],values[v]);
- e=e.substr(vp.index+vp[0].length);
- }
- else
- {
- let np=e.match(/\d+(.\d*)?/);
- if(np)
- {
- const n=Number(np[0]);
- ret=op(ret,p[0],n);
- e=e.substr(np.index+np[0].length);
- }else throw 'shit';
- }
- }
- return ret;
-}
-function evalsetexpr(e)
-{
- const s=e.split('=');
- if(s.length<2)throw 'shit';
- values[s[0].trim()]=evalexpr(s[1]);
-}
-function evaltestexpr(e)
-{
- const m=e.match(/([A-Za-z]\w*)\s*(leq|geq|lt|gt)\s*([A-Za-z0-9.]*)/);
- if(!m)throw 'shit';
- const v=m[1],op=m[2],vr=m[3];
- const vv=values[v];
- const vvr=isNaN(Number(vr))?values[vr]:Number(vr);
- if(vv===undefined||vvr===undefined)throw 'shit';
- switch(op.trim())
- {
- case 'leq':return vv<=vvr;
- case 'geq':return vv>=vvr;
- case 'lt':return vv<vvr;
- case 'gt':return vv>vvr;
- }
- throw 'shit';
-}
-function evalcondexpr(e)
-{
- if(!e.trim().length)return true;
- let ret=false;
- let op=function(a,o,b){
- switch(o){
- case '|':return a||b;
- case '&':return a&&b;
- }
- };
- for(let p=e.search(/[|&]/);p!=-1;p=e.search(/[|&]/))
- {
- let np=e.substr(p+1).search(/[|&]/);
- let n=e.substr(p+1,np!=-1?np-1:undefined);
- ret=op(ret,e[p],evaltestexpr(n.trim()));
- e=np?e.substr(np):"";
- }
- return ret;
-}
-function initq()
-{
- const q=p.question[curq];
- for(let i=0;i<q.initialization.length;++i)
- {
- if(evalcondexpr(q.initialization[i].c))
- evalsetexpr(q.initialization[i].s);
- }
- if(!evalcondexpr(q.precond)){++curq;if(curq<p.question.length)initq();else finalize();}
-}
-function evalq()
-{
- if(curq>=p.question.length)return;
- const q=p.question[curq];
- let seln=0;
- for(let i=0;i<q.choice.length;++i)
- {
- const e=document.getElementById(`choice${i}`);
- if(e.checked)++seln;
- if(e.checked)
- {
- for(let j=0;j<q.choice[i].setp.length;++j)
- if(evalcondexpr(q.choice[i].setp[j].c))
- evalsetexpr(q.choice[i].setp[j].s);
- }
- else
- {
- for(let j=0;j<q.choice[i].setn.length;++j)
- if(evalcondexpr(q.choice[i].setn[j].c))
- evalsetexpr(q.choice[i].setn[j].s);
- }
- }
- if(!seln&&q.type=='single'){alert('Wanna cheat?...');return;}
- ++curq;
- if(curq==p.question.length)finalize();else{showq();initq();}
-}
-function showq()
-{
- const q=p.question[curq];
- Caption.innerHTML=q.caption;
- while(Choices.firstChild)Choices.removeChild(Choices.firstChild);
- for(let i=0;i<q.choice.length;++i)
- {
- const d=document.createElement('div');
- const e=document.createElement('input');
- e.type=q.type=='multi'?'checkbox':'radio';
- e.innerHTML=q.choice[i].caption;
- e.qid=i;e.id=`choice${i}`;
- e.setAttribute('name','choice');
- e.classList.add('check');
- const l=document.createElement('label');
- l.innerHTML=q.choice[i].caption;
- l.setAttribute('for',e.id);
- d.appendChild(e);
- d.appendChild(l);
- Choices.appendChild(d);
- }
- Score.innerHTML=`${values['score']}, Question ${curq+1}/${p.question.length}`;
-}
-function _init()
-{
- Caption=document.getElementById('qcaption');
- Choices=document.getElementById('qchoices');
- Score=document.getElementById('score');
- Next=document.getElementById('nextbtn');
- curq=0;values['score']=0;
- initq();showq();
-}
-async function init()
-{
- const resp=await fetch(new Request('/blog/data/applefan.json'));
- r=await resp.text();
- p=JSON.parse(r);
- _init();
-}
-function finalize()
-{
- Next.style.color='#888';
- Score.innerHTML=`${values['score']}, Question ${p.question.length}/${p.question.length}`;
- Caption.innerHTML='';
- Choices.innerHTML='';
- for(let i=0;i<p.verdict.length;++i)
- if(evalcondexpr(p.verdict[i].precond))
- Caption.innerHTML+=p.verdict[i].caption;
-}
-init();