LeetCode 10-Min Timer

Adds a 10-minute countdown timer on LeetCode problems.

目前为 2025-03-10 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name LeetCode 10-Min Timer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds a 10-minute countdown timer on LeetCode problems.
  6. // @author Yange
  7. // @match https://leetcode.com/problems/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function createTimerButton() {
  16. const button = document.createElement("button");
  17. button.innerText = "Start 10m Timer";
  18. button.style.position = "absolute";
  19. button.style.bottom = "20px";
  20. button.style.right = "20px";
  21. button.style.padding = "10px";
  22. button.style.backgroundColor = "#ff5722";
  23. button.style.color = "white";
  24. button.style.border = "none";
  25. button.style.borderRadius = "5px";
  26. button.style.cursor = "pointer";
  27. button.style.fontSize = "14px";
  28. button.style.zIndex = "9999";
  29.  
  30. button.onclick = startTimer;
  31. document.body.appendChild(button);
  32. }
  33.  
  34. function startTimer() {
  35. let timeLeft = 10 * 60; // 10 minutes in seconds
  36. const timerDisplay = document.createElement("div");
  37. timerDisplay.style.position = "absolute";
  38. timerDisplay.style.bottom = "50px";
  39. timerDisplay.style.right = "20px";
  40. timerDisplay.style.padding = "10px";
  41. timerDisplay.style.backgroundColor = "#222";
  42. timerDisplay.style.color = "#fff";
  43. timerDisplay.style.borderRadius = "5px";
  44. timerDisplay.style.fontSize = "16px";
  45. timerDisplay.style.zIndex = "9999";
  46. timerDisplay.innerText = "10:00";
  47. document.body.appendChild(timerDisplay);
  48.  
  49. const interval = setInterval(() => {
  50. timeLeft--;
  51. const minutes = Math.floor(timeLeft / 60);
  52. const seconds = timeLeft % 60;
  53. timerDisplay.innerText = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
  54.  
  55. if (timeLeft <= 0) {
  56. clearInterval(interval);
  57. alert("Time is up!");
  58. timerDisplay.innerText = "Time's up!";
  59. timerDisplay.style.backgroundColor = "red";
  60. }
  61. }, 1000);
  62. }
  63.  
  64. createTimerButton();
  65. })();