-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandv3.js
115 lines (114 loc) · 4.1 KB
/
Randv3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
window.onload=function(){
var startTime = Date.now();
var clock = document.getElementById("clock");
var hours = 0;
var minutes = 0;
var seconds = 0;
var play = true;
var stoptime = 0;
function draw(){
var timePassed = Date.now()-startTime;
timePassed = Math.floor(timePassed/1000);
hours = Math.floor(timePassed/3600);
timePassed -= hours*3600;
minutes = Math.floor(timePassed/60);
timePassed -= minutes*60;
seconds = timePassed;
var curTime = "";
if(hours<10){
curTime+="0"+hours+":";
}
else{
curTime+=hours+":";
}
if(minutes<10){
curTime+="0"+minutes+":";
}
else{
curTime+=minutes+":";
}
if(seconds<10){
curTime+="0"+seconds;
}
else{
curTime+=seconds;
}
clock.innerHTML = curTime;
if(play==true){
window.requestAnimationFrame(draw);
}
}
draw();
var resetbtn = document.getElementById("reset");
resetbtn.addEventListener("click", function(){
if(play==true){
startTime = Date.now();
}
else{
startTime = Date.now();
stoptime = -1;
draw();
}
})
var playbtn = document.getElementById("pause-play");
playbtn.addEventListener("click", function(){
if(play==true){
play=false;
stoptime = Date.now();
playbtn.style.backgroundColor = "#c6c6c6";
}
else{
play=true;
if(stoptime==-1){
startTime=Date.now()-700;
}
else{
startTime+=Date.now()-stoptime;
}
draw();
playbtn.style.removeProperty("background-color");
}
})
};
function getProblem(){
document.getElementById("mincontestid").defaultValue=0;
document.getElementById("minrating").defaultValue=800;
document.getElementById("maxrating").defaultValue=3500;
const minContestId = document.getElementById("mincontestid").value;
const minRating = document.getElementById("minrating").value;
const maxRating = document.getElementById("maxrating").value;
var probTable = document.getElementById("suggestedproblems");
var btn = document.getElementById("submit");
btn.className = "button is-light is-fullwidth is-large is-loading";
fetch("https://codeforces.com/api/problemset.problems")
.then((res) => {
return res.json();
})
.then((data) => {
const startTime = Date.now();
var probFound = false;
while((Date.now()-startTime)<=4000){
let randPos = Math.max(Math.floor(Math.random()*data.result.problems.length)-1, 0);
let checkContestId = data.result.problems[randPos].contestId>=minContestId;
let checkRating = data.result.problems[randPos].rating>=minRating && data.result.problems[randPos].rating<=maxRating;
if(checkContestId==true && checkRating==true){
if(probTable.rows.length>7){
probTable.deleteRow(-1);
}
var row = probTable.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var linkk = document.createElement('a');
linkk.href = "https://codeforces.com/problemset/problem/"+data.result.problems[randPos].contestId+"/"+data.result.problems[randPos].index;
linkk.target = "_blank";
linkk.rel = "noopener";
linkk.innerHTML = data.result.problems[randPos].contestId+data.result.problems[randPos].index;
cell1.innerHTML = data.result.problems[randPos].name;
cell2.appendChild(linkk);
probFound = true;
break;
}
}
btn.className = "button is-light is-fullwidth is-large";
});
};