`, amazon: `Amazon Associates Example: `, ezoic: `Ezoic Example:
`, universal: `Universal Example (Any Ad Network): Paste any ad code from any network. The converter will automatically detect and process it.` }; this.adInput.placeholder = placeholders[this.selectedNetwork] || placeholders.universal; } validateInput() { const input = this.adInput.value.trim(); if (input.length > 0) { this.convertBtn.disabled = false; } else { this.convertBtn.disabled = true; } } convertCode() { const input = this.adInput.value.trim(); if (!input) { this.showStatus('⚠️ Please paste an ad code to convert', 'error'); return; } // Show loading state this.convertBtn.classList.add('loading'); this.convertBtn.innerHTML = '⏳ Converting...'; // Simulate processing delay setTimeout(() => { try { // Auto-detect network if not specified if (this.selectedNetwork === 'universal') { this.selectedNetwork = this.detectNetwork(input); } // Convert the code const convertedCode = this.convertToXml(input, this.selectedNetwork); // Display the result this.adOutput.value = convertedCode; this.outputSection.style.display = 'block'; this.adInput.classList.add('textarea-success'); // Show success message this.showStatus('✅ Ad code successfully converted to XML format!', 'success'); // Scroll to output this.adOutput.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } catch (error) { this.showStatus(`❌ Error converting ad code: ${error.message}`, 'error'); console.error(error); } finally { // Reset button state this.convertBtn.classList.remove('loading'); this.convertBtn.innerHTML = '🔄 Convert to XML'; } }, 500); } detectNetwork(code) { // Simple network detection based on code patterns if (code.includes('adsbygoogle') || code.includes('googlesyndication.com')) { return 'adsense'; } else if (code.includes('medianet') || code.includes('dmedianet.js')) { return 'medianet'; } else if (code.includes('propellerads') || code.includes('propellerclick.com')) { return 'propeller'; } else if (code.includes('taboola') || code.includes('taboola.com')) { return 'taboola'; } else if (code.includes('outbrain') || code.includes('outbrain.com')) { return 'outbrain'; } else if (code.includes('amzn_assoc') || code.includes('amazon-adsystem.com')) { return 'amazon'; } else if (code.includes('ezoic') || code.includes('ezojs.com')) { return 'ezoic'; } return 'universal'; } convertToXml(code, network) { // Network-specific conversion rules switch(network) { case 'adsense': return this.convertAdSense(code); case 'medianet': return this.convertMediaNet(code); case 'propeller': return this.convertPropellerAds(code); case 'taboola': return this.convertTaboola(code); case 'outbrain': return this.convertOutbrain(code); case 'amazon': return this.convertAmazon(code); case 'ezoic': return this.convertEzoic(code); default: return this.convertUniversal(code); } } convertAdSense(code) { // Special handling for AdSense let converted = code; // Replace script tags with CDATA sections converted = converted.replace(/'; }); // Ensure proper XML escaping converted = this.escapeXml(converted); return converted; } convertMediaNet(code) { // Special handling for Media.net let converted = code; // Handle their specific script patterns converted = converted.replace(/'; }); converted = this.escapeXml(converted); return converted; } convertPropellerAds(code) { // Special handling for PropellerAds let converted = code; // Wrap inline scripts in CDATA converted = converted.replace(/'; }); converted = this.escapeXml(converted); return converted; } convertTaboola(code) { // Special handling for Taboola let converted = code; // Handle their widget initialization converted = converted.replace(/'; }); converted = this.escapeXml(converted); return converted; } convertOutbrain(code) { // Special handling for Outbrain let converted = code; // Handle their widget initialization converted = converted.replace(/'; }); converted = this.escapeXml(converted); return converted; } convertAmazon(code) { // Special handling for Amazon Associates let converted = code; // Handle their configuration scripts converted = converted.replace(/'; }); converted = this.escapeXml(converted); return converted; } convertEzoic(code) { // Special handling for Ezoic let converted = code; // Handle their placement scripts converted = converted.replace(/'; }); converted = this.escapeXml(converted); return converted; } convertUniversal(code) { // Universal conversion for any ad code let converted = code; // Basic XML escaping converted = this.escapeXml(converted); // Try to handle scripts intelligently converted = converted.replace(/'; } }); return converted; } escapeXml(unsafe) { // Escape XML special characters return unsafe.replace(/[<>&'"]/g, function(c) { switch (c) { case '<': return '<'; case '>': return '>'; case '&': return '&'; case '\'': return '''; case '"': return '"'; default: return c; } }); } clearAll() { this.adInput.value = ''; this.adOutput.value = ''; this.outputSection.style.display = 'none'; this.adInput.classList.remove('textarea-success'); this.status.innerHTML = ''; // Reset network selection this.networkSelector.querySelectorAll('.network-button').forEach(btn => { btn.classList.remove('active'); }); this.networkSelector.querySelector('.network-button[data-network="universal"]').classList.add('active'); this.selectedNetwork = 'universal'; this.updatePlaceholder(); this.showStatus('🧹 All fields cleared. Ready for new conversion!', 'info'); } copyCode() { if (!this.adOutput.value) { this.showStatus('⚠️ No converted code to copy', 'error'); return; } this.adOutput.select(); document.execCommand('copy'); // Show notification this.copyNotification.classList.add('show'); setTimeout(() => { this.copyNotification.classList.remove('show'); }, 3000); this.showStatus('📋 XML code copied to clipboard!', 'success'); } highlightCode() { if (!this.adOutput.value) { this.showStatus('⚠️ No converted code to select', 'error'); return; } this.adOutput.select(); this.showStatus('🔍 All text selected - ready to copy!', 'info'); } showStatus(message, type) { this.status.innerHTML = ''; this.status.className = 'status'; const iconMap = { success: '✅', error: '❌', info: 'ℹ️' }; const statusDiv = document.createElement('div'); statusDiv.className = `status status-${type}`; statusDiv.innerHTML = `${iconMap[type] || 'ℹ️'} ${message}`; this.status.appendChild(statusDiv); } } // Initialize the converter when DOM is loaded document.addEventListener('DOMContentLoaded', () => { new UniversalAdConverter(); // Animate template items const templateItems = document.querySelectorAll('.template-item'); templateItems.forEach((item, index) => { setTimeout(() => { item.style.opacity = '1'; item.style.transform = 'translateY(0)'; }, 100 * index); }); });