Skip to content
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

[Feature Request] Add "sync all solved problems" button #77

Closed
JasperSui opened this issue Mar 17, 2021 · 11 comments
Closed

[Feature Request] Add "sync all solved problems" button #77

JasperSui opened this issue Mar 17, 2021 · 11 comments
Labels
feature What feature would you like LeetHub to have and why?

Comments

@JasperSui
Copy link

Hi Qasim Wani,

It's a very useful project, and how about having a "sync all solved problems" button to sync all solved problems on LeetCode but not in the specific repository?

It will be helpful for those who used to solve problems on LeetCode but are new to your extension.

Thank you for your contribution, I really appreciate it!

@JasperSui JasperSui changed the title Add "sync all solved problems" button [Feature Request] Add "sync all solved problems" button Mar 17, 2021
@QasimWani QasimWani added the feature What feature would you like LeetHub to have and why? label Mar 17, 2021
@QasimWani
Copy link
Owner

@JasperSui see #15
the main problem with this is that the only way to do this is by brute-forcing every single solved problem. Getting a list of solved problem along with URL is straightforward, taking less than a second. See the following code to do that:

const getAllSolvedProblems = () => {
  const LEETCODE_API_URL = 'https://leetcode.com/api/problems/algorithms';

  const LEETCODE_PROBLEM_URL_PREFIX = "https://leetcode.com/problems/";

  const xhr = new XMLHttpRequest();

  /* Gather data */
  var problems_data = [];

  xhr.addEventListener('readystatechange', function () {
    if (xhr.readyState === 4) {
      let problems = JSON.parse(xhr.responseText)["stat_status_pairs"];
      problems.forEach(problem => {
        if(problem["status"] && problem["status"] === "ac")
        {
          var stat = problem["stat"];
          let problem_data = {"title" : stat["question__title"], "url" : LEETCODE_PROBLEM_URL_PREFIX + stat["question__title_slug"], "id" : stat["frontend_question_id"]};
          problems_data.push(problem_data);
        }
      });
      console.log(problems_data[0]);
    }
  });


  xhr.open('POST', LEETCODE_API_URL, true);
  xhr.send();
};

The problem lies in getting the actual code for an existing problem. There's no public facing leetcode api that does this. This means that LeetHub would need to run N requests (N = number of solved leetcode problems that aren't already on LeetHub) causing the browser to be very slow. Since we can take care of it asynchronously, the process can very easily break down if you close the page (say welcome.html) that performs this action. Sure we can store this, but the main drawback that I see is that this will be very slow.

I personally think this is a great idea (see link above for past discussion) but I can't come up with a more time efficient approach. If you (or anyone else) has a better way of doing it, please submit a PR!

@JasperSui
Copy link
Author

JasperSui commented Mar 17, 2021

@QasimWani
First, thank you for instant reply!

I totally agree with your opinion that sync all problems one by one will facing some unexpected errors (closing welcome page, network issue, e.g.), I'll try to think about a better way after fully understanding this project.

Thank you again about explaining the reason why you chose not to do this and having an open mind!

Have a great day!

@LeeHeonSik
Copy link

LeeHeonSik commented Jan 5, 2022

#77
Hi, thank you for making Leethub.
I have another question about this.
How can I use this?
Please explain more specific if you can.
thank U so much and I'm sorry if I wasn't polite :)

@rockharshitmaurya
Copy link

rockharshitmaurya commented Feb 3, 2022

@JasperSui see #15 the main problem with this is that the only way to do this is by brute-forcing every single solved problem. Getting a list of solved problem along with URL is straightforward, taking less than a second. See the following code to do that:

const getAllSolvedProblems = () => {
  const LEETCODE_API_URL = 'https://leetcode.com/api/problems/algorithms';

  const LEETCODE_PROBLEM_URL_PREFIX = "https://leetcode.com/problems/";

  const xhr = new XMLHttpRequest();

  /* Gather data */
  var problems_data = [];

  xhr.addEventListener('readystatechange', function () {
    if (xhr.readyState === 4) {
      let problems = JSON.parse(xhr.responseText)["stat_status_pairs"];
      problems.forEach(problem => {
        if(problem["status"] && problem["status"] === "ac")
        {
          var stat = problem["stat"];
          let problem_data = {"title" : stat["question__title"], "url" : LEETCODE_PROBLEM_URL_PREFIX + stat["question__title_slug"], "id" : stat["frontend_question_id"]};
          problems_data.push(problem_data);
        }
      });
      console.log(problems_data[0]);
    }
  });


  xhr.open('POST', LEETCODE_API_URL, true);
  xhr.send();
};

The problem lies in getting the actual code for an existing problem. There's no public facing leetcode api that does this. This means that LeetHub would need to run N requests (N = number of solved leetcode problems that aren't already on LeetHub) causing the browser to be very slow. Since we can take care of it asynchronously, the process can very easily break down if you close the page (say welcome.html) that performs this action. Sure we can store this, but the main drawback that I see is that this will be very slow.

I personally think this is a great idea (see link above for past discussion) but I can't come up with a more time efficient approach. If you (or anyone else) has a better way of doing it, please submit a PR!

there is a pre-existing repo on GitHub which can sync all previous submissions please take a look at that repo's code to get some idea and add a new feature for adding previously solved problem

check this https://github.com/joshcai/leetcode-sync

@Ifechukwudaniel
Copy link

Actually, Leetcode stores all your previously solved problems in local storage so it is very possible, all I have to do is reverse engineer it , you also need the question number

Screenshot 2022-02-17 at 17 39 01

Screenshot 2022-02-17 at 17 39 05

@Ifechukwudaniel
Copy link

All i just need is the go ahead

@QasimWani
Copy link
Owner

All i just need is the go ahead

Sure thing. Plz join our discord (see readMe) and we can chat over there for updates

@Ifechukwudaniel
Copy link

😎😎😎😎

@Sanojkumaryadav
Copy link

#83

@vigneshkumar28
Copy link

vigneshkumar28 commented Dec 12, 2023

@JasperSui see #15 the main problem with this is that the only way to do this is by brute-forcing every single solved problem. Getting a list of solved problem along with URL is straightforward, taking less than a second. See the following code to do that:

const getAllSolvedProblems = () => {
  const LEETCODE_API_URL = 'https://leetcode.com/api/problems/algorithms';

  const LEETCODE_PROBLEM_URL_PREFIX = "https://leetcode.com/problems/";

  const xhr = new XMLHttpRequest();

  /* Gather data */
  var problems_data = [];

  xhr.addEventListener('readystatechange', function () {
    if (xhr.readyState === 4) {
      let problems = JSON.parse(xhr.responseText)["stat_status_pairs"];
      problems.forEach(problem => {
        if(problem["status"] && problem["status"] === "ac")
        {
          var stat = problem["stat"];
          let problem_data = {"title" : stat["question__title"], "url" : LEETCODE_PROBLEM_URL_PREFIX + stat["question__title_slug"], "id" : stat["frontend_question_id"]};
          problems_data.push(problem_data);
        }
      });
      console.log(problems_data[0]);
    }
  });


  xhr.open('POST', LEETCODE_API_URL, true);
  xhr.send();
};

The problem lies in getting the actual code for an existing problem. There's no public facing leetcode api that does this. This means that LeetHub would need to run N requests (N = number of solved leetcode problems that aren't already on LeetHub) causing the browser to be very slow. Since we can take care of it asynchronously, the process can very easily break down if you close the page (say welcome.html) that performs this action. Sure we can store this, but the main drawback that I see is that this will be very slow.

I personally think this is a great idea (see link above for past discussion) but I can't come up with a more time efficient approach. If you (or anyone else) has a better way of doing it, please submit a PR!

Hi @QasimWani / Someone,

How to use this. Can someone please explain. I want push the old submission codes to github with same dates(if i do manully its pushing with today date not the date which i submitted the leetcode question). Thanks in advance!

@akshat-1
Copy link

I think it can be a feasible if we check if number of solved problems are less than let say 50 , then only this feature will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature What feature would you like LeetHub to have and why?
Projects
None yet
Development

No branches or pull requests

8 participants