Загрузка данных


(() => {
  const INDENT = '\u00A0'.repeat(6);   // отступ: 6 неразрывных пробелов
  const EMPTY_LINE = false;            // true — пустая строка между абзацами

  const ae = document.activeElement;
  const target = (ae && (ae.tagName === 'TEXTAREA' || ae.isContentEditable))
    ? ae : document.querySelector('textarea, [contenteditable="true"]');
  if (!target) { alert('Поле не найдено. Кликните в поле ответа и запустите снова.'); return; }

  const box = document.createElement('div');
  box.style.cssText = 'position:fixed;top:10%;left:15%;right:15%;bottom:10%;z-index:999999;background:#fff;border:2px solid #333;padding:12px;display:flex;flex-direction:column;gap:8px;box-shadow:0 0 30px rgba(0,0,0,.4)';
  box.innerHTML = '<b>Вставьте текст (Ctrl+V) и нажмите «Перенести в форму»</b>' +
    '<textarea style="flex:1;font:14px sans-serif"></textarea>' +
    '<div><button data-a="ok">Перенести в форму</button> <button data-a="no">Отмена</button></div>';
  document.body.appendChild(box);
  const ta = box.querySelector('textarea');
  ta.focus();

  box.addEventListener('click', e => {
    const a = e.target.dataset.a;
    if (!a) return;
    if (a === 'ok') {
      const paras = ta.value.replace(/\r\n?/g, '\n').split('\n')
        .map(l => l.replace(/^[\s\u00A0.°·•\u2022\u25E6]+/, '').trimEnd())
        .filter(l => l);

      if (target.tagName === 'TEXTAREA') {
        const text = paras.map(p => INDENT + p).join(EMPTY_LINE ? '\n\n' : '\n');
        Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set.call(target, text);
        target.dispatchEvent(new Event('input', { bubbles: true }));
        target.dispatchEvent(new Event('change', { bubbles: true }));
      } else {
        const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
        target.focus();
        document.execCommand('selectAll');
        document.execCommand('insertHTML', false,
          paras.map(p => '<p>' + INDENT + esc(p) + '</p>').join(EMPTY_LINE ? '<p><br></p>' : ''));
      }
    }
    box.remove();
  });
})();