Hide Code

Hides the code editor of leetcode problems to prevent spoilers when redoing problems

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

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 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        Hide Code
// @namespace   Violentmonkey Scripts
// @match       https://leetcode.com/problems/*
// @grant       none
// @version     1.0
// @author      ojwefiasdfoj98298347
// @description Hides the code editor of leetcode problems to prevent spoilers when redoing problems
// @license MIT
// ==/UserScript==

async function wait_element(root, selector) {
  return new Promise((resolve, reject) => {
    (new MutationObserver(check)).observe(root, {childList: true, subtree: true});
    function check(changes, observer) {
      let element = root.querySelector(selector);
      if(element) {
        observer.disconnect();
        resolve(element);
      }
    }
  });
}

(async () => {
  const container = await wait_element(document, '[data-track-load="code_editor"]');
  const first = container.firstElementChild;
  first.style['display'] = 'none';

  const btn = document.createElement('button');
  btn.appendChild(document.createTextNode('Reveal'));
  btn.setAttribute('type', 'button');
  btn.style['background-color'] = 'red';
  btn.style['height'] = '100%';
  btn.style['font-size'] = '36pt';
  container.prepend(btn);

  btn.addEventListener('click', () => {
    first.style['display'] = '';
    btn.remove();
  })
})()