Greasy Fork is available in English.

LeetCode Reset Code to Default Keybind

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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