LeetCode Reset Code to Default Keybind

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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')
      }
    }
  });
})();