LeetCode Contest: Open All Problems

Add an "Open All Problems" button on the LeetCode Contest page. Note that Pop-up windows need to be allowed in the web browser.

As of 2022-08-22. See the latest version.

  1. // ==UserScript==
  2. // @name LeetCode Contest: Open All Problems
  3. // @namespace JohnZhu04
  4. // @match https://leetcode.com/contest/*-contest-*/
  5. // @grant none
  6. // @version 1.0
  7. // @author JohnZhu04
  8. // @license MIT
  9. // @supportURL https://github.com/JohnZhu04/LeetScript/issues
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
  11. // @description Add an "Open All Problems" button on the LeetCode Contest page. Note that Pop-up windows need to be allowed in the web browser.
  12. // ==/UserScript==
  13.  
  14. const openAllProblems = () => {
  15. const problems = document.querySelectorAll("ul.contest-question-list li a");
  16. console.log(problems.length);
  17. problems.forEach((problem) => {
  18. window.open(problem.href);
  19. });
  20. };
  21.  
  22. const main = () => {
  23. if (document.querySelector(".col-md-6") === null) {
  24. window.setTimeout(main, 2000);
  25. }
  26. const button = document.createElement("button");
  27. button.innerText = "Open All Problems";
  28. button.addEventListener("click", openAllProblems);
  29. button.className = "btn btn-default panel-hover";
  30. document.querySelector(".col-md-6").appendChild(button);
  31. };
  32.  
  33. main();