├── README.md
├── images
└── code.png
├── index.html
├── script.js
└── style.css
/README.md:
--------------------------------------------------------------------------------
1 | # CF-Solver
--------------------------------------------------------------------------------
/images/code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abhishek-singh31/CF-Solver/24560f31049ace626531a465898bc411fa4c209d/images/code.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | CF-Solver
10 |
11 |
12 |
13 | CF-Solver
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
Select Rating:
31 |
61 |
62 |
63 |
64 |
65 |
105 |
106 |
107 |
108 |
109 |
Select Time:
110 |
124 |
125 |
126 |
127 |
128 |
Your Score: 0
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
Time Left:
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
Time's Up !!
162 |
163 |
164 |
165 |
166 |
167 |
168 |
Problem Solved Successfully !!
169 |
170 |
171 |
172 |
173 |
174 |
175 |
Problem Not Solved Successfully !!
176 |
177 |
178 |
179 |
180 |
181 |
You Gave up !!
182 |
183 |
184 |
185 |
186 |
187 |
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | const solve=document.querySelector('#solve');
2 | const tags=document.querySelectorAll('#tags');
3 | const rating=document.querySelectorAll('#rating');
4 | const hour=document.querySelector('#hour');
5 | const minute=document.querySelector('#minute');
6 | const second=document.querySelector('#second');
7 | const login=document.querySelector('#login');
8 | const userName=document.querySelector('#uname');
9 | const container=document.querySelector('.container');
10 | const login_section=document.querySelector('.login-section');
11 | const modal=document.querySelector('.modal');
12 | const footer=document.querySelector('.footer');
13 | const timeLeft=document.querySelector('.time-left');
14 | const overlay=document.querySelector('.overlay');
15 | const done=document.querySelector('#done');
16 | const giveup=document.querySelector('#giveup');
17 | const current=document.querySelector('.current');
18 | const high=document.querySelector('.high');
19 | const timeup=document.querySelector('.timeup');
20 | const success=document.querySelector('.success');
21 | const failure=document.querySelector('.failure');
22 | const gaveup=document.querySelector('.gaveup');
23 | let totalTime;
24 | let userSolvedProblems;
25 | login.addEventListener('click',(e)=>{
26 | e.preventDefault();
27 | let userHandle='https://codeforces.com/api/user.info?handles=';
28 | userHandle+=`${userName.value}`;
29 | fetch(userHandle)
30 | .then((response) => {
31 | if(response.ok){
32 | return response.json();
33 | }
34 | else{
35 | throw new Error();
36 | }
37 | })
38 | .then((data)=>{
39 | console.log(data);
40 | login_section.style.display='none';
41 | footer.classList.remove('before');
42 | container.style.display='flex';
43 | let userStatus=`https://codeforces.com/api/user.status?handle=${userName.value}`;
44 | fetch(userStatus)
45 | .then(response=>response.json())
46 | .then(data=>{
47 | userSolvedProblems=[]
48 | let UserProblems=data['result'];
49 | for(const problem of UserProblems){
50 | if(problem['verdict']==="OK"){
51 | let problemName=problem['problem']['name'];
52 | userSolvedProblems.push(problemName);
53 | }
54 | }
55 | })
56 | })
57 | .catch(err=>{
58 | alert("Please enter correct username !");
59 | })
60 | })
61 |
62 | let myInterval;
63 | let selectedRating;
64 | let selectedTags;
65 | let selectedProblems;
66 | let x;
67 | solve.addEventListener('click',(e)=>{
68 | e.preventDefault();
69 | let URL='https://codeforces.com/api/problemset.problems';
70 | selectedTags=[];
71 | selectedRating=[];
72 | for(let r of rating){
73 | if(r.checked==true){
74 | selectedRating.push(+r.name);
75 | }
76 | }
77 | for(let t of tags){
78 | if(t.checked==true){
79 | selectedTags.push(t.name);
80 | }
81 | }
82 | if(selectedTags.length){
83 | URL+='?tags=';
84 | for(let t of selectedTags)
85 | URL+=`${t};`;
86 | }
87 | // console.log(userName.value)
88 | fetch(URL)
89 | .then((response) => {
90 | if(response.ok){
91 | return response.json();
92 | }
93 | else{
94 | throw new Error();
95 | }
96 | })
97 | .then((data)=>{
98 | const problems=data['result']['problems'];
99 | selectedProblems=[];
100 | for(const problem of problems){
101 | if(problem.hasOwnProperty('rating')){
102 | if((selectedRating.length==0 || selectedRating.includes(problem['rating']))&& !userSolvedProblems.includes(problem['name'])){
103 | selectedProblems.push(problem);
104 | }
105 | }
106 | }
107 | // console.log(selectedProblems);
108 | if(selectedProblems.length==0){
109 | throw new Error();
110 | }
111 | x=Math.floor(Math.random()*selectedProblems.length);
112 | let problemURL=`https://www.codeforces.com/contest/${selectedProblems[x]['contestId']}/problem/${selectedProblems[x]['index']}`;
113 | totalTime=(+hour.value*3600)+(+minute.value*60) + (+second.value);
114 | // console.log(totalTime);
115 | if(totalTime==0 || isNaN(totalTime)){
116 | alert('Please enter valid time !');
117 | }
118 | else{
119 | modal.style.display='grid';
120 | container.style.display='none';
121 | footer.classList.add('before');
122 | overlay.style.display='block';
123 | myInterval=setInterval(()=>{
124 | timeLeft.innerHTML=fancyTimeFormat(totalTime);
125 | totalTime--;
126 | if(totalTime==0){
127 | check(selectedProblems,x,totalTime);
128 | clearInterval(myInterval);
129 | reset();
130 | }
131 | },1000);
132 | openProblem(problemURL);
133 | }
134 | })
135 | .catch(err=>{
136 | alert("No problems found with selected tags/ratings !");
137 | })
138 | })
139 |
140 |
141 | done.addEventListener('click',(e)=>{
142 | e.preventDefault();
143 | let previousScore=+current.innerHTML;
144 | check(selectedProblems,x,totalTime);
145 | })
146 | giveup.addEventListener('click',(e)=>{
147 | e.preventDefault();
148 | gaveup.classList.add('active');
149 | setTimeout(()=>{
150 | gaveup.classList.remove('active');
151 | },2000);
152 | reset();
153 | totalTime=0;
154 | })
155 |
156 | function check(selectedProblems,x){
157 | let URL=`https://codeforces.com/api/user.status?handle=${userName.value}&from=1&count=1`;
158 | console.log(URL);
159 | fetch(URL)
160 | .then((response) => {
161 | if(response.ok){
162 | return response.json();
163 | }
164 | else{
165 | throw new Error();
166 | }
167 | })
168 | .then((data)=>{
169 | let userContestId=data['result'][0]['problem']['contestId'];
170 | let userIndex=data['result'][0]['problem']['index'];
171 | let solvedContestId=selectedProblems[x]['contestId'];
172 | let solvedIndex=selectedProblems[x]['index'];
173 | let verdict=data['result'][0]['verdict'];
174 | if(userContestId==solvedContestId && userIndex==solvedIndex && verdict==="OK"){
175 | // console.log("Mission Successful");
176 | current.innerHTML++;
177 | clearInterval(myInterval);
178 | success.classList.add('active');
179 | setTimeout(()=>{
180 | success.classList.remove('active');
181 | },2000);
182 | reset();
183 | }
184 | else{
185 | if(totalTime==0){
186 | timeup.classList.add('active');
187 | setTimeout(()=>{
188 | timeup.classList.remove('active');
189 | },3000);
190 | reset();
191 | }
192 | else{
193 | failure.classList.add('active');
194 | setTimeout(()=>{
195 | failure.classList.remove('active');
196 | },2000);
197 | }
198 | }
199 | })
200 | .catch(err=>{
201 | alert("Some Error Occured !");
202 | })
203 |
204 | }
205 |
206 | function reset(){
207 | clearInterval(myInterval);
208 | modal.style.display='none';
209 | container.style.display='flex';
210 | footer.classList.remove('before');
211 | overlay.style.display='none';
212 | timeLeft.innerHTML="";
213 | }
214 | function openProblem(URL){
215 | window.open(URL,'_blank');
216 | }
217 |
218 | function fancyTimeFormat(duration)
219 | {
220 | // Hours, minutes and seconds
221 | var hrs = ~~(duration / 3600);
222 | var mins = ~~((duration % 3600) / 60);
223 | var secs = ~~duration % 60;
224 |
225 | // Output like "1:01" or "4:03:59" or "123:03:59"
226 | var ret = "";
227 |
228 | if (hrs > 0) {
229 | ret += "" + hrs + ":" + (mins < 10 ? "0" : "");
230 | }
231 |
232 | ret += "" + mins + ":" + (secs < 10 ? "0" : "");
233 | ret += "" + secs;
234 | return ret;
235 | }
236 |
237 |
238 |
239 |
240 |
--------------------------------------------------------------------------------
/style.css:
--------------------------------------------------------------------------------
1 | *{
2 | box-sizing: border-box;
3 | margin:0;
4 | padding: 0;
5 | outline: 0;
6 |
7 | }
8 |
9 | body{
10 | background:#1F1D36;
11 | color:#FFFFFF;
12 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
13 | overflow-x: hidden;
14 | }
15 |
16 | .login-section{
17 | width:350px;
18 | height:400px;
19 | display: flex;
20 | flex-direction: column;
21 | justify-content: center;
22 | align-items: center;
23 | margin:0 auto;
24 | }
25 |
26 | .login-section label{
27 | font-size: 18px;
28 | margin:10px;
29 | }
30 |
31 | .login-section input{
32 | border:2px solid #000;
33 | padding:5px 10px;
34 | width:200px;
35 | border-radius:20px;
36 | font-size:16px;
37 | text-align: center;
38 | color:#000;
39 | margin:20px;
40 | }
41 |
42 | .container{
43 | padding:32px;
44 | display: none;
45 | flex-direction: column;
46 | align-items: center;
47 | justify-content: center;
48 | }
49 |
50 | h1{
51 | font-size: 72px;
52 | margin:15px;
53 | text-align: center;
54 | }
55 |
56 | h3{
57 | font-size: 28px;
58 | }
59 |
60 | input[type="checkbox"]{
61 | height:20px;
62 | width:20px;
63 | margin-right:5px;
64 | position: relative;
65 | top:5px;
66 | }
67 |
68 | .ratings-div,.tags-div{
69 | margin:20px auto;
70 | display: flex;
71 | flex-direction: column;
72 |
73 | }
74 | .ratings-tab,.tags-tab{
75 | display: grid;
76 | grid-template-columns: repeat(7,1fr);
77 | }
78 |
79 | .ratings-tab .check,.tags-tab .check{
80 | margin:10px;
81 | margin-left:0;
82 | }
83 |
84 | button{
85 | background:rgb(36, 36, 36);
86 | color:#fff;
87 | border:2px solid rgb(168, 164, 164);
88 | font-size:16px;
89 | padding:10px 15px;
90 | border-radius:10px;
91 | cursor:pointer;
92 | }
93 |
94 | button:hover{
95 | background:#0e0d0d;
96 | color:#fff;
97 | }
98 |
99 | .timer{
100 | display: flex;
101 | flex-direction: column;
102 | }
103 |
104 | .timer-div{
105 | display: flex;
106 | flex-direction: row;
107 | margin:10px 0;
108 | }
109 |
110 | .timer-form{
111 | margin-right: 20px;
112 | }
113 |
114 | .timer-form input[type="text"]{
115 | width:40px;
116 | margin:5px;
117 | text-align: center;
118 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
119 | }
120 |
121 | .score{
122 | background:rgba(0, 0, 0, 0.4);
123 | border:2px solid #f1f1f1;
124 | border-radius:10px;
125 | padding:10px;
126 | position: fixed;
127 | right:10px;
128 | top:10px;
129 | }
130 |
131 | .overlay{
132 | height:100vh;
133 | width:100vw;
134 | background:rgba(20, 20, 20, 0.671);
135 | position: absolute;
136 | display: none;
137 | top:0;
138 | z-index:1;
139 | backdrop-filter: blur(10px);
140 | }
141 |
142 | .modal{
143 | height:250px;
144 | width:300px;
145 | display:none;
146 | place-items: center;
147 | position: absolute;
148 | left:50%;
149 | top:50%;
150 | transform: translate(-50%,-50%);
151 | background: #191919cb;
152 | border:2px solid #000;
153 | border-radius: 10px;
154 | backdrop-filter: blur(20px);
155 | z-index:2;
156 | }
157 |
158 | .btn-group button{
159 | margin:10px;
160 | }
161 |
162 | .footer{
163 | background:#191919;
164 | text-align: center;
165 | padding:10px;
166 | font-size:18px;
167 | width:100%;
168 | }
169 |
170 | .footer.before{
171 | position: absolute;
172 | bottom:0;
173 | z-index:1;
174 | }
175 |
176 | .contact-links{
177 | display: flex;
178 | justify-content: center;
179 | margin-top:10px;
180 | align-items: center;
181 | }
182 |
183 | a{
184 | color:#fff;
185 | text-decoration: none;
186 | margin-right:10px;
187 | }
188 |
189 | i{
190 | font-size: 24px;
191 | }
192 |
193 | .result{
194 | z-index:10000;
195 | background:#fff;
196 | width:fit-content;
197 | padding:10px 20px;
198 | display: flex;
199 | position: absolute;
200 | bottom:100px;
201 | right:20px;
202 | border-radius:20px;
203 | transform:translateX(+1000px);
204 | transition: transform 0.4s;
205 |
206 | }
207 |
208 | .result.active{
209 | transition: transform 0.4s;
210 | transform:translateX(0);
211 | }
212 |
213 | .result i{
214 | margin-right:10px;
215 | }
216 |
217 | .result p{
218 | margin-left:10px;
219 | font-weight:700;
220 | }
221 | .timeup{
222 | border:5px solid rgb(255, 0, 0);
223 | color:rgb(255, 0, 0);
224 | }
225 |
226 | .success{
227 | border:5px solid rgb(30, 207, 30);
228 | color:rgb(30, 207, 30);
229 | }
230 |
231 | .failure{
232 | border:5px solid rgb(255, 136, 0);
233 | color:rgb(255, 136, 0);
234 | }
235 |
236 | .gaveup{
237 | border:5px solid rgb(119, 0, 255);
238 | color:rgb(119, 0, 255);
239 | }
240 |
241 |
242 |
243 | @media only screen and (max-width:600px) {
244 | h1{
245 | font-size:3.5em;
246 | }
247 |
248 | h3{
249 | font-size:1em;
250 | }
251 |
252 | input{
253 | height:15px;
254 | width:15px;
255 | margin-right:5px;
256 | position: relative;
257 | top:2.5px;
258 | }
259 | .ratings-div,.tags-div{
260 | margin:10px auto;
261 | display: flex;
262 | flex-direction: column;
263 |
264 | }
265 | .ratings-tab,.tags-tab{
266 | display: grid;
267 | grid-template-columns: repeat(3,1fr);
268 | }
269 |
270 | .ratings-tab .check,.tags-tab .check{
271 | margin:10px;
272 | margin-left:0;
273 | }
274 |
275 | button{
276 | background:rgb(36, 36, 36);
277 | color:#fff;
278 | border:2px solid rgb(168, 164, 164);
279 | font-size:16px;
280 | padding:10px 15px;
281 | border-radius:10px;
282 | cursor:pointer;
283 | margin:10px;
284 | }
285 | button:hover{
286 | background:#0e0d0d;
287 | color:#fff;
288 | }
289 | }
290 |
--------------------------------------------------------------------------------