diff --git a/README.md b/README.md index bd66bd0..90be3d0 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ - [X] Timer is not working properly, fix it - [X] When user gets a question correct, automatically redirect to next question - [X] Add a live leaderboard -- [ ] Change frontend -- [ ] Add details in about section -- [ ] Cursor does not goes up in the editor, fix it +- [X] Change frontend - Leaderboard opening animation is inserted, might require to change other background colors and stuff later. +- [X] Add details in about section +- [X] Cursor does not goes up in the editor, fix it - [ ] Do Backend stuff - do not put keys as it is within the files -- [ ] Add feature to show code for sometime, say 5-10 seconds once per question +- [X] Add feature to show code for sometime, say 5-10 seconds once per question - [ ] Disable run button for the time compiler runs the code and returns the result to prevent multiple compiler runs -- [ ] Limit number of runs per question per user +- [X] Limit number of runs per question per user - feature not needed anymore diff --git a/blind_coding/blind_coding/settings.py b/blind_coding/blind_coding/settings.py index 7cf4434..d4e7522 100644 --- a/blind_coding/blind_coding/settings.py +++ b/blind_coding/blind_coding/settings.py @@ -137,5 +137,5 @@ MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(REPOSITORY_ROOT, 'media/') -clientId: "222a2ef84f6881409d32ae21369d1a32" -clientSecret:"67872757630a355db890ee74b6b20926cb9e025dbb444182df2bd2700fc64af1" +clientId = "222a2ef84f6881409d32ae21369d1a32" +clientSecret = "67872757630a355db890ee74b6b20926cb9e025dbb444182df2bd2700fc64af1" diff --git a/blind_coding/db.sqlite3 b/blind_coding/db.sqlite3 index b5ab100..6b7e412 100644 Binary files a/blind_coding/db.sqlite3 and b/blind_coding/db.sqlite3 differ diff --git a/blind_coding/main_app/__pycache__/urls.cpython-36.pyc b/blind_coding/main_app/__pycache__/urls.cpython-36.pyc new file mode 100644 index 0000000..c686f04 Binary files /dev/null and b/blind_coding/main_app/__pycache__/urls.cpython-36.pyc differ diff --git a/blind_coding/main_app/__pycache__/views.cpython-36.pyc b/blind_coding/main_app/__pycache__/views.cpython-36.pyc new file mode 100644 index 0000000..c6d899f Binary files /dev/null and b/blind_coding/main_app/__pycache__/views.cpython-36.pyc differ diff --git a/blind_coding/main_app/admin.py b/blind_coding/main_app/admin.py index 9e89a0c..3f569ee 100644 --- a/blind_coding/main_app/admin.py +++ b/blind_coding/main_app/admin.py @@ -1,7 +1,8 @@ from __future__ import unicode_literals from django.contrib import admin -from .models import Question,Userdata +from .models import Question,Userdata,Time_Penalty # Register your models here. admin.site.register(Question) admin.site.register(Userdata) +admin.site.register(Time_Penalty) \ No newline at end of file diff --git a/blind_coding/main_app/migrations/0002_auto_20200104_1324.py b/blind_coding/main_app/migrations/0002_auto_20200104_1324.py new file mode 100644 index 0000000..a500cd2 --- /dev/null +++ b/blind_coding/main_app/migrations/0002_auto_20200104_1324.py @@ -0,0 +1,43 @@ +# Generated by Django 2.2.7 on 2020-01-04 07:54 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('main_app', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='question', + name='weight', + field=models.IntegerField(default=10), + preserve_default=False, + ), + migrations.AddField( + model_name='userdata', + name='total_penalty', + field=models.IntegerField(default=0), + ), + migrations.CreateModel( + name='Time_Penalty', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('time_penalty', models.IntegerField(default=0)), + ('no_wa', models.IntegerField(default=0)), + ('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main_app.Userdata')), + ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='questions', to='main_app.Question')), + ], + options={ + 'unique_together': {('player', 'question')}, + }, + ), + migrations.AddField( + model_name='question', + name='time_penalty', + field=models.ManyToManyField(blank=True, null=True, through='main_app.Time_Penalty', to='main_app.Userdata'), + ), + ] diff --git a/blind_coding/main_app/migrations/0003_auto_20200104_1332.py b/blind_coding/main_app/migrations/0003_auto_20200104_1332.py new file mode 100644 index 0000000..ff0fc09 --- /dev/null +++ b/blind_coding/main_app/migrations/0003_auto_20200104_1332.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.7 on 2020-01-04 08:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main_app', '0002_auto_20200104_1324'), + ] + + operations = [ + migrations.AlterField( + model_name='question', + name='weight', + field=models.IntegerField(default=20), + ), + ] diff --git a/blind_coding/main_app/models.py b/blind_coding/main_app/models.py index f58d542..c5b5808 100644 --- a/blind_coding/main_app/models.py +++ b/blind_coding/main_app/models.py @@ -8,13 +8,16 @@ class Userdata(models.Model): score = models.IntegerField(default = 0) answerGiven = models.CharField(max_length = 10, default="00000") timeElapsed = models.IntegerField(default = 0) - + total_penalty=models.IntegerField(default = 0) + def __str__(self): return str(self.user_id.username) class Question(models.Model): qno=models.IntegerField(default=0) + weight = models.IntegerField(default=20) text = models.CharField(max_length=45000) + time_penalty = models.ManyToManyField(Userdata, through="Time_Penalty",blank=True,null=True) testcaseno=models.IntegerField(default=0) samplein = models.CharField(max_length=45000,default='') sampleout = models.CharField(max_length=45000,default='') @@ -27,3 +30,15 @@ class Question(models.Model): def __str__(self): return str(self.pk) + +class Time_Penalty(models.Model): + player = models.ForeignKey(Userdata, on_delete=models.CASCADE) + question = models.ForeignKey(Question, on_delete=models.CASCADE,related_name='questions') + time_penalty = models.IntegerField(default=0) + no_wa = models.IntegerField(default=0) + + class Meta: + unique_together = ("player", "question") + + def __str__(self): + return "{} : {}".format(self.player.name, self.question.qno) diff --git a/blind_coding/main_app/templates/loggedIn.html b/blind_coding/main_app/templates/loggedIn.html index 34eaf9e..724b4e2 100644 --- a/blind_coding/main_app/templates/loggedIn.html +++ b/blind_coding/main_app/templates/loggedIn.html @@ -11,6 +11,7 @@ + @@ -60,20 +61,23 @@
-
-
+
+
-

About

-
1. What is Lorem Ipsum?
-

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

-
2. Where does it come from?
-

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested.

-
+

Instructions

+
- There are five questions of varying difficulties and points associated with them.
Score associated are 20, 30, 40, 50, 60 points respectively.
+
- For every question, the first time you submit the correct answer, you are awarded points corresponding to that question and the time penalty is + also calculated which takes into consideration the time taken until last successful solve together with the number of wrong attempts
+
- Standings will be based on the points scored and in cases of clashes, time penalties are compared and one with lesser time penalty is better ranker
+
- Every time you give a correct answer, the question is automatically changed and code editor is reset.
+
- You have only two attempts throughout the event to see the code you have written. To see the code, press Show Code button near Run button.
+
- Don't try to open up the console or changing the window/tab. You'll be logged out immediately
+
diff --git a/blind_coding/main_app/views.py b/blind_coding/main_app/views.py index 3353103..3f163a3 100644 --- a/blind_coding/main_app/views.py +++ b/blind_coding/main_app/views.py @@ -1,24 +1,21 @@ from django.shortcuts import render,redirect -import requests - -# Create your views here. -def default(request): - return render(request,'loggedIn.html') - -def index(request): - return render(request,'index.html') -# -#def login(request): -# pass from django.shortcuts import render from django.http import JsonResponse,HttpResponseRedirect,HttpResponse -from .models import Userdata,Question +from .models import Userdata,Question,Time_Penalty from django.contrib.auth import logout +from django.contrib.auth.decorators import login_required + import json +import requests +import base64 +import time import blind_coding.settings as settings -from django.contrib.auth.decorators import login_required +def default(request): + return render(request,'loggedIn.html') +def index(request): + return render(request,'index.html') def login(request): # if request.POST: @@ -48,36 +45,56 @@ def question(request): print('hi') print(res['userScore']) return HttpResponse(json.dumps(res)) - + def runCode(request): postData = json.loads( request.body.decode('utf-8') ) - url = 'https://api.jdoodle.com/execute/' - print(postData) + url = 'https://api.judge0.com/submissions?base64_encoded=false&wait=false' que = Question.objects.get(qno=postData['qNo']) - postData['stdin'] = '3'+'\n'+que.test_case1+'\n'+que.test_case2+'\n'+que.test_case3 - postData['clientId'] = settings.clientId - postData['clientSecret'] = settings.clientSecret + stdin = '3'+'\n'+que.test_case1+'\n'+que.test_case2+'\n'+que.test_case3 + # postData['stdin'] = str(base64.b64encode(stdin.encode("utf-8"))) + postData['stdin'] = stdin + # postData['source_code'] = str(base64.b64encode(postData['source_code'].encode('utf-8'))) + print(postData) + response = requests.post(url,json=postData) resp = response.json() -# resp = json.loads(resp) + # resp = json.loads(resp) print('qNo',postData['qNo']) - print('jdoodle response json object: ',resp) - print('jdoodle output response: ',resp['output']) + print('response token: ',resp['token']) + + url2 = 'https://api.judge0.com/submissions/'+resp['token']+'?base64_encoded=false' + time.sleep(1) + resp = requests.get(url2).json() + if 'status' in resp: + if resp['status']['description'] == "Processing": + while resp['status']['description'] == "Processing": + resp = requests.get(url2).json() + print(resp) + # print('exit_code ',resp['exit_code']) + # print('exit_signal ',resp['exit_signal']) + # print( str(base64.b64decode(resp['stderr'].encode('utf-8').strip()), "utf-8") ) + # print('output response: ',resp['stdout']) res = {} #Get current user currUser = Userdata.objects.get(user_id = request.user) - - if resp['output'].find('error') != -1: - res['output'] = resp['output'] + if 'error' in resp: + res['stdout'] = 'error' + elif resp['status']['description'] != "Accepted": + if resp['stderr'] is not None: + res['stdout'] = resp['stderr'] + elif resp['compile_output'] is not None: + res['stdout'] = resp['compile_output'] + else: + res['stdout'] = 'error' else: quesNo = postData['qNo'] quesData = Question.objects.get(qno= quesNo) answer = quesData.test_case1_sol+'\n'+quesData.test_case2_sol+'\n'+quesData.test_case3_sol+'\n' print(answer) currUser.timeElapsed += int(postData['timeElapsed']) - if answer == resp['output']: + if answer == resp['stdout']: print('hurray') - res['output'] = 'Correct Answer' + res['stdout'] = 'Correct Answer' print(currUser.answerGiven) lst = list(currUser.answerGiven) print(lst) @@ -85,21 +102,34 @@ def runCode(request): print('Updating score for question no', ) lst[quesNo] = '1' currUser.answerGiven="".join(lst) - currUser.score+=10 + timepenalty , status =Time_Penalty.objects.get_or_create(player=currUser,question=que) + timepenalty.time_penalty=int(postData['timeElapsed'])+(0.2*timepenalty.no_wa*que.weight) + currUser.score+=que.weight + currUser.total_penalty+=timepenalty.time_penalty + timepenalty.save() currUser.save() else: - res['output'] = 'Wrong answer..' - - currUser.save() + timepenalty , status = Time_Penalty.objects.get_or_create(player=currUser,question=que) + print('hiii') + print('hola: ',timepenalty) + print('timepenalty_player',timepenalty.player) + timepenalty.no_wa+=1 + res['stdout'] = 'Wrong answer..' + timepenalty.save() + currUser.save() res['score'] = currUser.score + if currUser.answerGiven == "11111": + res['completedGame'] = 'true' + else: + res['completedGame'] = 'false' return HttpResponse(json.dumps(res)) def l_out(request): - logout(request) - return render(request,'index.html') + logout(request) + return render(request,'index.html') def leaderboard(request): - leaderboard = Userdata.objects.order_by('-score') + leaderboard = Userdata.objects.order_by('-score','total_penalty') print(leaderboard) username = [] score = [] diff --git a/blind_coding/static/css/style-1.css b/blind_coding/static/css/style-1.css index 66a7783..01f0583 100644 --- a/blind_coding/static/css/style-1.css +++ b/blind_coding/static/css/style-1.css @@ -37,7 +37,7 @@ outline: none; background: rgba(0,0,0,0.8); } -.about { +.instructions { color: white; display: none; position: absolute; @@ -178,8 +178,8 @@ nav#header ul a { .options { display: flex; - margin: 8px 0 0 0; - justify-content: space-around; + margin: 15px 0 0 0; + justify-content: center; } button { @@ -287,8 +287,14 @@ textarea:focus { background: black; } -.run,.submit{ +.bttn,.submit, #showCode{ width: 10vw; + background-color: rgba(57, 255, 216, 0.8); + transition: all 100ms ease-in 50ms; +} + +.bttn:nth-child(1) { + margin-right: 3.5vw; } #footer p { @@ -501,12 +507,7 @@ tr td, tr th { transition-delay: 0s; } -* { - -webkit-transition: 0.25s all ease; - -moz-transition: 0.25s all ease; - -o-transition: 0.25s all ease; - transition: 0.25s all ease; -} + /* Sidenav body */ @@ -588,7 +589,8 @@ a { #codeInput{ color: black; - caret-color: white; + caret-color: white; + transition: color 100ms ease-out; } ::selection{ diff --git a/blind_coding/static/css/style.css b/blind_coding/static/css/style.css index 117cf79..8a67107 100644 --- a/blind_coding/static/css/style.css +++ b/blind_coding/static/css/style.css @@ -29,7 +29,7 @@ body, html { background: rgba(0,0,0,0.8); } -.about { +.instructions { color: white; display: none; position: absolute; diff --git a/blind_coding/static/js/app.js b/blind_coding/static/js/app.js index 7f31c56..3ae6d45 100644 --- a/blind_coding/static/js/app.js +++ b/blind_coding/static/js/app.js @@ -1,11 +1,12 @@ // var request = require('request'); $(document).ready(function() { + populateLangs(); var inp = document.getElementsByClassName('noselect')[0]; -getQuestion(0); -inp.addEventListener('select', function() { - this.selectionStart = this.selectionEnd; -}, false); + getQuestion(0); + inp.addEventListener('select', function() { + this.selectionStart = this.selectionEnd; + }, false); document.addEventListener('contextmenu', event => event.preventDefault()); var ctrlDown = false, @@ -40,7 +41,7 @@ inp.addEventListener('select', function() { // Display/hide leaderboard let i = 0; $('.leaderboard-icon').click(function() { - $('.leaderboard').fadeToggle(); + $('.leaderboard').fadeToggle(650, "swing"); if (i === 0) { $('.li').html('cancel'); i = 1 @@ -70,6 +71,23 @@ let qNo = 0; let tc1 = ''; let tc2 = ''; let tc3 = ''; +let languageIDs = JSON.parse("[{\"id\":45,\"name\":\"Assembly (NASM 2.14.02)\"},{\"id\":46,\"name\":\"Bash (5.0.0)\"},{\"id\":47,\"name\":\"Basic (FBC 1.07.1)\"},{\"id\":48,\"name\":\"C (GCC 7.4.0)\"},{\"id\":52,\"name\":\"C++ (GCC 7.4.0)\"},{\"id\":49,\"name\":\"C (GCC 8.3.0)\"},{\"id\":53,\"name\":\"C++ (GCC 8.3.0)\"},{\"id\":50,\"name\":\"C (GCC 9.2.0)\"},{\"id\":54,\"name\":\"C++ (GCC 9.2.0)\"},{\"id\":51,\"name\":\"C# (Mono 6.6.0.161)\"},{\"id\":55,\"name\":\"Common Lisp (SBCL 2.0.0)\"},{\"id\":56,\"name\":\"D (DMD 2.089.1)\"},{\"id\":57,\"name\":\"Elixir (1.9.4)\"},{\"id\":58,\"name\":\"Erlang (OTP 22.2)\"},{\"id\":44,\"name\":\"Executable\"},{\"id\":59,\"name\":\"Fortran (GFortran 9.2.0)\"},{\"id\":60,\"name\":\"Go (1.13.5)\"},{\"id\":61,\"name\":\"Haskell (GHC 8.8.1)\"},{\"id\":62,\"name\":\"Java (OpenJDK 13.0.1)\"},{\"id\":63,\"name\":\"JavaScript (Node.js 12.14.0)\"},{\"id\":64,\"name\":\"Lua (5.3.5)\"},{\"id\":65,\"name\":\"OCaml (4.09.0)\"},{\"id\":66,\"name\":\"Octave (5.1.0)\"},{\"id\":67,\"name\":\"Pascal (FPC 3.0.4)\"},{\"id\":68,\"name\":\"PHP (7.4.1)\"},{\"id\":43,\"name\":\"Plain Text\"},{\"id\":69,\"name\":\"Prolog (GNU Prolog 1.4.5)\"},{\"id\":70,\"name\":\"Python (2.7.17)\"},{\"id\":71,\"name\":\"Python (3.8.1)\"},{\"id\":72,\"name\":\"Ruby (2.7.0)\"},{\"id\":73,\"name\":\"Rust (1.40.0)\"},{\"id\":74,\"name\":\"TypeScript (3.7.4)\"}]"); + +function populateLangs() +{ + console.log('populating languages...'); + let selectField = document.getElementById('langSelect'); + for(element of languageIDs) + { + // console.log('adding.. ',element); + var opt = document.createElement("option"); + opt.value= element['id']; + opt.innerHTML = element['name']; // whatever property it has + + // then append it to the select element + selectField.appendChild(opt); + } +} function setCode(prog){ code = prog; @@ -104,7 +122,7 @@ function getCustomInput(){ } function setOutput(outp) { - output = outp['output']; + output = outp['stdout']; } function getOutput(){ return output @@ -128,6 +146,7 @@ function runCode(){ // Get language chosen by the user and store it let lang = document.getElementById("langSelect").value; + console.log('langCode: ', lang); // setLanguage(lang); // console.log('Language: ', getLanguage(), '\nCode: ', getCode()); @@ -139,9 +158,9 @@ function runCode(){ // Code equals script // script : getCode(), // language: getLanguage(), - script : prog, - language: lang, - versionIndex: versions[versionNo], + source_code : prog, + language_id: lang, + // versionIndex: versions[versionNo], stdin: getCustomInput(), //to give custom input qNo: getQNum(), timeElapsed: time @@ -170,53 +189,59 @@ const sendRequest = (method, url, data) => { ourRequest.onload = function() { if (ourRequest.status >= 200 && ourRequest.status < 400) { // console.log('output: '); - console.log('success 200'); - if(url == 'runCode/'){ - console.log('1'); - let recievedData = JSON.parse(ourRequest.responseText); - console.log('receivedData: ', recievedData); - setOutput(recievedData); - document.getElementById("compilerOutput").value = getOutput(); - document.getElementById('score').innerHTML = recievedData['score']; - console.log(recievedData['score']); - if(getOutput() == 'Correct Answer') - { - s = 0; - m = 0; - qNo = (getQNum() + 1) % 5; - console.log(qNo); - document.getElementsByClassName('left')[0].getElementsByTagName('h5')[0] = "Question "+qNo; - document.getElementsByClassName('left')[0].innerHTML = getQuestion(qNo); - console.log("OO"); + // console.log('success 200'); + if(url == 'runCode/'){ + console.log('1'); + let recievedData = JSON.parse(ourRequest.responseText); + console.log('receivedData: ', recievedData); + setOutput(recievedData); + document.getElementById("compilerOutput").value = getOutput(); + document.getElementById('score').innerHTML = recievedData['score']; + console.log(recievedData['score']); + if(getOutput() == 'Correct Answer') + { + Swal.fire( + 'Congratulations', + 'You have successfully attempted all the questions', + 'success' + ); + window.location.href = "/logout"; + s = 0; + m = 0; + qNo = (getQNum() + 1) % 5; + console.log(qNo); + document.getElementsByClassName('left')[0].getElementsByTagName('h5')[0] = "Question "+qNo; + document.getElementsByClassName('left')[0].innerHTML = getQuestion(qNo); + console.log("OO"); + } + increaseTime(); + return recievedData; + } + else{ + console.log('2'); + let recievedData = JSON.parse(ourRequest.responseText); + let inpt = recievedData['sampIn'].split(' '); + let inStr = ''; + for(let i = 0; i < inpt.length;i++) + { + inStr += inpt[i]; + inStr += '\n'; + } + let que = recievedData['question'] + '

'+'Sample Input'+'
'+recievedData['sampTCNum']+'
'+inStr+'

'+'Sample Output'+'
'+recievedData['sampleOut']; + console.log('hi ',recievedData); + document.getElementsByClassName('left')[0].innerHTML=que; + qNo = recievedData['qNo']; + // console.log(qNo); + // console.log(recievedData['userScore']); + document.getElementById('score').innerHTML = recievedData['userScore']; + console.log(recievedData); + return recievedData; } - increaseTime(); - return recievedData; - } - else{ - console.log('2'); - let recievedData = JSON.parse(ourRequest.responseText); - let inpt = recievedData['sampIn'].split(' '); - let inStr = ''; - for(let i = 0; i < inpt.length;i++) - { - inStr += inpt[i]; - inStr += '\n'; - } - let que = recievedData['question'] + '

'+'Sample Input'+'
'+recievedData['sampTCNum']+'
'+inStr+'

'+'Sample Output'+'
'+recievedData['sampleOut']; - console.log('hi ',recievedData); - document.getElementsByClassName('left')[0].innerHTML=que; - qNo = recievedData['qNo']; - console.log(qNo); - console.log(recievedData['userScore']); - document.getElementById('score').innerHTML = recievedData['userScore']; - console.log(recievedData); - return recievedData; - } } else { // Nothing // startClock(); - console.log("OO") + // console.log("OO") increaseTime() } } @@ -224,11 +249,11 @@ const sendRequest = (method, url, data) => { ourRequest.onerror = function() { // Nothing // startClock(); - console.log("OO") + // console.log("OO") increaseTime() } - console.log(JSON.stringify(data)); + // console.log(JSON.stringify(data)); ourRequest.send(JSON.stringify(data)); }; @@ -243,12 +268,19 @@ const getQuestion = queNum => { // let data = { queNum }; // sendRequest('POST', '/question/', data); sendRequest('POST', '/question/', { queNum }); + // console.log(queNum) + // clicks = 0; }; window.onresize = function() { if ((window.outerHeight - window.innerHeight) > 100) { // console was opened (or screen was resized) - alert("Sorry! You will be logged out since you didn't follow the instructions."); + // alert("Sorry! You will be logged out since you didn't follow the instructions."); + Swal.fire( + 'Sorry', + "You will be logged out since you didn't follow the instructions", + 'warning' + ) window.location.href = "/logout" } } @@ -274,20 +306,20 @@ function login() { ourRequest.send(); } -function showAbout() { - document.getElementsByClassName('about')[0].style.display = 'flex'; +function showInstructions() { + document.getElementsByClassName('instructions')[0].style.display = 'flex'; document.getElementsByClassName('backdrop')[0].style.display = 'block'; } -function closeAbout() { - document.getElementsByClassName('about')[0].style.display = 'none'; +function closeInstructions() { + document.getElementsByClassName('instructions')[0].style.display = 'none'; document.getElementsByClassName('backdrop')[0].style.display = 'none'; } document.addEventListener('DOMContentLoaded', function() { var elems = document.querySelectorAll('select'); - console.log('hikljhg'); -// var instances = M.FormSelect.init(elems, options); + // console.log('hikljhg'); + // var instances = M.FormSelect.init(elems, options); }); // Or with jQuery @@ -402,8 +434,57 @@ function pauseTime() { clearInterval(timerId); } +// Won't allow user to cheat by changing text-color +let codeIntervalId; +let clicks = 0; +const hideCode = () => { + codeIntervalId = setInterval(() => document.getElementById('codeInput').style.color = 'black', 200) +} + +const showCode = () => { + const box = document.getElementById('codeInput'); + + if (box.disabled === false) { + // Functionality won't be achieved after two clicks + if (clicks >= 2) { + // box.disabled = false; + // alert('You have used up your time!'); + Swal.fire( + 'Sorry..', + 'You have used up your time!', + 'error' + ); + return; + } + else { + // Disable button and show code for 5 seconds + box.disabled = true; + clearInterval(codeIntervalId); + box.style.color = 'white'; + setTimeout(() => { + hideCode() + box.disabled = false; + }, 5000); + } + clicks++; + console.log(clicks); + } + else{ + // alert('You have used up your time!'); + Swal.fire( + 'Sorry..', + 'You have used up your time!', + 'warning' + ); + } +} + +document.getElementById('showCode').addEventListener('click', () => { + showCode() +}) + window.onload = () => { // startClock(); - console.log("OO") increaseTime() + hideCode(); } diff --git a/blind_coding/static/main/loggedIn.html b/blind_coding/static/main/loggedIn.html index 2ce878c..ee48f07 100644 --- a/blind_coding/static/main/loggedIn.html +++ b/blind_coding/static/main/loggedIn.html @@ -32,8 +32,8 @@
- - + +