LeetCode Reset Code to Default Keybind

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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')
      }
    }
  });
})();