-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
64 lines (51 loc) · 2.21 KB
/
popup.js
File metadata and controls
64 lines (51 loc) · 2.21 KB
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
document.addEventListener('DOMContentLoaded', function () {
function fetchProblems(callback) {
var url = 'https://codeforces.com/api/problemset.problems';
// Make a request to the Codeforces API to fetch the problems
fetch(url)
.then(function (response) {
return response.json();
})
.then(function (data) {
if (data.status === 'OK') {
var problems = data.result.problems;
callback(problems);
}
})
.catch(function (error) {
console.error('Error fetching problems:', error);
});
}
function filterProblems(problems, minRating, maxRating) {
// Filter the problems based on the rating range
var filteredProblems = problems.filter(function (problem) {
var rating = problem.rating;
return rating >= minRating && rating <= maxRating;
});
return filteredProblems;
}
function displayProblems(problems) {
var problemContainer = document.getElementById('problemContainer');
problemContainer.innerHTML = '';
if (problems.length === 0) {
problemContainer.textContent = 'No problems found within the specified rating range.';
} else {
var randomIndex = Math.floor(Math.random() * problems.length);
var randomProblem = problems[randomIndex];
var problemUrl = `https://codeforces.com/problemset/problem/${randomProblem.contestId}/${randomProblem.index}`;
chrome.tabs.create({ url: problemUrl });
}
}
document.getElementById('filterButton').addEventListener('click', function () {
var minRating = parseInt(document.getElementById('minRating').value);
var maxRating = parseInt(document.getElementById('maxRating').value);
if (isNaN(minRating) || isNaN(maxRating) || minRating > maxRating) {
alert('Invalid rating range.');
return;
}
fetchProblems(function (problems) {
var filteredProblems = filterProblems(problems, minRating, maxRating);
displayProblems(filteredProblems);
});
});
});