Greasy Fork is available in English.

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.

  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.1
  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. // @exclude https://leetcode.com/contest/*/problems/*/
  12. // @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.
  13. // ==/UserScript==
  14.  
  15. const openAllProblems = () => {
  16. const problemsClass = "ul.contest-question-list li a";
  17. const problems = document.querySelectorAll(problemsClass);
  18. // console.log(problems.length);
  19. problems.forEach((problem) => {
  20. window.open(problem.href);
  21. });
  22. };
  23.  
  24. const main = () => {
  25. const whichClass = ".col-md-6";
  26. const buttonClass = "btn btn-default panel-hover";
  27. const buttonText = "Open All Problems";
  28. if (document.querySelector(whichClass) === null) {
  29. // wait for the page to load
  30. window.setTimeout(main, 2000);
  31. }
  32. const button = document.createElement("button");
  33. button.innerText = buttonText;
  34. button.addEventListener("click", openAllProblems);
  35. button.className = buttonClass;
  36. document.querySelector(whichClass).appendChild(button);
  37. };
  38.  
  39. main();