Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ // Mobile menu toggle
+ const menuToggle = document.querySelector('.menu-toggle');
+ const navLinks = document.querySelector('.nav-links');
+
+ menuToggle.addEventListener('click', () => {
+ navLinks.classList.toggle('active');
+ });
+
+ // Scraping functionality
+ const urlInput = document.getElementById('urlInput');
+ const scrapeButton = document.getElementById('scrapeButton');
+ const exportButton = document.getElementById('exportButton');
+ const resultsTable = document.getElementById('resultsTable');
+ const loadingSpinner = document.querySelector('.loading-spinner');
+
+ scrapeButton.addEventListener('click', async () => {
+ const url = urlInput.value;
+ if (!url.includes('property24.com')) {
+ alert('Please enter a valid Property24 URL');
+ return;
+ }
+
+ // Show loading state
+ loadingSpinner.classList.remove('hidden');
+ scrapeButton.disabled = true;
+
+ try {
+ // Simulated scraping delay
+ await new Promise(resolve => setTimeout(resolve, 2000));
+
+ // Sample data (in real implementation, this would come from the server)
+ const sampleData = [
+ {id: 'P123', price: 'R2,500,000', location: 'Cape Town', bedrooms: '3', bathrooms: '2', area: '200m²'},
+ {id: 'P124', price: 'R1,800,000', location: 'Johannesburg', bedrooms: '2', bathrooms: '1', area: '150m²'}
+ ];
+
+ updateTable(sampleData);
+ exportButton.classList.remove('hidden');
+ } catch (error) {
+ alert('Error scraping data. Please try again.');
+ } finally {
+ loadingSpinner.classList.add('hidden');
+ scrapeButton.disabled = false;
+ }
+ });
+
+ function updateTable(data) {
+ const tbody = resultsTable.querySelector('tbody');
+ tbody.innerHTML = '';
+
+ data.forEach(item => {
+ const row = document.createElement('tr');
+ row.innerHTML = `
+
${item.id} | +
${item.price} | +
${item.location} | +
${item.bedrooms} | +
${item.bathrooms} | +
${item.area} | + `;
+ tbody.appendChild(row);
+ });
+ }
+
+ exportButton.addEventListener('click', () => {
+ // Convert table data to CSV
+ const rows = Array.from(resultsTable.querySelectorAll('tr'));
+ const csv = rows
+ .map(row => {
+ return Array.from(row.querySelectorAll('th,td'))
+ .map(cell => cell.textContent)
+ .join(',');
+ })
+ .join('\n');
+
+ // Create download link
+ const blob = new Blob([csv], { type: 'text/csv' });
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.setAttribute('href', url);
+ a.setAttribute('download', 'property_data.csv');
+ a.click();
+ window.URL.revokeObjectURL(url);
+ });
+ });