Better GitHub Gists Code Area

Resizes the editor to fit the viewport height, subtracting 500px. Handles window resizing.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Better GitHub Gists Code Area
// @namespace    https://github.com/palemoky
// @version      20250325
// @description  Resizes the editor to fit the viewport height, subtracting 500px. Handles window resizing.
// @author       Palemoky
// @license      Apache
// @match        https://gist.github.com/*
// @icon         https://raw.githubusercontent.com/homarr-labs/dashboard-icons/refs/heads/main/webp/github.webp
// @run-at       document-body
// @grant        none
// ==/UserScript==

'use strict';

function adjustCodeMirrorHeight() {
    requestAnimationFrame(() => {
        const codeMirrorDiv = document.querySelector('.CodeMirror');

        if (codeMirrorDiv && codeMirrorDiv.CodeMirror) {
            const newHeight = document.documentElement.clientHeight - 457;
            codeMirrorDiv.style.height = Math.max(0, newHeight) + 'px';
            codeMirrorDiv.CodeMirror.refresh();
        }
    });
}

function debounce(func, wait) {
    let timeout;
    return function(...args) {
        const context = this;
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(context, args), wait);
    };
}

const debouncedAdjustCodeMirrorHeight = debounce(adjustCodeMirrorHeight, 200);

setTimeout(debouncedAdjustCodeMirrorHeight, 100);

const observer = new MutationObserver(debouncedAdjustCodeMirrorHeight);
observer.observe(document.body, { childList: true, subtree: true });

window.addEventListener('resize', debouncedAdjustCodeMirrorHeight);