Skip to content

Commit

Permalink
Merge pull request #92 from CodeforcesContestHelper/dev
Browse files Browse the repository at this point in the history
Huge performance improvement
  • Loading branch information
tiger2005 authored Jul 1, 2023
2 parents 9012a14 + be5bf50 commit 7cf006e
Show file tree
Hide file tree
Showing 7 changed files with 1,032 additions and 117 deletions.
6 changes: 3 additions & 3 deletions css/problem.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ body {
z-index: 1;
}

.ToolList {
#ToolList {
-webkit-app-region: drag;
position: relative;
height: 30px;
}

.ToolListTitle {
#ToolListTitle {
margin: 8px 12px;
font-size: 14px;
user-select: none;
Expand Down Expand Up @@ -580,7 +580,7 @@ p {
display: inline-block;
}

.watchDisplayer {
#watchDisplayer {
user-select: none;
z-index: 98;
width: 370px !important;
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./js/jquery.min.js"></script>
<script src="./js/aes.js"></script>
<script src="./js/json3.min.js"></script>
<script src="./js/highcharts.js"></script>
<link rel="stylesheet" href="./css/client.css">
Expand Down
804 changes: 804 additions & 0 deletions js/aes.js

Large diffs are not rendered by default.

132 changes: 113 additions & 19 deletions js/authorize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,71 @@
var loginTypeLoader = null;
var CodeforcesUserAPIKey, CodeforcesUserAPISeg;

var queryCsrf = new RegExp(`<meta name="X-Csrf-Token" content="([0-9a-f]*)"`);
var queryGlobalChannel = new RegExp(`<meta name="gc" content="([0-9a-f]*)"`);
var queryHandle = new RegExp(`handle = "([\s\S]+?)"`);
var queryHandle2 = new RegExp(`<title>([0-9a-zA-Z-_.]+?) - Codeforces</title>`);

function getFtaa() {
var str = "0123456789qwertyuiopasdfghjklzxcvbnm";
var ret = "";
for (var i = 0; i < 18; i++)
ret += str[Math.floor(Math.random() * str.length)];
return ret;
}

// https://github.com/icpc-scu-community/codeforces-rcpc/blob/master/src/aes.ts
function encryptAES(c, a, b) {
// c => Encrypted Hex String
// a => (Key) Number Array
// b => (IV) Initiliaztion Vector
// When ready to decrypt the hex string, convert it back to bytes
const encryptedBytes = aesjs.utils.hex.toBytes(c);
const iv = aesjs.utils.hex.toBytes(b);
const key = aesjs.utils.hex.toBytes(a);
// The cipher-block chaining mode of operation maintains internal
// state, so to decrypt a new instance must be instantiated.
const aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
const decryptedBytes = aesCbc.decrypt(encryptedBytes);
const decryptedHex = aesjs.utils.hex.fromBytes(decryptedBytes);
return decryptedHex;
}

// https://github.com/icpc-scu-community/codeforces-rcpc/blob/master/src/index.ts
function tryDecodeRCPC(data) {
return new Promise((resolve) => {
if (data.indexOf(`Redirecting...`) === -1)
resolve(data);
let params = data.matchAll(/toNumbers\(\"([\d\w]*)\"\)/g)
const [a, b, c] = [...params].map((e) => e[1]);
if (a && b && c) {
let rcpc = encryptAES(c, a, b);
console.log(a, b, c, rcpc);
if (RunInNwjs) {
win.cookies.set({
domain: settings.mainURL.split("/")[2],
name: "RCPC",
value: rcpc,
path: '/',
url: settings.mainURL
}, (cookies) => {
$.ajax({
url: settings.mainURL,
success: (dt) => {
resolve(dt)
},
error: (err) => {
resolve(data)
}
})
})
}
}
else
resolve(data);
})
}

function loadLoginType() {
currentLoginHandle = "";
if (problemNewWinLoaded) initProblemNewWin();
Expand All @@ -13,7 +78,16 @@ function loadLoginType() {
loginTypeLoader.abort();
loginTypeLoader = $.ajax({
url: settings.mainURL + '?locale=en',
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
csrf = queryCsrf.exec(data);
}
if (csrf == null) {
$(".settingsLoginType").html(`<span info='loadLoginTypeError' style="cursor: pointer" onclick="loadLoginType()">${languageOption.general.loadLoginTypeError}</span>`);
return;
}
var q = $(data).find(".lang-chooser > div").eq(1);
if (q.children("a").eq(1).html() == "Logout") {
var hdl = q.children("a").eq(0).html();
Expand All @@ -35,18 +109,6 @@ function loadLoginType() {
}
})
}
var queryCsrf = new RegExp(`<meta name="X-Csrf-Token" content="([0-9a-f]*)"`);
var queryGlobalChannel = new RegExp(`<meta name="gc" content="([0-9a-f]*)"`);
var queryHandle = new RegExp(`handle = "([\s\S]+?)"`);
var queryHandle2 = new RegExp(`<title>([0-9a-zA-Z-_.]+?) - Codeforces</title>`);

function getFtaa() {
var str = "0123456789qwertyuiopasdfghjklzxcvbnm";
var ret = "";
for (var i = 0; i < 18; i++)
ret += str[Math.floor(Math.random() * str.length)];
return ret;
}

function submitLogout(cb) {
if (currentLoginHandle == "") {
Expand All @@ -55,7 +117,19 @@ function submitLogout(cb) {
}
$.ajax({
url: settings.mainURL,
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
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;
}
var q = $(data).find(".lang-chooser > div").eq(1);
if (q.children("a").eq(1).html() == "Register") {
cb();
Expand Down Expand Up @@ -94,8 +168,12 @@ function submitLogin() {
submitLogout(function() {
$.ajax({
url: settings.mainURL,
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
csrf = queryCsrf.exec(data);
}
if (csrf == null) {
$(".settingsLoginButton").html(`<span info='errorCsrfLoadFailed'>${languageOption.error.errorCsrfLoadFailed}</span>`);
setTimeout(function() {
Expand Down Expand Up @@ -162,8 +240,12 @@ function submitLogin() {
function submitSolution(ci, idx, code, lang, S, E) {
$.ajax({
url: settings.mainURL,
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
csrf = queryCsrf.exec(data);
}
if (csrf == null) {
E('errorCsrfLoadFailed', languageOption.error.errorCsrfLoadFailed);
return;
Expand Down Expand Up @@ -274,8 +356,12 @@ function loadContestPassedStatus(S, E) {
}
$.ajax({
url: settings.mainURL + '/contests',
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
csrf = queryCsrf.exec(data);
}
if (csrf == null) {
E();
return;
Expand Down Expand Up @@ -335,8 +421,12 @@ function checkRegistation(ci, S, E) {
function registerContest(ci, S, E) {
$.ajax({
url: settings.mainURL,
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
csrf = queryCsrf.exec(data);
}
if (csrf == null) {
E();
return;
Expand Down Expand Up @@ -389,8 +479,12 @@ function registerVirtualRound(ci, tm, S, E) {
var offsetTime = new Date(tm.getTime() + tm.getTimezoneOffset() * 60 * 1000);
$.ajax({
url: settings.mainURL,
success: function(data) {
success: async function(data) {
var csrf = queryCsrf.exec(data);
if (csrf == null) {
data = await tryDecodeRCPC(data);
csrf = queryCsrf.exec(data);
}
if (csrf == null) {
E("fa-unlink");
return;
Expand Down
13 changes: 10 additions & 3 deletions js/contest.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,31 @@ function loadContestList() {
}
var _contestAllList = [];
data = data.result;
$(".contestListLoadIf > span").html(`<span class='fas fa-hourglass-half'></span> ` + localize("loadingAcCount"));
loadContestPassedStatus(function() {
let display = (ref = false) => {
_contestAllList = [];
for (var i = 0; i < data.length; i++)
_contestAllList.push([data[i].name, data[i].id, data[i].type, data[i].startTimeSeconds, data[i].durationSeconds]);
contestAllList = _contestAllList;
contestListCurrentPage = 1;
if (ref)
contestListCurrentPage = 1;
var q = $(".contestListSearchArea > input").val();
contestListFilter(q);
var x = $(".contestSortOption").children().eq(0).hasClass("chosen");
var y = $(".contestDirectionOption").children().eq(1).hasClass("chosen");
contestListSort(x, y);
displayContestListPage();
}
display(true)
$(".contestListLoadIf > span").html(`<span class='fas fa-hourglass-half'></span> ` + localize("loadingAcCount"));
loadContestPassedStatus(function() {
display()
$(".contestListLoadIf > span").html(`<span class='fas fa-check green'></span> ` + localize("success"));
$(".contestListLoadIf > span").css("cursor", "pointer");
$(".contestListLoadIf > span").unbind("click").click(function() {
loadContestList();
})
}, function() {
display()
$(".contestListLoadIf > span").html(`<span class='fas fa-times red'></span> ` + localize("failed"));
$(".contestListLoadIf > span").css("cursor", "pointer");
$(".contestListLoadIf > span").unbind("click").click(function() {
Expand Down
Loading

0 comments on commit 7cf006e

Please sign in to comment.