-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 23.2 KB
/
index.js
1
const $=e=>document.getElementById(e),_=e=>e.value="",e=e=>e.style.border="2px solid #AA0000",c=e=>e.style.border="none",d=e=>"none"!=e.style.display,viewLoader=()=>$("loader-container").style.display="flex",hideLoader=()=>$("loader-container").style.display="none";window.onbeforeunload=(()=>!0);let key=document.cookie.substring(4);function post(e){return e.key=key,fetch("https://jhihyangwu.pythonanywhere.com",{method:"POST",body:JSON.stringify(e)}).then(e=>e.json())}$("host-ranking-screen").style.display="none",post({action:"checkAuth"}).then(e=>{e.valid&&viewIsAuth(e.username,e.tables)});let maxWidth=window.innerWidth,maxHeight=window.innerHeight-68;1.25*maxHeight<maxWidth?($("tree").style.width=`${1.25*maxHeight}px`,$("tree").style.height=`${maxHeight}px`,$("tree").style.left=`${(window.innerWidth-1.25*maxHeight)/2}px`):($("tree").style.width=`${maxWidth}px`,$("tree").style.height=`${maxWidth/1.25}px`,$("tree").style.left=`${(window.innerWidth-maxWidth)/2}px`,$("tree").style.bottom=`${maxHeight/2-maxWidth/1.25/2}px`),$("tree").width=2e3,$("tree").height=1600;let context=$("tree").getContext("2d");context.strokeStyle="#EEEEEE",context.font="40px Arial",context.lineWidth=5,context.textAlign="center",context.translate($("tree").width/2,$("tree").height);let tree=[];for(let e=0;e<=8;e++)tree.push(new Array(Math.pow(2,e)));function drawTreeNode(e,t=0,n=0,i=350,s=0,o=0,a=0){if(0==o)context.save();else if(9==o)return;if(context.translate(t,n),context.rotate(s),!tree[o][a])return context.beginPath(),context.moveTo(0,-30),context.lineTo(0,-i),context.stroke(),context.beginPath(),context.arc(0,-i,30,0,2*Math.PI),context.stroke(),context.beginPath(),context.arc(0,-i,29,0,2*Math.PI),context.fillStyle="#444444",context.fill(),context.fillStyle="#EEEEEE",context.fillText(e,0,14-i),tree[o][a]=e,context.restore(),void setTimeout(()=>drawTreeNode(Math.floor(100*Math.random())),100);e<tree[o][a]?drawTreeNode(e,0,-i,.8*i,-Math.PI/8,o+1,2*a):drawTreeNode(e,0,-i,.8*i,Math.PI/8,o+1,2*(a+.5))}function updateHeight(){window.innerWidth<=780&&["left-container","right-container"].forEach(e=>{for(let t of document.getElementsByClassName(e))t.style.height=`${$("main").offsetHeight}px`})}function updateLineNumbers(e){let t=e.value.split("\n").length,n="";for(let e=1;e<=t;e++)n+=`${e}\n`;e.parentNode.children[0].innerText=n}function updateScroll(e){e.parentNode.children[0].scrollTop=e.scrollTop}function updateCode(e,t){let n=e.selectionStart,i=e.selectionEnd,s=e.value.substring(0,n),o=e.value.substring(n,i),a=e.value.substring(i);if(9==t.keyCode&&t.shiftKey)t.preventDefault(),"\t"==e.value.substring(s.lastIndexOf("\n")+1,s.lastIndexOf("\n")+2)&&(e.value=e.value.substring(0,s.lastIndexOf("\n")+1)+e.value.substring(s.lastIndexOf("\n")+2),"\n"==e.value.substring(n-1,n)?e.selectionStart=n:e.selectionStart=n-1,e.selectionEnd=i-1,n=e.selectionStart,i=e.selectionEnd,s=e.value.substring(0,n),o=e.value.substring(n,i),a=e.value.substring(i)),e.value=s+o.replace(/\n\t/g,"\n")+a,e.selectionStart=n,e.selectionEnd=i-o.split("\n\t").length+1;else if(9==t.keyCode)t.preventDefault(),e.value=s+"\t"+o.replace(/\n/g,"\n\t")+a,e.selectionStart=n+1,e.selectionEnd=i+o.split("\n").length;else if(13==t.keyCode){t.preventDefault();let o=s.split("{").length-1-(s.split("}").length-1)+(s.split("[").length-1-(s.split("]").length-1))+(s.split("(").length-1-(s.split(")").length-1)),l=e.value.substring(n-1,i+1);e.value="{}"==l||"[]"==l||"()"==l?s+"\n"+"\t".repeat(o)+"\n"+"\t".repeat(o-1)+a:s+"\n"+"\t".repeat(o)+a,e.selectionEnd=n+1+o,updateLineNumbers(e)}}drawTreeNode(Math.floor(100*Math.random()));let pages=["home","host-matches","about","contact"],pageViewed="home",switchingPages=!1,switchingElements=!1;function switchPage(e){let t=pages.indexOf(e.dataset.page)-pages.indexOf(pageViewed);if(0!=t&&!switchingPages){switchingPages=!0;let n=$(e.dataset.page),i=$(pageViewed);n.style.display="block",t>0?(n.style.top="-100%",i.style.animation="leftOut 0.5s forwards",n.style.animation="rightIn 0.5s forwards"):t<0&&(i.style.top="-100%",i.style.animation="rightOut 0.5s forwards",n.style.animation="leftIn 0.5s forwards"),setTimeout(()=>{i.style.display="none",n.style.top="0%",switchingPages=!1},500),pageViewed=e.dataset.page}}function switchElement(e,t){switchingElements||(switchingElements=!0,e.style.animation="fadeOut 0.25s forwards",setTimeout(()=>{t.style.animation="fadeIn 0.25s forwards",e.style.display="none",t.style.display="block"},250),setTimeout(()=>switchingElements=!1,500))}function submitMessage(){let e={action:"submitMessage"};return["name","email","message"].forEach(t=>e[t]=$(`contact-form-${t}`).value),viewLoader(),post(e).then(()=>{["name","email","message"].forEach(e=>_($(`contact-form-${e}`))),hideLoader()}).catch(()=>hideLoader()),!1}let signInUsername=$("sign-in-form-username"),signInPassword=$("sign-in-form-password"),signUpUsername=$("sign-up-form-username"),signUpPassword=$("sign-up-form-password"),signUpConfirmPassword=$("sign-up-form-confirm-password");function cNotAuth(){setTimeout(()=>{[signInUsername,signInPassword,signUpUsername,signUpPassword,signUpConfirmPassword].forEach(e=>{c(e),_(e)})},250)}function viewSignIn(){switchElement($("sign-up-form"),$("sign-in-form")),cNotAuth()}function viewSignUp(){switchElement($("sign-in-form"),$("sign-up-form")),cNotAuth()}function signIn(){c(signInUsername),c(signInPassword);let t={action:"signIn",username:signInUsername.value,password:signInPassword.value};return viewLoader(),post(t).then(n=>{n.valid?(key=n.key,document.cookie=`key=${n.key}`,viewIsAuth(t.username,n.tables)):(_(signInUsername),_(signInPassword),e(signInUsername),e(signInPassword)),hideLoader()}).catch(()=>hideLoader()),!1}function signUp(){if(c(signUpUsername),c(signUpPassword),c(signUpConfirmPassword),signUpPassword.value==signUpConfirmPassword.value){let t={action:"signUp",username:signUpUsername.value,password:signUpPassword.value};viewLoader(),post(t).then(n=>{n.valid?(key=n.key,document.cookie=`key=${n.key}`,viewIsAuth(t.username,n.tables)):(n.username&&(_(signUpUsername),e(signUpUsername)),n.password&&(_(signUpPassword),_(signUpConfirmPassword),e(signUpPassword),e(signUpConfirmPassword))),hideLoader()}).catch(()=>hideLoader())}else _(signUpConfirmPassword),e(signUpConfirmPassword);return!1}function viewIsAuth(e,t){$("username").innerText=e,updateTables(t),switchElement($("not-auth"),$("is-auth")),setTimeout(()=>cNotAuth(),250)}function updateTables(e){$("find-problems").children[1].innerHTML="",$("my-problems").children[1].innerHTML="",$("match-history").children[1].innerHTML="",e.findProblems.forEach(e=>$("find-problems").children[1].innerHTML+=`<tr>\n <td>${e[0]}</td>\n <td>${e[1]}</td>\n <td>${new Date(e[2]).toLocaleString().replace(",","")}</td>\n <td>${e[3]}</td>\n <td><span class="clickable" onclick="viewTableDropdown(this)" data-date="${e[2]}">…</span></td>\n </tr>`),e.myProblems.forEach(e=>$("my-problems").children[1].innerHTML+=`<tr>\n <td>${e[0]}</td>\n <td>${new Date(e[1]).toLocaleString().replace(",","")}</td>\n <td>${e[2]}</td>\n <td>${e[3]}</td>\n <td><span class="clickable" onclick="viewTableDropdown(this)" data-date="${e[1]}">…</span></td>\n </tr>`),e.matchHistory.forEach(e=>$("match-history").children[1].innerHTML+=`<tr>\n <td>${e[0]}</td>\n <td>${new Date(e[1]).toLocaleString().replace(",","")}</td>\n <td><span class="clickable" onclick="viewTableDropdown(this)" data-date="${e[1]}">…</span></td>\n </tr>`)}let hostFileViewed,guestFileViewed,language,hostFileData={},guestFileData={},hostFileIndex=0;const saveHostFile=e=>hostFileViewed&&(hostFileData[e]=$("host-code-area").value),saveGuestFile=e=>guestFileViewed&&(guestFileData[e]=$("code-area").value),updateHostFileLabel=e=>$(`host-file-label-${e.dataset.index}`).innerText=e.value,removeTestCase=e=>e.parentNode.remove();function viewFile(e){e.parentNode.childNodes.forEach(e=>e.style.color="#888888"),e.style.color="#444444","host-files"==e.parentNode.id?(saveHostFile(hostFileViewed),hostFileViewed=e.id,$("host-code-area").value=hostFileData[hostFileViewed],updateLineNumbers($("host-code-area"))):(saveGuestFile(guestFileViewed),guestFileViewed=e.innerText,$("code-area").value=guestFileData[guestFileViewed],updateLineNumbers($("code-area")))}function addFile(){$("new-problem-files").children[0].insertAdjacentHTML("beforeend",`<tr>\n <td class="file-name-input"><input type="text" placeholder="FILE NAME" oninput="updateHostFileLabel(this)" data-index="${hostFileIndex}"></td>\n <td onclick="removeFile(this)" class="clickable" data-index="${hostFileIndex}">−</td>\n </tr>`),$("host-files").innerHTML+=`<span id="host-file-label-${hostFileIndex}" onclick="viewFile(this)"></span>`,hostFileData[`host-file-label-${hostFileIndex}`]="",viewFile($("host-files").lastChild),hostFileIndex++}function removeFile(e){$(`host-file-label-${e.dataset.index}`).remove(),e.parentNode.remove(),$("host-files").firstChild?viewFile($("host-files").firstChild):(_($("host-code-area")),hostFileViewed=void 0,updateLineNumbers($("host-code-area"))),delete hostFileData[`host-file-label-${e.dataset.index}`]}function addTestCase(){$("new-problem-test-cases").children[0].insertAdjacentHTML("beforeend",'<tr>\n <td>\n <input type="text" placeholder="FUNCTION CALL">\n <input type="text" placeholder="EXPECTED OUTPUT">\n </td>\n <td onclick="removeTestCase(this)" class="clickable">−</td>\n </tr>')}function submitProblem(t,n=""){for(object of document.getElementsByClassName("file-name-input"))c(object);saveHostFile(hostFileViewed);let i={action:"submitProblem",problemName:$("new-problem-form-problem-name").value,description:$("new-problem-form-description").value,files:{},testCases:[],public:$("new-problem-form-public").checked,edit:t,date:n};for(const t in hostFileData){i.files[$(t).innerText]=hostFileData[t];let n=$(t).innerText.substr($(t).innerText.lastIndexOf(".")+1);if(null==language)language=n;else if(language!=n){for(object of document.getElementsByClassName("file-name-input"))e(object);return}}i.language=language;let s=$("new-problem-test-cases").children[0];for(let e=1;e<s.children.length;e++)i.testCases.push([s.children[e].children[0].children[0].value,s.children[e].children[0].children[1].value]);viewLoader(),post(i).then(e=>{updateTables(e.tables);let t=$("explorer-bar").children[0];t.value="MY PROBLEMS",switchTable(t),switchingElements=!1,switchElement($("host-coding-screen"),$("explorer")),hideLoader()}).catch(()=>hideLoader())}function resetNewProblem(){_($("new-problem-form-problem-name")),_($("new-problem-form-description"));let e=$("new-problem-files").children[0];for(let t=e.children.length-1;t>=1;t--)e.children[t].remove();$("host-files").innerHTML="",hostFileData={},hostFileViewed=void 0;for(let t=(e=$("new-problem-test-cases").children[0]).children.length-1;t>=1;t--)e.children[t].remove();$("new-problem-form-public").checked=!0,language=void 0,addFile(),addTestCase()}let previousTableDropdown,resetData,tableViewed="find-problems",tableDropdown=0;function switchTable(e){$("table-drop-down").style.display="none",tableDropdown=0;let t={"FIND PROBLEMS":"find-problems","MY PROBLEMS":"my-problems","MATCH HISTORY":"match-history"}[e.value];switchElement($(tableViewed),$(t)),setTimeout(()=>{$(t).style.display="table"},250),tableViewed=t}function viewNewProblem(){resetNewProblem(),$("submit-new-problem").onclick=(()=>submitProblem(!1)),switchElement($("explorer"),$("host-coding-screen")),setTimeout(()=>{$("host-coding-screen").style.display="flex",updateHeight()},250)}function viewSettings(){$("settings").style.animation="fadeIn 0.25s forwards",$("settings").style.display="flex"}function resetPassword(){let t=$("reset-password-form-password"),n=$("reset-password-form-confirm-password");if(c(t),c(n),t.value==n.value){let i={action:"resetPassword",password:t.value};viewLoader(),post(i).then(i=>{i.valid?($("settings").click(),setTimeout(()=>{_(t),_(n)},250)):(_(t),_(n),e(t),e(n)),hideLoader()}).catch(()=>hideLoader())}else _(n),e(n);return!1}function signOut(){viewLoader(),viewSignIn(),post({action:"signOut"}).then(()=>{key="",document.cookie="key=",$("settings").click(),switchingElements=!1,switchElement($("is-auth"),$("not-auth")),setTimeout(()=>{$("not-auth").style.display="flex";let e=$("explorer-bar").children[0];e.value="FIND PROBLEMS",switchingElements=!1,switchTable(e)},250),hideLoader()}).catch(()=>hideLoader())}function viewTableDropdown(e){if(0==tableDropdown||e!=previousTableDropdown){let t=$("table-drop-down"),n="find-problems"==tableViewed&&e.parentNode.parentNode.children[1].innerText==$("username").innerText;t.innerHTML="","find-problems"!=tableViewed&&"my-problems"!=tableViewed||(t.innerHTML+=`<div onclick="hostProblem('${e.dataset.date}')">HOST</div>`),t.innerHTML+="my-problems"==tableViewed||n?`<div onclick="viewProblem(true, '${e.dataset.date}')">EDIT</div>`:"match-history"==tableViewed?`<div onclick="viewMatchHistory('${e.dataset.date}')">VIEW</div>`:`<div onclick="viewProblem(false, '${e.dataset.date}')">VIEW</div>`,("find-problems"!=tableViewed||n)&&(t.innerHTML+=`<div onclick="deleteObject('${e.dataset.date}')">DELETE</div>`),t=e.getBoundingClientRect(),$("table-drop-down").style.top=`${t.bottom+5}px`,$("table-drop-down").style.right=`calc(100% - ${t.right}px)`,$("table-drop-down").style.display="inline-block",tableDropdown=1,previousTableDropdown=e}}function hostProblem(e){let t={action:"hostProblem",date:e};viewLoader(),post(t).then(e=>{$("match-id").innerText=e.matchID,switchElement($("explorer"),$("host-waiting-screen")),updateLastResponse(!0,e.matchID),hideLoader()}).catch(()=>hideLoader())}function joinMatch(){let t=$("join-form-your-name"),n=$("join-form-match-id");c(t),c(n);let i={action:"joinMatch",matchID:n.value,name:t.value};return viewLoader(),post(i).then(i=>{i.valid?(switchElement($("not-join"),$("is-join")),updateLastResponse(!1,n.value,t.value)):(i.name||(_(t),e(t)),i.matchID||(_(n),e(n))),hideLoader()}).catch(()=>hideLoader()),!1}window.onclick=(e=>{e.target==$("settings")&&($("settings").style.animation="fadeOut 0.25s forwards",setTimeout(()=>{$("settings").style.display="none";let e=$("reset-password-form-password"),t=$("reset-password-form-confirm-password");c(e),c(t)},250)),e.target!=$("table-drop-down")&&(2==tableDropdown?($("table-drop-down").style.display="none",tableDropdown=0):1==tableDropdown&&tableDropdown++)});let matchHistoryFiles,matchHistoryFileOrder,retry=0;function updateLastResponse(e,t,n=null){post({action:"updateLastResponse",host:e,matchID:t,name:n}).then(i=>{retry=0,!e&&i.problemName&&(switchingElements=!1,resetData=JSON.parse(JSON.stringify(i.files)),guestFileData=i.files,$("problem").innerHTML=`<div>${i.problemName}</div>${i.description}`,Object.keys(guestFileData).forEach(e=>$("files").innerHTML+=`<span onclick="viewFile(this)">${e}</span>`),viewFile($("files").firstChild),i.testCases.forEach(e=>$("test-cases").children[0].innerHTML+=`<tr>\n <td>${e[0]}</td>\n <td>${e[1]}</td>\n <td></td>\n <td></td>\n </tr>`),switchElement($("waiting-screen"),$("coding-screen")),setTimeout(()=>{$("coding-screen").style.display="flex",updateHeight()},250),viewTestCases()),e?d($("host-waiting-screen"))?($("name-container").innerHTML="",i.guestNames.forEach(e=>$("name-container").innerHTML+=`<div onclick="kickGuest('${t}', '${e}')">${e}</div>`),$("people-count").innerText=`PEOPLE: ${i.guestNames.length}`,$("completed-count").innerText=`COMPLETED: 0/${i.guestNames.length}`):d($("host-ranking-screen"))&&([[$("time-tbody"),i.time],[$("attempts-tbody"),i.attempts],[$("runtime-tbody"),i.runtime]].forEach(e=>{e[0].innerHTML="";for(let t=0;t<Object.keys(e[1]).length;t++)e[0].innerHTML+=`<tr>\n <td>${t+1}</td>\n <td>${Object.keys(e[1])[t]}</td>\n <td>${e[1][Object.keys(e[1])[t]]}</td>\n </tr>`}),$("completed-count").innerText=`COMPLETED: ${Object.keys(i.time).length}/${i.guestNames.length}`):("ended"==i.status&&d($("is-join"))&&leaveMatch(),i.time&&($("time-rank").innerText=i.time,$("attempts-rank").innerText=i.attempts,$("runtime-rank").innerText=i.runtime)),(e&&(d($("host-waiting-screen"))||d($("host-ranking-screen")))||!e&&d($("is-join")))&&updateLastResponse(e,t,n)}).catch(()=>{retry<5?(retry++,setTimeout(()=>updateLastResponse(e,t,n),5e3)):e?(switchingElements=!1,d($("host-waiting-screen"))?switchElement($("host-waiting-screen"),$("explorer")):switchElement($("host-ranking-screen"),$("explorer")),setTimeout(()=>{$("name-container").innerHTML="",$("people-count").innerText="PEOPLE: 0",$("time-tbody").innerHTML="",$("attempts-tbody").innerHTML="",$("runtime-tbody").innerHTML=""},250)):d($("is-join"))&&leaveMatch()})}function startMatch(){let e={action:"startMatch",matchID:$("match-id").innerText};viewLoader(),post(e).then(()=>{switchElement($("host-waiting-screen"),$("host-ranking-screen")),setTimeout(()=>$("host-ranking-screen").style.display="flex",250),hideLoader()}).catch(()=>hideLoader())}function endMatch(){let e={action:"endMatch",matchID:$("match-id").innerText};viewLoader(),post(e).then(e=>{if(updateTables(e.tables),switchingElements=!1,d($("host-waiting-screen")))switchElement($("host-waiting-screen"),$("explorer"));else{switchElement($("host-ranking-screen"),$("explorer"));let e=$("explorer-bar").children[0];e.value="MATCH HISTORY",switchingElements=!1,switchTable(e)}setTimeout(()=>{$("name-container").innerHTML="",$("people-count").innerText="PEOPLE: 0",$("time-tbody").innerHTML="",$("attempts-tbody").innerHTML="",$("runtime-tbody").innerHTML=""},250),hideLoader()}).catch(()=>hideLoader())}function viewTestCases(){$("console").style.display="none",$("test-cases").style.display="table",$("console-button").style.color="#888888",$("test-cases-button").style.color="#444444"}function viewConsole(){$("test-cases").style.display="none",$("console").style.display="block",$("test-cases-button").style.color="#888888",$("console-button").style.color="#444444"}function run(){saveGuestFile(guestFileViewed);let e={action:"run",matchID:$("join-form-match-id").value,name:$("join-form-your-name").value,files:guestFileData};viewLoader(),post(e).then(e=>{if($("console").innerText=e.console,-1==e.status)viewConsole();else if(0==e.status){for(let t=0;t<e.functionOutput.length;t++){let n=$("test-cases").children[0].children[t];n.children[2].innerText=e.functionOutput[t],n.children[3].innerHTML=e.correctCases[t]}viewTestCases()}else $("time").innerText=e.stats[0],$("attempts").innerText=e.stats[1],$("runtime").innerText=e.stats[2],$("time-rank").innerText=e.time,$("attempts-rank").innerText=e.attempts,$("runtime-rank").innerText=e.runtime,switchElement($("coding-screen"),$("ranking-screen")),setTimeout(()=>$("ranking-screen").style.display="flex",250);hideLoader()}).catch(()=>hideLoader())}function reset(){$("code-area").value=resetData[guestFileViewed],updateLineNumbers($("code-area"))}function leaveMatch(){switchingElements=!1,switchElement($("is-join"),$("not-join")),setTimeout(()=>{$("waiting-screen").style.display="flex",$("coding-screen").style.display="none",$("ranking-screen").style.display="none",$("waiting-screen").style.animation="",$("test-cases").children[0].innerHTML="",$("console").innerText="",$("files").innerHTML="",$("line-numbers").innerHTML="",$("code-area").value="",guestFileData={},guestFileViewed=void 0,$("join-form-match-id").value=""},250)}function viewMatchHistory(e){let t={action:"viewMatchHistory",date:e};viewLoader(),post(t).then(e=>{$("new-problem-form").style.display="none",$("scoreboard").style.display="table",$("cancel-new-problem").style.display="none",$("submit-new-problem").style.display="none",$("back-to-explorer").style.display="inline-block",$("host-files").innerHTML="",$("host-line-numbers").innerHTML="",$("host-code-area").value="",$("scoreboard").children[1].innerHTML="",e.scoreboard.forEach(e=>$("scoreboard").children[1].innerHTML+=`<tr onclick="viewMatchHistoryFiles('${e[0]}')">\n <td>${e[0]}</td>\n <td>${e[1]}</td>\n <td>${e[2]}</td>\n <td>${e[3]}</td>\n </tr>`),matchHistoryFiles=e.files,matchHistoryFileOrder=e.fileOrder,switchElement($("explorer"),$("host-coding-screen")),setTimeout(()=>{$("host-coding-screen").style.display="flex",updateHeight()},250),hideLoader()}).catch(()=>hideLoader())}function backToExplorer(){switchElement($("host-coding-screen"),$("explorer")),setTimeout(()=>{$("scoreboard").style.display="none",$("new-problem-form").style.display="block",$("back-to-explorer").style.display="none",$("cancel-new-problem").style.display="inline-block",$("submit-new-problem").style.display="inline-block"},250)}function viewMatchHistoryFiles(e){$("host-files").innerHTML="",$("host-line-numbers").innerHTML="",$("host-code-area").value="",0!=Object.keys(matchHistoryFiles[e]).length&&matchHistoryFileOrder.forEach(t=>$("host-files").innerHTML+=`<span onclick="viewMatchHistoryFile(this, '${e}', '${t}')">${t}</span>`),$("host-files").firstChild&&$("host-files").firstChild.click()}function viewMatchHistoryFile(e,t,n){e.parentNode.childNodes.forEach(e=>e.style.color="#888888"),e.style.color="#444444",$("host-code-area").value=matchHistoryFiles[t][n],updateLineNumbers($("host-code-area"))}function deleteObject(e){let t={action:"deleteObject",problem:"MATCH HISTORY"!=$("explorer-bar").children[0].value,date:e};viewLoader(),post(t).then(e=>{updateTables(e.tables),hideLoader()}).catch(()=>hideLoader())}function viewProblem(e,t){e?$("submit-new-problem").onclick=(()=>submitProblem(!0,t)):($("cancel-new-problem").style.display="none",$("submit-new-problem").style.display="none",$("back-to-explorer").style.display="inline-block");let n={action:"viewProblem",date:t};viewLoader(),post(n).then(e=>{language=void 0,$("new-problem-form-problem-name").value=e.problemName,$("new-problem-form-description").value=e.description;let t=$("new-problem-files").children[0];for(let e=t.children.length-1;e>=1;e--)t.children[e].remove();$("host-files").innerHTML="",$("host-line-numbers").innerHTML="",$("host-code-area").value="",hostFileData={},hostFileViewed=void 0;for(let e=(t=$("new-problem-test-cases").children[0]).children.length-1;e>=1;e--)t.children[e].remove();Object.keys(e.files).forEach(t=>{addFile();let n=$("new-problem-files").children[0].lastChild.children[0].children[0];n.value=t,updateHostFileLabel(n),$("host-code-area").value=e.files[t]}),$("host-files").firstChild&&viewFile($("host-files").firstChild),e.testCases.forEach(e=>{addTestCase();let t=$("new-problem-test-cases").children[0].lastChild.children[0];t.children[0].value=e[0],t.children[1].value=e[1]}),$("new-problem-form-public").checked=e.public,switchElement($("explorer"),$("host-coding-screen")),setTimeout(()=>{$("host-coding-screen").style.display="flex",updateHeight()},250),hideLoader()}).catch(()=>hideLoader())}function filterTables(e){[$("find-problems").children[1],$("my-problems").children[1],$("match-history").children[1]].forEach(t=>{for(let n=0;n<t.children.length;n++)-1!=t.children[n].innerText.toUpperCase().indexOf(e.value.toUpperCase())?t.children[n].style.display="":t.children[n].style.display="none"})}function kickGuest(e,t){let n={action:"kickGuest",matchID:e,name:t};viewLoader(),post(n).then(()=>hideLoader()).catch(()=>hideLoader())}