function copyToClipboard(element) { if (!element) return; const messageElement = element.closest(".message, .user-message, .assistant-message"); if (!messageElement) return; const rawText = messageElement.getAttribute("data-raw"); if (!rawText) return; navigator.clipboard.writeText(rawText).then(function() { const originalSvg = element.innerHTML; element.innerHTML = ""; setTimeout(() => { element.innerHTML = originalSvg; }, 1000); }).catch(function(err) { console.error("Failed to copy text: ", err); }); } function regenerateClick() { document.getElementById("Regenerate").click(); } function handleMorphdomUpdate(text) { console.log("Morphing!"); morphdom( document.getElementById("chat").parentNode, "
" + text + "
", { onBeforeElUpdated: function(fromEl, toEl) { if (fromEl.tagName === "PRE" && fromEl.querySelector("code[data-highlighted]")) { const fromCode = fromEl.querySelector("code"); const toCode = toEl.querySelector("code"); if (fromCode && toCode && fromCode.textContent === toCode.textContent) { // If the content is the same, preserve the entire
 element
            toEl.className = fromEl.className;
            toEl.innerHTML = fromEl.innerHTML;
            return false; // Skip updating the 
 element
          }
        }
        return !fromEl.isEqualNode(toEl); // Update only if nodes differ
      }
    }
  );
}