Skip to content

Organize all JavaScript code #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
paramt opened this issue May 17, 2019 · 0 comments
Open

Organize all JavaScript code #10

paramt opened this issue May 17, 2019 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@paramt
Copy link
Owner

paramt commented May 17, 2019

Move all JavaScript code into its own file

mathu/index.html

Lines 23 to 53 in b7f1391

<script>
window.onload = function(){
if(localStorage.getItem("name") !== null){
document.getElementById("name-input").value = localStorage.getItem("name");
}
if(localStorage.getItem("qCount") === null){
localStorage.setItem("qCount", 10);
};
if(localStorage.getItem("negSubtraction") === null){
localStorage.setItem("negSubtraction", true);
};
}
var btn = document.getElementById("submit");
function link(name){
if(name == name.toUpperCase()){
name = name.toLowerCase();
}
}
document.getElementById("name-input")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
btn.click();
}
});
</script>

mathu/settings.html

Lines 33 to 52 in b7f1391

<script>
window.onload = function(){
document.getElementById("qCount").value = localStorage.getItem("qCount");
document.getElementById("include-neg").checked = JSON.parse(localStorage.getItem("negSubtraction"));
}
function updateSettings(){
localStorage.setItem("qCount", document.getElementById("qCount").value);
localStorage.setItem("negSubtraction", document.getElementById("include-neg").checked);
}
function resetSettings(){
document.getElementById("qCount").value = 10;
document.getElementById("include-neg").checked = true;
localStorage.setItem("qCount", 10);
localStorage.setItem("include-neg", true)
}
</script>

mathu/submit.html

Lines 28 to 44 in b7f1391

<script>
var LIMIT = localStorage.getItem("qCount");
var score = window.atob(localStorage.getItem("score"));
var time = window.atob(localStorage.getItem("seconds"))/100;
document.getElementById("score").value = ((score/LIMIT)*100)/time;
document.getElementById("time").value = time;
document.getElementById("correct").value = score;
document.getElementById("total").value = LIMIT;
document.getElementById("name").value = localStorage.getItem('name');
document.getElementById("type").value = localStorage.getItem("type");
window.onload = function() {
document.getElementById("form").submit()
}
</script>

@paramt paramt assigned paramt and unassigned paramt May 17, 2019
@paramt paramt added enhancement New feature or request good first issue Good for newcomers labels May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant