LeetCode Reset Code to Default Keybind

Press Ctrl+Shift+X to reset code to default on LeetCode

Verze ze dne 01. 03. 2026. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         LeetCode Reset Code to Default Keybind
// @namespace    Violentmonkey Scripts
// @match        https://leetcode.com/problems/*
// @grant        none
// @version      1.0
// @author      github.com/geoffkrishnan
// @description Press Ctrl+Shift+X to reset code to default on LeetCode
// @license MIT
// ==/UserScript==

(function() {
  const DEBUG = false;

  document.addEventListener('keydown', function(e) {
    // keybind - change if you want
    if (e.ctrlKey && e.shiftKey && e.key === 'KeyX') {
      e.preventDefault();
      if (DEBUG) console.log('key presses detected');

      const resetButton = document.querySelector('.fa-arrow-rotate-left');
      console.log('reset button:', resetButton);
      if (resetButton) {
        resetButton.closest('button').click();
        if (DEBUG) console.log('reset button clicked');


        const observer = new MutationObserver(() => {
          const confirmBtns = document.querySelectorAll('button');
          for (const cb of confirmBtns) {
            if (DEBUG) console.log('cb: ', cb);
            if (cb.textContent.trim() === 'Confirm') {
              if (DEBUG) console.log('confirm button: ', cb);
              cb.click();
              if (DEBUG) console.log('confirm button clicked');
              observer.disconnect();
            }
          }
        });

        observer.observe(document.body, { childList: true, subtree: true });
        setTimeout(() => observer.disconnect(), 3000);
      } else {
        console.warn('Reset button not found')
      }
    }
  });
})();