Auto start LeetCode timer

Automatically start LeetCode official timer.

  1. // ==UserScript==
  2. // @name Auto start LeetCode timer
  3. // @name:zh-tw 自動開始 LeetCode 計時器
  4. // @namespace https://github.com/zica87/self-made-userscipts
  5. // @version 1.2
  6. // @description Automatically start LeetCode official timer.
  7. // @description:zh-tw 自動開始 LeetCode 官方計時器。
  8. // @author zica
  9. // @match https://leetcode.com/problems/*
  10. // @grant none
  11. // @license GPL-2.0
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. if (document.URL.includes("/solutions/")) return;
  18.  
  19. const observer = new MutationObserver((_, observerInstance) => {
  20. const cur = document.getElementsByClassName("p-2");
  21. for (const c of cur) {
  22. if (
  23. c.classList.contains("flex-none") &&
  24. c.dataset?.state !== undefined
  25. ) {
  26. c.click();
  27. observerInstance.disconnect();
  28. }
  29. }
  30. });
  31. observer.observe(document.body, {
  32. childList: true,
  33. subtree: true,
  34. });
  35. })();