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');
+
+ function xmlToScroll(xml) {
+ // Remove XML declaration
+ xml = xml.replace(/<\?xml.*?\?>/, '');
+
+ // Convert self-closing tags
+ xml = xml.replace(/<([^\s>]+)([^>]*)\/>/g, '<$1$2>$1>');
+
+ // Convert attributes to Scroll format
+ xml = xml.replace(/<([^\s>]+)([^>]*)>/g, (match, tag, attrs) => {
+ const attributes = attrs.match(/(\w+)="([^"]*)"/g);
+ if (!attributes) return tag + '\n';
+
+ const scrollAttrs = attributes
+ .map(attr => {
+ const [key, value] = attr.split('=');
+ return `${key} ${value.replace(/"/g, '')}`;
+ })
+ .join('\n');
+
+ return `${tag}\n${scrollAttrs}\n`;
+ });
+
+ // Remove closing tags
+ xml = xml.replace(/<\/[^>]+>/g, '');
+
+ // Clean up whitespace
+ return xml.trim().split('\n').map(line => line.trim()).filter(Boolean).join('\n');
+ }
+
+ convertBtn.addEventListener('click', () => {
+ try {
+ const xml = xmlInput.value;
+ const scroll = xmlToScroll(xml);
+ scrollOutput.value = scroll;
+ } catch (error) {
+ scrollOutput.value = 'Error: Invalid XML format';
+ }
+ });
+
+ copyBtn.addEventListener('click', async () => {
+ try {
+ await navigator.clipboard.writeText(scrollOutput.value);
+ copyBtn.textContent = 'Copied!';
+ setTimeout(() => {
+ copyBtn.textContent = 'Copy';
+ }, 2000);
+ } catch (error) {
+ copyBtn.textContent = 'Failed to copy';
+ }
+ });
+ });