Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const xmlInput = document.getElementById('xmlInput');
+ const scrollOutput = document.getElementById('scrollOutput');
+ const convertBtn = document.getElementById('convertBtn');
+ const copyBtn = document.getElementById('copyBtn');
+
+ const convertXmlToScroll = (xml) => {
+ try {
+ // Basic XML to Scroll conversion logic
+ // This is a simplified example - expand based on requirements
+ const parser = new DOMParser();
+ const xmlDoc = parser.parseFromString(xml, 'text/xml');
+
+ let scroll = '';
+ const processNode = (node, indent = '') => {
+ if (node.nodeType === 1) { // Element node
+ scroll += `${indent}${node.nodeName}\n`;
+ if (node.attributes.length > 0) {
+ Array.from(node.attributes).forEach(attr => {
+ scroll += `${indent} ${attr.name} ${attr.value}\n`;
+ });
+ }
+ Array.from(node.childNodes).forEach(child => {
+ processNode(child, indent + ' ');
+ });
+ } else if (node.nodeType === 3 && node.nodeValue.trim()) { // Text node
+ scroll += `${indent}${node.nodeValue.trim()}\n`;
+ }
+ };
+
+ processNode(xmlDoc.documentElement);
+ return scroll;
+ } catch (error) {
+ return `Error: ${error.message}`;
+ }
+ };
+
+ convertBtn.addEventListener('click', () => {
+ const xml = xmlInput.value;
+ if (!xml.trim()) {
+ scrollOutput.value = 'Please enter XML content';
+ return;
+ }
+
+ scrollOutput.value = convertXmlToScroll(xml);
+ });
+
+ copyBtn.addEventListener('click', async () => {
+ try {
+ await navigator.clipboard.writeText(scrollOutput.value);
+ const originalText = copyBtn.textContent;
+ copyBtn.textContent = 'Copied!';
+ setTimeout(() => {
+ copyBtn.textContent = originalText;
+ }, 2000);
+ } catch (err) {
+ console.error('Failed to copy text:', err);
+ }
+ });
+
+ // Add animation effects
+ const addTypingEffect = (element) => {
+ element.addEventListener('input', () => {
+ element.style.borderColor = var(--primary-color);
+ setTimeout(() => {
+ element.style.borderColor = '';
+ }, 500);
+ });
+ };
+
+ addTypingEffect(xmlInput);
+ });