forked from 9Axes/9axes.github.io
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfullquiz.html
More file actions
186 lines (165 loc) · 6.65 KB
/
Copy pathfullquiz.html
File metadata and controls
186 lines (165 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:400,700" rel="stylesheet">
<link href='style.css?v=20260312b' rel='stylesheet' type='text/css'>
<title>Quiz - 9Eixos</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
</head>
<body class="quiz-page full-quiz-page">
<script type="application/javascript" src="questions.js"></script>
<div class="quiz-shell">
<section class="quiz-header">
<h1>9Eixos</h1>
<p class="quiz-subtitle">Versão completa · 216 questões</p>
<h2 id="question-number">A carregar...</h2>
</section>
<p class="question" id="question-text"></p>
<section class="answer-grid">
<button class="button answer-button answer-level-3" onclick="next_question( 3)">Concordo totalmente</button> <br>
<button class="button answer-button answer-level-2" onclick="next_question( 2)">Concordo</button> <br>
<button class="button answer-button answer-level-1" onclick="next_question( 1)">Tendo a concordar</button> <br>
<button class="button answer-button answer-level-0" onclick="next_question( 0)">Não sei / Indeciso</button> <br>
<button class="button answer-button answer-level--1" onclick="next_question(-1)">Tendo a discordar</button> <br>
<button class="button answer-button answer-level--2" onclick="next_question(-2)">Discordo</button> <br>
<button class="button answer-button answer-level--3" onclick="next_question(-3)">Discordo totalmente</button> <br>
</section>
<section class="quiz-actions">
<button class="small_button" onclick="prev_question()" id="back_button">Anterior</button>
<button class="small_button_off" id="back_button_off">Voltar</button><br>
</section>
</div>
<script>
var scores = [0, 0, 0, 0, 0, 0, 0, 0, 0];//fed, dem, glo, mil, fre, equ, sec, pro, mul - User's scores
var qn = 0; // Question number
var answers = [];
var quests = [];
var axisMaxScores = [0, 0, 0, 0, 0, 0, 0, 0, 0];
init_all_questions(quests);
init_axis_max_scores();
init_question(quests);
function get_question_data(ax, rate, num) {
var entry = questions[ax][rate][num];
if (typeof entry === "string") {
return { question: entry, weight: 1 };
}
var text = entry.question || entry.text || "";
var parsedWeight = Number(entry.weight);
var weight = Number.isFinite(parsedWeight) && parsedWeight > 0 ? parsedWeight : 1;
return { question: text, weight: weight };
}
function init_axis_max_scores() {
for (var i = 0; i < quests.length; i++) {
var ax = quests[i][0];
var rate = quests[i][1];
var num = quests[i][2];
var questionData = get_question_data(ax, rate, num);
axisMaxScores[ax] += questionData.weight * 3;
}
}
function init_all_questions(qs) {
//1,2,3,-2,-4
for(var i = 0; i < 9; i++) //Number of Axes
{
for(var j = 0; j < questions[i].length; j++)
{
for(var k = 0; k < questions[i][j].length; k++)
{
var m = [i, j, k];
qs.push(m);
}
}
}
shuffle(qs);
}
function init_question() {
var ax = quests[qn][0];
var rate = quests[qn][1];
var num = quests[qn][2];
var questionData = get_question_data(ax, rate, num);
document.getElementById("question-text").innerHTML = questionData.question;
document.getElementById("question-number").innerHTML = "Questão " + (qn + 1) + " de " + (quests.length);
if (qn == 0) {
document.getElementById("back_button").style.display = 'none';
document.getElementById("back_button_off").style.display = 'block';
} else {
document.getElementById("back_button").style.display = 'block';
document.getElementById("back_button_off").style.display = 'none';
}
}
function shuffle(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;
}
function next_question(mult) {
var ax = quests[qn][0];
var rate = quests[qn][1];
var num = quests[qn][2];
var questionData = get_question_data(ax, rate, num);
var delta = mult * (rate<4?1:-1) * questionData.weight;
scores[ax] += delta;
answers[qn] = delta;
qn++;
if (qn < quests.length) {
init_question();
} else {
results();
}
}
function prev_question() {
if (qn == 0) {
return;
}
qn--;
var ax = quests[qn][0];
var rate = quests[qn][1];
scores[ax] -= answers[qn];
init_question();
}
function calc_score(score, axisMax) {
if (!axisMax) {
return 50;
}
var normalized = 50 + (score / axisMax) * 50;
return Math.max(0, Math.min(100, Math.round(normalized * 10) / 10));
}
function toBase64Url(value) {
return btoa(value).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
function signPayload(payload) {
var input = payload + "|9axes-share-v1|";
var hash = 0;
for (var i = 0; i < input.length; i++) {
hash = ((hash << 5) - hash) + input.charCodeAt(i);
hash |= 0;
}
return (hash >>> 0).toString(36);
}
function results() {
var scoreData = {
a: calc_score(scores[0], axisMaxScores[0]),
b: calc_score(scores[1], axisMaxScores[1]),
c: calc_score(scores[2], axisMaxScores[2]),
d: calc_score(scores[3], axisMaxScores[3]),
e: calc_score(scores[4], axisMaxScores[4]),
f: calc_score(scores[5], axisMaxScores[5]),
g: calc_score(scores[6], axisMaxScores[6]),
h: calc_score(scores[7], axisMaxScores[7]),
i: calc_score(scores[8], axisMaxScores[8])
};
var payload = toBase64Url(JSON.stringify(scoreData));
var signature = signPayload(payload);
location.href = `results.html?r=${payload}&s=${signature}`;
}
</script>
</body>