LeetCode Reset Stopwatch

Leetcode reset the stopwatch with one click

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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();
})();