Skip to content

Commit

Permalink
Merge pull request #26 from CodeforcesContestHelper/dev
Browse files Browse the repository at this point in the history
Optimize fetcher & Bug fix
  • Loading branch information
tiger2005 authored Nov 7, 2021
2 parents f922dbb + b6cf5ea commit fa836aa
Show file tree
Hide file tree
Showing 15 changed files with 936 additions and 173 deletions.
37 changes: 25 additions & 12 deletions css/client.css
Original file line number Diff line number Diff line change
Expand Up @@ -820,16 +820,25 @@ pre{
cursor: pointer;
}











/* MULTI */
.multiInfoDisplayer{
width: 100%;
height: 100%;
flex: 1;
position: relative;
overflow: auto;
}
.multiSettingsBar{
height: 100px;
width: 100%;
}
.multiInfoTable{
width: 100%;
max-height: 100%;
}
.multiInfoThead{
display: table-header-group;
}

/* SETTINGS */
.settingPage{
Expand All @@ -843,7 +852,7 @@ pre{
font-weight: bold;
font-size: 28px;
margin-bottom: 15px;
margin-top: 5px;
margin-top: 30px;
}
.settingsUI{
margin: 20px 0px !important;
Expand Down Expand Up @@ -974,7 +983,7 @@ pre{
}



/* SEARCH */

.searchPage{
padding: 10px 0px;
Expand Down Expand Up @@ -1059,6 +1068,9 @@ pre{
margin: 3px 10px 3px 0px;
font-size: 18px;
}

/* CONTEST */

.contestInfoCard{
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -1116,6 +1128,7 @@ pre{
font-size: 16px;
}
.contestCardTime{
margin-top: 5px;
font-size: 16px;
}
.contestCardTimeRunningType{
Expand Down
4 changes: 3 additions & 1 deletion css/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ body{
.highlightedContestList{
background: #444;
}

.multiSettingsBar{
background: rgb(46, 51, 56);
}



Expand Down
4 changes: 3 additions & 1 deletion css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ body{
.highlightedContestList{
background: #ccc;
}

.multiSettingsBar{
background: #ccc;
}



Expand Down
16 changes: 11 additions & 5 deletions css/problem/client.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ body{
}
.bigButton{
cursor: pointer;
width: calc(100% - 20px);
margin: 10px;
height: 30px;
width: 100%;
margin: 10px 0px;
height: 40px;
border-radius: 5px;
font-size: 16px;
font-family: var(--font-family);
Expand All @@ -240,7 +240,7 @@ body{
border-radius: 5px;
}
.submitInterfaceTitle{
font-size: 18px;
font-size: 16px;
}
.closeSubmitPage{
position: absolute;
Expand Down Expand Up @@ -273,6 +273,7 @@ select{
margin-right: 10px;
}
.addProblemInterface{
user-select: none;
border-radius: 5px;
}
.inputButtonSplitter{
Expand Down Expand Up @@ -318,7 +319,9 @@ select{
outline: 0;
}


.problemTag{
user-select: none;
}
.problemTag > i{
margin-right: 10px;
}
Expand Down Expand Up @@ -487,6 +490,7 @@ ul, ol{
display: inline-block;
}
.watchDisplayer{
user-select: none;
z-index: 98;
width: 370px !important;
position: absolute;
Expand All @@ -495,6 +499,7 @@ ul, ol{
text-align: center;
}
.singleWatchContent{
user-select: none;
transition: 0.2s;
padding: 0px 10px;
margin: 10px 0px;
Expand All @@ -506,6 +511,7 @@ ul, ol{
flex-direction: column;
}
.singleWatchTitle{
user-select: none;
font-size: 16px;
text-align: center;
}
Expand Down
51 changes: 47 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link class="ThemeTypeIf" rel="stylesheet" href="./css/default.css">
<link rel="stylesheet" href="./css/all.min.css">
<script src="./js/highlight.min.js"></script>
<script src="./js/sha512.js"></script>
<script src="./js/highlightjs-line-numbers.js"></script>
<script src="./KaTeX/katex.min.js"></script>
<script src="./KaTeX/auto-render.min.js"></script>
Expand Down Expand Up @@ -346,8 +347,22 @@
</div>
</div>
<div class="contentWrapper multiContent">
<div class="contentRowInfo">

<div class="contentRowInfo"><div class="contentPage">
<div style="width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden">
<div class="multiInfoDisplayer">
<table class="multiInfoTable">
<thead class="multiInfoThead">

</thead>
<tbody class="multiInfoTbody">

</tbody>
</table>
</div>
<div class="multiSettingsBar">

</div>
</div></div>
</div>
</div>
<div class="contentWrapper contestContent">
Expand Down Expand Up @@ -483,7 +498,7 @@
<div class="contentPage">
<div class="settingPage"> <div style="margin: 20px 0px">
<div class="settingsHeader" info="settingsAccount"></div>
<div class="settingsSelectInfoAddition settingsLoginType">...</div>
<div class="settingsSelectInfoAddition" style="position: relative"><span class="settingsLoginType"></span><span info="redirectVerification" style="float: right; cursor: pointer" onclick="openCodeforcesPage()"></span></div>
<div class="settingsUI settingsInput" for="accountHandleOrEmail">
<div class="settingsInputInfo">
<div class="settingsInputInfoMain">Radio Name</div>
Expand All @@ -503,6 +518,34 @@
</div>
</div>
<div class="settingsSelectInfoAddition settingsLoginButton"><span info='settingsLoginButton' onclick="submitLogin()"></span></div>
<div class="settingsUI settingsRadio" for="useApiKeys">
<div class="settingsRadioInfo">
<div class="settingsRadioInfoMain">Radio Name</div>
<div class="settingsRadioInfoAddition">Radio Addition</div>
</div>
<div class="settingsRadioButton">
<i class="far fa-square"></i>
<i class="fas fa-check-square"></i>
</div>
</div>
<div class="settingsUI settingsInput" for="apiKey">
<div class="settingsInputInfo">
<div class="settingsInputInfoMain">Radio Name</div>
<div class="settingsInputInfoAddition">Radio Addition</div>
</div>
<div class="settingsInputPart">
<input class="settingsInputPartContent" type="password"></input>
</div>
</div>
<div class="settingsUI settingsInput" for="apiSecret">
<div class="settingsInputInfo">
<div class="settingsInputInfoMain">Radio Name</div>
<div class="settingsInputInfoAddition">Radio Addition</div>
</div>
<div class="settingsInputPart">
<input class="settingsInputPartContent" type="password"></input>
</div>
</div>
<div class="settingsHeader" info="settingsPreference"></div>
<div class="settingsUI settingsSelect" for="styleSelection">
<div class="settingsSelectInfo">
Expand Down Expand Up @@ -751,7 +794,7 @@
</div>
</div>
<div class="settingsSelectInfoAddition settingsReloadLanguages"><span info='reloadLanguages' onclick="reloadLanguages()"></span></div>
<div style="text-align: center; margin-top: 30px" class="settingsOpenProblems"><span info='openProblems' onclick="openProblemWin([])"></span></div>
<div style="text-align: center; margin-top: 30px"><span class="settingsOpenProblems"><span info='openProblems' onclick="openProblemWin([])"></span></span></div>
<!-- <div class="settingsUI settingsRadio" for="testRadio">
<div class="settingsRadioInfo">
<div class="settingsRadioInfoMain">Radio Name</div>
Expand Down
79 changes: 75 additions & 4 deletions js/authorize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var loginTypeLoader = null;
var CodeforcesUserAPIKey, CodeforcesUserAPISeg;

function loadLoginType(){
currentLoginHandle = "";
if(problemNewWinLoaded) initProblemNewWin();
getSolvedProblemsByContest = {problemCountsByContestId: {}, solvedProblemCountsByContestId: {}};
$(".settingsLoginType").html(`<span info='settingsLoadingLoginType'>${languageOption.general.settingsLoadingLoginType}</span>`);
if(loginTypeLoader != null)
Expand Down Expand Up @@ -38,6 +41,10 @@ function getFtaa(){
return ret;
}
function submitLogout(cb){
if(currentLoginHandle == ""){
cb();
return;
}
$.ajax({
url: settings.mainURL,
success: function(data){
Expand Down Expand Up @@ -72,7 +79,15 @@ function submitLogin(){
submitLogout(function(){$.ajax({
url: settings.mainURL,
success: function(data){
var csrf = queryCsrf.exec(data)[1];
var csrf = queryCsrf.exec(data);
if(csrf == null){
$(".settingsLoginButton").html(`<span info='errorCsrfLoadFailed'>${languageOption.error.errorCsrfLoadFailed}</span>`);
setTimeout(function(){
$(".settingsLoginButton").html(`<span info='settingsLoginButton' onclick="submitLogin()">${languageOption.general.settingsLoginButton}</span>`);
}, 2000)
return;
}
csrf = csrf[1];
$.ajax({
url: settings.mainURL + '/enter?back=%2F&locale=en',
type: "POST",
Expand Down Expand Up @@ -127,7 +142,12 @@ function submitSolution(ci, idx, code, lang, S, E){
$.ajax({
url: settings.mainURL,
success: function(data){
var csrf = queryCsrf.exec(data)[1];
var csrf = queryCsrf.exec(data);
if(csrf == null){
E('errorCsrfLoadFailed', languageOption.error.errorCsrfLoadFailed);
return;
}
csrf = csrf[1];
$.ajax({
url: settings.mainURL + `/${ci >= 100000 ? "gym" : "contest"}/` + ci + '/submit',
type: "POST",
Expand Down Expand Up @@ -216,7 +236,12 @@ function loadContestPassedStatus(S, E){
$.ajax({
url: settings.mainURL + '/contests',
success: function(data){
var csrf = queryCsrf.exec(data)[1];
var csrf = queryCsrf.exec(data);
if(csrf == null){
E();
return;
}
csrf = csrf[1];
$.ajax({
url: settings.mainURL + '/data/contests',
type: "POST",
Expand Down Expand Up @@ -267,7 +292,12 @@ function registerContest(ci, S, E){
$.ajax({
url: settings.mainURL,
success: function(data){
var csrf = queryCsrf.exec(data)[1];
var csrf = queryCsrf.exec(data);
if(csrf == null){
E();
return;
}
csrf = csrf[1];
$.ajax({
url: settings.mainURL + '/contestRegistration/' + ci,
type: "POST",
Expand Down Expand Up @@ -303,5 +333,46 @@ function registerContest(ci, S, E){
});
}

function generateAuthorizeURL(url, data){
function parseObject(x){
var ret = [];
for(var v in x)
if(x.hasOwnProperty(v))
ret.push([v, x[v]]);
return ret.sort();
}
function generateParams(x){
var ret = "";
for(var i=0; i<x.length; i++){
if(i == 0)
ret += '?';
else
ret += "&";
ret += (x[i][0] + '=' + x[i][1]);
}
return ret;
}
if(!settings.useApiKeys)
return url + generateParams(parseObject(data));
var method = url.split("/");
method = method[method.length - 1];
data.time = Math.floor((new Date()).getTime() / 1000);
data.apiKey = settings.apiKey;
data = parseObject(data);
var rnd = "";
var str = "0123456789qwertyuiopasdfghjklzxcvbnm";
for(var j=0; j<6; j++)
rnd += str[Math.floor(Math.random()*str.length)];
var shaCode = rnd + '/' + method + generateParams(data) + '#' + settings.apiSecret;
shaCode = hex_sha512(shaCode);
data.push(["apiSig", rnd + shaCode]);
return url + generateParams(data);
}
function openCodeforcesPage(){
if(!RunInNwjs)
return;
window.open(settings.mainURL)
}

if(RunInNwjs)
loadLoginType();
Loading

0 comments on commit fa836aa

Please sign in to comment.