-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate with leetcode to populate completed problems #155
Comments
The closest thing to an API Leetcode has is this: https://leetcode.com/api/problems/algorithms/ In the meantime var solved = ['Contains Duplicate' ... ];
var tr = document.getElementsByTagName("tr");
// Skip the first 2 rows as they are not question rows
for (var i = 2; i < tr.length; i++) {
// Check if in solved
if(solved.includes(tr[i].children[1].children[0].innerText) === true){
tr[i].children[0].children[0].children[0].click(); // Simulate a toggle
}
} |
Relates to #179 |
With the introduction of #210, we should be able to accomplish this. I was thinking that we could retrieve all completed questions for a user and populate the checkboxes as such. https://leetcode.com/discuss/general-discussion/1297705/is-there-public-api-endpoints-available-for-leetcode might have a few leads for us! |
if you go to the site https://leetcode.com/api/problems/algorithms/ and paste the following code on the browser console while logged in on leetcode on another tab you can retrieve a list of all the names of the completed algorithms. Just copy the list and substitute the var solved with it and execute the code on the console and it will work :) fetch('https://leetcode.com/api/problems/algorithms/')
.then(response => response.json())
.then(data => {
const questionList = [];
const statStatusPairs = data.stat_status_pairs;
for (const pair of statStatusPairs) {
if (pair.status === 'ac') {
const questionTitle = pair.stat.question__title;
questionList.push(questionTitle);
}
}
console.log(questionList);
})
.catch(error => console.error('Error:', error)); I tried using the following code directly so I could skip copying the list and substituting the solved var, but was not able to make it work because of cors policy. As I am not a javascript dev nor a web developer, I gave up. If anyone knows how to circunvent the cors policy, feel free to modify the code: function get_solved_questions() {
return fetch('https://leetcode.com/api/problems/algorithms/')
.then(response => response.json())
.then(data => {
const questionList = [];
const statStatusPairs = data.stat_status_pairs;
for (const pair of statStatusPairs) {
if (pair.status === 'ac') {
const questionTitle = pair.stat.question__title;
questionList.push(questionTitle);
}
}
return questionList;
})
.catch(error => {
console.error('Error:', error);
return [];
});
}
var tr = document.getElementsByTagName("tr");
get_solved_questions()
.then(solved => {
// Skip the first 2 rows as they are not question rows
for (var i = 2; i < tr.length; i++) {
// Check if in solved
if (solved.includes(tr[i].children[1].children[0].innerText)) {
tr[i].children[0].children[0].children[0].click(); // Simulate a toggle
}
}
});
|
Another idea is integrating with Leetcode's API, if one exists, to mark already completed problems on LC as done.
The text was updated successfully, but these errors were encountered: