import { ScraperUtils } from './scraper_utils.js'; class ScraperApp { constructor() { this.utils = new ScraperUtils(); this.form = document.getElementById('scrapingForm'); this.stopButton = document.getElementById('stopButton'); this.startButton = document.getElementById('startButton'); this.init(); } init() { this.utils.checkScrapingStatus(); this.addEventListeners(); } async startScraping(event) { event.preventDefault(); // Prevent default form submission const formData = new FormData(this.form); try { const response = await fetch('/start_scraping', { method: 'POST', body: formData }); const data = await response.json(); if (data.status === "Scraping started") { this.utils.checkScrapingStatus(); // Update UI } } catch (error) { console.error('Error starting scraping:', error); } } async stopScraping() { try { const response = await fetch('/stop_scraping', { method: 'POST' }); const data = await response.json(); if (data.status === "Scraping stopped") { this.utils.checkScrapingStatus(); // Update UI } } catch (error) { console.error('Error stopping scraping:', error); } } addEventListeners() { this.form.addEventListener('submit', (event) => this.startScraping(event)); this.stopButton.addEventListener('click', () => this.stopScraping()); } } document.addEventListener('DOMContentLoaded', () => { new ScraperApp(); });