Greasy Fork is available in English.
Leetcode reset the stopwatch with one click
// ==UserScript==
// @name LeetCode Reset Stopwatch
// @description Leetcode reset the stopwatch with one click
// @namespace http://tampermonkey.net/
// @version 1.0
// @match https://leetcode.com/*
// @author Jatin Sharma
// @icon https://leetcode.com/favicon.ico
// @license MIT
// @grant none
// ==/UserScript==
(function () {
'use strict';
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
async function restartStopwatch() {
for (let i = 0; i < 5; i++) {
const buttons = document.querySelectorAll('div[role="popover"] button');
let clickedStart = false;
for (const btn of buttons) {
const text = btn.textContent?.trim();
btn.click();
if (text?.includes('Start Stopwatch')) {
clickedStart = true;
break;
}
await sleep(10);
}
if (clickedStart) break;
await sleep(80);
}
}
function init() {
document.addEventListener('click', (e) => {
if (e.ctrlKey) return;
const reset = e.target.closest('div[aria-label="Reset"]');
if (!reset) return;
restartStopwatch();
}, true);
}
init();
})();