```// ==UserScript==
// @name         codecurber 2.0 simple scale fold with toggle
// @version      2.0
// @description  Scale down all code blocks larger than 5 lines with native styling; toggle full size on button click
// @match        *://yuntian-deng-chatgpt.hf.space/*
// @match        *://yuntian-deng-o1mini.hf.space/*
// @match        *://yuntian-deng-chatgpt4.hf.space/*
// @match        *://yuntian-deng-o1.hf.space/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  const MIN_LINES = 6;
  const SCALE_HEIGHT = '6em';

  const style = document.createElement('style');
  style.textContent = `
    .codecurber-mini-preview {
      max-height: ${SCALE_HEIGHT};
      overflow: auto;
      user-select: text;
      cursor: text;
      transition: max-height 0.3s ease;
      position: relative;
    }
    .codecurber-toggle-btn {
      display: inline-block;
      margin: 4px 0 12px 0;
      padding: 4px 12px;
      background: #1e1e1e;
      border: 1.5px solid #39ff14;
      border-radius: 8px;
      color: #39ff14;
      font-family: monospace;
      font-weight: bold;
      cursor: pointer;
      user-select: none;
      font-size: 0.75rem;
      line-height: 1;
      transition: background-color 0.25s ease, color 0.25s ease;
    }
    .codecurber-toggle-btn:hover {
      background: #39ff14;
      color: black;
    }
  `;
  document.head.appendChild(style);

  function isCodeBlockFoldable(codeEl) {
    if (!codeEl) return false;
    const text = codeEl.textContent || '';
    const lines = text.split('\n').length;
    return lines >= MIN_LINES;
  }

  function createToggleButton() {
    const btn = document.createElement('button');
    btn.type = 'button';
    btn.className = 'codecurber-toggle-btn';
    btn.textContent = 'Show full code';
    return btn;
  }

  function foldCodeBlock(codeEl) {
    if (codeEl.dataset.codecurberFolded === 'true') return; // Already processed

    codeEl.dataset.codecurberFolded = 'true';

    // Wrap code block in a container div to hold toggle btn & manage styles
    const container = document.createElement('div');
    container.style.display = 'inline-flex';
    container.style.flexDirection = 'column';
    container.style.width = '100%';
    codeEl.parentNode.insertBefore(container, codeEl);
    container.appendChild(codeEl);

    // Apply fold style
    codeEl.classList.add('codecurber-mini-preview');

    // Create and append toggle button
    const btn = createToggleButton();
    container.appendChild(btn);

    btn.addEventListener('click', () => {
      const folded = codeEl.classList.contains('codecurber-mini-preview');
      if (folded) {
        // Expand
        codeEl.style.maxHeight = 'none';
        codeEl.style.overflow = 'visible';
        codeEl.classList.remove('codecurber-mini-preview');
        btn.textContent = 'Fold code';
      } else {
        // Fold again
        codeEl.style.maxHeight = SCALE_HEIGHT;
        codeEl.style.overflow = 'auto';
        codeEl.classList.add('codecurber-mini-preview');
        btn.textContent = 'Show full code';
      }
    });
  }

  function foldAllLargeCodeBlocks() {
    const chat = document.querySelector('.bubble-wrap.svelte-gjtrl6');
    if (!chat) return;
    chat.querySelectorAll('code').forEach(codeEl => {
      if (isCodeBlockFoldable(codeEl)) {
        foldCodeBlock(codeEl);
      }
    });
  }

  function observeChat() {
    const chat = document.querySelector('.bubble-wrap.svelte-gjtrl6');
    if (!chat) return;
    const observer = new MutationObserver(() => {
      foldAllLargeCodeBlocks();
    });
    observer.observe(chat, {childList: true, subtree: true});
  }

  const initInt = setInterval(() => {
    if (document.querySelector('.bubble-wrap.svelte-gjtrl6')) {
      clearInterval(initInt);
      foldAllLargeCodeBlocks();
      observeChat();
    }
  }, 300);
})();
```