Add source files
This commit is contained in:
commit
49bed7259e
10 changed files with 1190 additions and 0 deletions
23
res/js/defs.js
Normal file
23
res/js/defs.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Stairway.js: a simple JavaScript privacy quiz
|
||||
* Copyright © 2021 luca0N!
|
||||
*
|
||||
* This file is part of Stairway.js.
|
||||
*
|
||||
* Stairway.js is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Stairway.js is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Stairway.js. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* E-mail contact: <luca0n@luca0n.com>.
|
||||
*/
|
||||
|
||||
var onReady;
|
39
res/js/io.js
Normal file
39
res/js/io.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Stairway.js: a simple JavaScript privacy quiz
|
||||
* Copyright © 2021 luca0N!
|
||||
*
|
||||
* This file is part of Stairway.js.
|
||||
*
|
||||
* Stairway.js is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Stairway.js is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Stairway.js. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* E-mail contact: <luca0n@luca0n.com>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to fetch the resource file and returns it via callback.
|
||||
* @param file The desired file.
|
||||
* @param callback A function(string) which will be used to return the result of the requested file.
|
||||
* @since 2021-05-27
|
||||
*/
|
||||
function sendGetRequest(file, listener){
|
||||
let request = new XMLHttpRequest();
|
||||
request.addEventListener('load', function(){
|
||||
listener(this.responseText);
|
||||
});
|
||||
request.open("GET", file);
|
||||
request.send();
|
||||
}
|
||||
|
||||
|
28
res/js/js.js
Normal file
28
res/js/js.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Stairway.js: a simple JavaScript privacy quiz
|
||||
* Copyright © 2021 luca0N!
|
||||
*
|
||||
* This file is part of Stairway.js.
|
||||
*
|
||||
* Stairway.js is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Stairway.js is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Stairway.js. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* E-mail contact: <luca0n@luca0n.com>.
|
||||
*/
|
||||
|
||||
window.onload = function() {
|
||||
document.getElementById('javascript-warning').innerText =
|
||||
'An error occurred.'; // This message should be hidden later on, but if it doesn't, then this means an error occurred.
|
||||
|
||||
onReady(); // Call onReady in order to execute main code (this calls whatever function was attached)..
|
||||
}
|
114
res/js/main.js
Normal file
114
res/js/main.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Stairway.js: a simple JavaScript privacy quiz
|
||||
* Copyright © 2021 luca0N!
|
||||
*
|
||||
* This file is part of Stairway.js.
|
||||
*
|
||||
* Stairway.js is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Stairway.js is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Stairway.js. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* E-mail contact: <luca0n@luca0n.com>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 2021-05-27
|
||||
* by luca0N! <https://www.luca0n.com>
|
||||
*/
|
||||
|
||||
// Attach setUpStrings() to onReady() in order to execute the main code as soon as possible. This overwrites onReady().
|
||||
onReady = setUpStrings;
|
||||
|
||||
/**
|
||||
* Replaces dummy strings with localized messages.
|
||||
* @since 2021-05-27
|
||||
*/
|
||||
function setUpStrings(){
|
||||
// Hide JavaScript warning message.
|
||||
document.getElementById('javascript-warning').style['display'] = 'none';
|
||||
let warning = document.getElementById('warning');
|
||||
warning.style['display'] = 'unset';
|
||||
// Get JSON file which contains all of the challenges required.
|
||||
sendGetRequest('privacy-quiz.en.json', function(text){
|
||||
let quiz = JSON.parse(text);
|
||||
|
||||
// Set up UI elements based on quiz metadata.
|
||||
let quizTitle = document.getElementById('quiz-title');
|
||||
quizTitle.innerText = quiz.title;
|
||||
quizTitle.style['display'] = 'unset';
|
||||
let quizAuthor = document.getElementById('quiz-author');
|
||||
quizAuthor.innerText = quiz.publisher;
|
||||
quizAuthor.style['display'] = 'unset';
|
||||
|
||||
let contents = quiz.contents;
|
||||
let elQuiz = document.getElementById('quiz'); // quiz div element.
|
||||
|
||||
for (let x = 0; x < contents.length; x++){
|
||||
//console.log(contents[x].title);
|
||||
let itemDiv = document.createElement('div');
|
||||
itemDiv.className = 'section-question';
|
||||
let itemTitle = document.createElement('p');
|
||||
itemTitle.innerText = contents[x].title;
|
||||
itemTitle.className = 'question';
|
||||
|
||||
itemDiv.appendChild(itemTitle);
|
||||
|
||||
if (contents[x].type === 'multiple' || contents[x].type === 'single'){
|
||||
// Generate a checkbox for each choice.
|
||||
for (let y = 0; y < contents[x].choices.length; y++){
|
||||
if (contents[x].choices.length != contents[x].values.length){
|
||||
console.error('Unable to add choice #' + (y + 1) + ' for question #' + (x + 1) + ': ' +
|
||||
contents[x].choices.length > contents[x].values.length ? 'missing values' : 'extra values found');
|
||||
continue;
|
||||
}
|
||||
|
||||
let questionInput = document.createElement('input');
|
||||
questionInput.type = contents[x].type === 'multiple' ? 'checkbox' : 'radio';
|
||||
if (contents[x].type === 'single')
|
||||
questionInput.name = 'sec.' + x + '.chg'; // choice group
|
||||
let currentId = 'sec.' + x + '.ch.' + y; // section, choice
|
||||
questionInput.id = currentId;
|
||||
let questionLabel = document.createElement('label');
|
||||
questionLabel.htmlFor = currentId;
|
||||
questionLabel.innerText = contents[x].choices[y];
|
||||
|
||||
itemDiv.append(questionInput);
|
||||
itemDiv.append(questionLabel);
|
||||
if (y < contents[x].choices.length)
|
||||
itemDiv.append(document.createElement('br')); // Add a line break if this is not the last question.
|
||||
}
|
||||
if (contents[x].type === 'single'){
|
||||
// This is a 'single' choice type question.
|
||||
// Add a button that clears the current question selection.
|
||||
let questionClear = document.createElement('button');
|
||||
questionClear.innerText = 'Clear';
|
||||
questionClear.onclick = function() {
|
||||
for (let y = 0; y < contents[x].choices.length; y++) // Iterate through all input tags.
|
||||
document.getElementById('sec.' + x + '.ch.' + y).checked = false; // Uncheck it.
|
||||
}
|
||||
itemDiv.append(questionClear); // Append the button to the item dit.
|
||||
}
|
||||
|
||||
} else console.warn('Warning: unknown type "' + contents[x].type + '" for question #' + (x + 1));
|
||||
|
||||
elQuiz.appendChild(itemDiv);
|
||||
}
|
||||
// Add the finish button.
|
||||
let finish = document.createElement('button');
|
||||
finish.innerText = 'Finish!';
|
||||
finish.onclick = function(){
|
||||
document.location = 'final.html';
|
||||
}
|
||||
elQuiz.appendChild(finish);
|
||||
warning.style['display'] = 'none';
|
||||
});
|
||||
}
|
129
res/privacy-rating.css
Normal file
129
res/privacy-rating.css
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Stairway.js: a simple JavaScript privacy quiz
|
||||
* Copyright © 2021 luca0N!
|
||||
*
|
||||
* This file is part of Stairway.js.
|
||||
*
|
||||
* Stairway.js is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Stairway.js is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Stairway.js. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* E-mail contact: <luca0n@luca0n.com>.
|
||||
*/
|
||||
|
||||
body {
|
||||
margin-left: 15%;
|
||||
margin-right: 15%;
|
||||
}
|
||||
|
||||
.warning {
|
||||
color: white;
|
||||
background-color: orange;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.badge-small {
|
||||
padding: 6px 6px 2px 6px;
|
||||
font-weight: bold;
|
||||
text-shadow: 0 0 2px #000c;
|
||||
}
|
||||
|
||||
.badge {
|
||||
padding: 14px;
|
||||
font-weight: bold;
|
||||
font-size: 32pt;
|
||||
box-shadow: 0px 0px 5px gray;
|
||||
text-shadow: 0 0 2px #000c;
|
||||
}
|
||||
|
||||
.grade-s {
|
||||
color: white;
|
||||
background: linear-gradient(#881df9, #881db9);
|
||||
border-radius: 24px;
|
||||
}
|
||||
.grade-a{
|
||||
color: white;
|
||||
background: linear-gradient(#50d50d, #0a0);
|
||||
border-radius: 18px;
|
||||
}
|
||||
.grade-b{
|
||||
color: white;
|
||||
background: linear-gradient(#afff00, #d4db00);
|
||||
border-radius: 12px;
|
||||
}
|
||||
.grade-c{
|
||||
color: white;
|
||||
background: linear-gradient(#ff0, #fc0);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.grade-d{
|
||||
color: white;
|
||||
background: linear-gradient(#f4a50d, #f36d0c);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.grade-e{
|
||||
color: white;
|
||||
background: linear-gradient(#ff7800, #bd0000);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.grade-f{
|
||||
color: white;
|
||||
background: linear-gradient(#ca0000, #4a0000);
|
||||
}
|
||||
|
||||
.section-question {
|
||||
margin-top: 32px;
|
||||
margin-bottom: 32px;
|
||||
padding: 15px;
|
||||
border-style: dashed;
|
||||
}
|
||||
|
||||
#warning {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#quiz-title, #quiz-author {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.question {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.section-report {
|
||||
margin-top: 12px;
|
||||
padding: 15px;
|
||||
border: solid;
|
||||
}
|
||||
|
||||
.report {
|
||||
font-weight: bold;
|
||||
}
|
||||
.report-class {
|
||||
padding: 4px 4px 0px 4px;
|
||||
text-shadow: 0 0 2px #0005;
|
||||
box-shadow: 2px 2px 2px #0004;
|
||||
}
|
||||
.report-good {
|
||||
color: white;
|
||||
background-color: #3C0;
|
||||
}
|
||||
.report-warning {
|
||||
background-color: yellow;
|
||||
}
|
||||
.report-bad {
|
||||
background-color: orange;
|
||||
}
|
||||
.report-critical {
|
||||
color: white;
|
||||
background-color: red;
|
||||
}
|
Reference in a new issue