Auto start LeetCode timer

Automatically start LeetCode official timer.

2023-11-10 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  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.1
  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 i of [0, 1]) {
  22. if (cur[i]?.classList.contains("flex-none")) {
  23. cur[i].click();
  24. observerInstance.disconnect();
  25. }
  26. }
  27. });
  28. observer.observe(document.body, {
  29. childList: true,
  30. subtree: true,
  31. });
  32. })();