refactoring

This commit is contained in:
2025-11-25 22:12:43 +01:00
parent de7bcf881a
commit e2a3d54198
12 changed files with 1458 additions and 2842 deletions

526
web/css/style.css Normal file
View File

@ -0,0 +1,526 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
height: 100vh;
overflow: hidden;
background: #1a1a1a;
color: #e0e0e0;
}
.container {
display: grid;
grid-template-columns: 380px 1fr;
grid-template-rows: auto 1fr;
height: calc(100vh - 60px);
}
.search-bar {
grid-column: 1 / -1;
background: #242424;
padding: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
display: grid;
grid-template-columns: 1fr auto auto auto auto;
gap: 12px;
align-items: end;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-size: 12px;
font-weight: 600;
color: #b0b0b0;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.search-bar input, .search-bar select {
padding: 12px;
border: 1px solid #3a3a3a;
border-radius: 6px;
font-size: 14px;
background: #2a2a2a;
color: #e0e0e0;
transition: all 0.2s;
}
.search-bar input:focus, .search-bar select:focus {
outline: none;
border-color: #0ea5e9;
box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
.price-inputs {
display: flex;
gap: 8px;
align-items: center;
}
.price-inputs input {
width: 120px;
}
.price-separator {
color: #666;
font-weight: 600;
padding: 0 4px;
}
.search-bar button {
padding: 12px 24px;
background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
font-size: 14px;
transition: all 0.2s;
box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}
.search-bar button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}
.search-bar button:disabled {
background: #3a3a3a;
cursor: not-allowed;
box-shadow: none;
}
.search-bar button.cancel {
background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}
.search-bar button.cancel:hover {
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}
.results-panel {
background: #1e1e1e;
overflow-y: auto;
border-right: 1px solid #2a2a2a;
}
.results-panel::-webkit-scrollbar {
width: 8px;
}
.results-panel::-webkit-scrollbar-track {
background: #1a1a1a;
}
.results-panel::-webkit-scrollbar-thumb {
background: #3a3a3a;
border-radius: 4px;
}
.results-panel::-webkit-scrollbar-thumb:hover {
background: #4a4a4a;
}
.results-header {
background: #242424;
padding: 20px;
border-bottom: 1px solid #2a2a2a;
position: sticky;
top: 0;
z-index: 10;
}
.results-count {
font-weight: 700;
color: #e0e0e0;
margin-bottom: 12px;
font-size: 16px;
}
.progress-info {
background: rgba(14, 165, 233, 0.1);
padding: 14px;
border-radius: 6px;
margin-bottom: 12px;
display: none;
border: 1px solid rgba(14, 165, 233, 0.2);
}
.progress-info.active {
display: block;
}
.progress-bar {
width: 100%;
height: 6px;
background: rgba(255, 255, 255, 0.1);
border-radius: 3px;
overflow: hidden;
margin-top: 10px;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #0ea5e9 0%, #06b6d4 100%);
width: 0%;
transition: width 0.3s;
box-shadow: 0 0 10px rgba(14, 165, 233, 0.5);
}
.progress-text {
font-size: 13px;
color: #0ea5e9;
margin-bottom: 6px;
font-weight: 600;
}
.eta-text {
font-size: 11px;
color: #888;
margin-top: 6px;
}
.sort-control {
display: flex;
gap: 8px;
align-items: center;
}
.sort-control label {
font-size: 12px;
color: #888;
font-weight: 600;
}
.sort-control select {
padding: 8px 12px;
border: 1px solid #3a3a3a;
border-radius: 6px;
font-size: 13px;
background: #2a2a2a;
color: #e0e0e0;
}
.result-item {
background: #242424;
margin: 12px;
border-radius: 8px;
overflow: hidden;
cursor: pointer;
transition: all 0.2s;
border: 1px solid #2a2a2a;
}
.result-item:hover {
border-color: #0ea5e9;
box-shadow: 0 4px 16px rgba(14, 165, 233, 0.2);
transform: translateY(-2px);
}
.result-item.selected {
border-color: #0ea5e9;
box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.3);
}
.result-image {
width: 100%;
height: 180px;
object-fit: cover;
background: #1a1a1a;
}
.result-content {
padding: 14px;
}
.result-title {
font-weight: 600;
color: #e0e0e0;
margin-bottom: 10px;
font-size: 14px;
line-height: 1.4;
}
.result-price {
color: #0ea5e9;
font-weight: 700;
font-size: 20px;
margin-bottom: 10px;
}
.result-meta {
display: flex;
justify-content: space-between;
font-size: 12px;
color: #888;
}
.result-location {
display: flex;
align-items: center;
gap: 4px;
}
.result-date {
font-style: italic;
}
.map-container {
position: relative;
height: 100%;
background: #1a1a1a;
}
#map {
width: 100%;
height: 100%;
filter: brightness(0.9) contrast(1.1);
}
.status-bar {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: #242424;
padding: 14px 24px;
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0,0,0,0.4);
z-index: 1000;
display: none;
border: 1px solid #3a3a3a;
}
.status-bar.visible {
display: block;
}
.status-bar.loading {
background: rgba(14, 165, 233, 0.2);
color: #0ea5e9;
border-color: rgba(14, 165, 233, 0.3);
}
.status-bar.success {
background: rgba(34, 197, 94, 0.2);
color: #22c55e;
border-color: rgba(34, 197, 94, 0.3);
}
.status-bar.error {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
border-color: rgba(239, 68, 68, 0.3);
}
.no-results {
text-align: center;
padding: 60px 20px;
color: #666;
font-size: 14px;
}
.loading-spinner {
display: inline-block;
width: 14px;
height: 14px;
border: 2px solid #0ea5e9;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.8s linear infinite;
margin-right: 10px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.footer {
background: #242424;
border-top: 1px solid #2a2a2a;
padding: 15px 20px;
height: 60px;
}
.footer-content {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 1400px;
margin: 0 auto;
}
.footer-links {
display: flex;
gap: 20px;
}
.footer-links a {
color: #888;
text-decoration: none;
font-size: 13px;
transition: color 0.2s;
}
.footer-links a:hover {
color: #0ea5e9;
}
.footer-info {
color: #666;
font-size: 12px;
}
.modal {
display: none;
position: fixed;
z-index: 10000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.8);
}
.modal.show {
display: block;
}
.modal-content {
background-color: #242424;
margin: 5% auto;
padding: 0;
border: 1px solid #3a3a3a;
border-radius: 8px;
width: 90%;
max-width: 800px;
max-height: 80vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
.modal-content h2 {
background: #2a2a2a;
padding: 20px;
margin: 0;
color: #e0e0e0;
border-bottom: 1px solid #3a3a3a;
}
.modal-body {
padding: 20px;
overflow-y: auto;
flex: 1;
}
.modal-body::-webkit-scrollbar {
width: 8px;
}
.modal-body::-webkit-scrollbar-track {
background: #1a1a1a;
}
.modal-body::-webkit-scrollbar-thumb {
background: #3a3a3a;
border-radius: 4px;
}
.modal-body h3 {
color: #0ea5e9;
margin-top: 20px;
margin-bottom: 10px;
font-size: 18px;
}
.modal-body h4 {
color: #888;
margin-top: 15px;
margin-bottom: 8px;
font-size: 14px;
}
.modal-body p {
margin-bottom: 10px;
line-height: 1.6;
color: #ccc;
}
.modal-body ul {
margin-left: 20px;
margin-bottom: 15px;
}
.modal-body li {
margin-bottom: 8px;
color: #ccc;
line-height: 1.6;
}
.modal-body a {
color: #0ea5e9;
text-decoration: none;
}
.modal-body a:hover {
text-decoration: underline;
}
.modal-close {
color: #888;
position: absolute;
right: 20px;
top: 20px;
font-size: 28px;
font-weight: bold;
cursor: pointer;
transition: color 0.2s;
}
.modal-close:hover,
.modal-close:focus {
color: #fff;
}
@media (max-width: 1024px) {
.container {
grid-template-columns: 320px 1fr;
}
.search-bar {
grid-template-columns: 1fr;
}
.price-inputs input {
width: 100px;
}
}
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
grid-template-rows: auto auto 1fr;
}
.results-panel {
max-height: 300px;
}
.footer-content {
flex-direction: column;
gap: 10px;
}
}

View File

@ -1,394 +1,22 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kleinanzeigen Karten-Suche</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
height: 100vh;
overflow: hidden;
background: #1a1a1a;
color: #e0e0e0;
}
.container {
display: grid;
grid-template-columns: 380px 1fr;
grid-template-rows: auto 1fr;
height: 100vh;
}
.search-bar {
grid-column: 1 / -1;
background: #242424;
padding: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
display: grid;
grid-template-columns: 1fr auto auto auto auto;
gap: 12px;
align-items: end;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-size: 12px;
font-weight: 600;
color: #b0b0b0;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.search-bar input, .search-bar select {
padding: 12px;
border: 1px solid #3a3a3a;
border-radius: 6px;
font-size: 14px;
background: #2a2a2a;
color: #e0e0e0;
transition: all 0.2s;
}
.search-bar input:focus, .search-bar select:focus {
outline: none;
border-color: #0ea5e9;
box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
.price-inputs {
display: flex;
gap: 8px;
align-items: center;
}
.price-inputs input {
width: 120px;
}
.price-separator {
color: #666;
font-weight: 600;
padding: 0 4px;
}
.search-bar button {
padding: 12px 24px;
background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
font-size: 14px;
transition: all 0.2s;
box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}
.search-bar button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}
.search-bar button:disabled {
background: #3a3a3a;
cursor: not-allowed;
box-shadow: none;
}
.search-bar button.cancel {
background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}
.search-bar button.cancel:hover {
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}
.results-panel {
background: #1e1e1e;
overflow-y: auto;
border-right: 1px solid #2a2a2a;
}
.results-panel::-webkit-scrollbar {
width: 8px;
}
.results-panel::-webkit-scrollbar-track {
background: #1a1a1a;
}
.results-panel::-webkit-scrollbar-thumb {
background: #3a3a3a;
border-radius: 4px;
}
.results-panel::-webkit-scrollbar-thumb:hover {
background: #4a4a4a;
}
.results-header {
background: #242424;
padding: 20px;
border-bottom: 1px solid #2a2a2a;
position: sticky;
top: 0;
z-index: 10;
}
.results-count {
font-weight: 700;
color: #e0e0e0;
margin-bottom: 12px;
font-size: 16px;
}
.progress-info {
background: rgba(14, 165, 233, 0.1);
padding: 14px;
border-radius: 6px;
margin-bottom: 12px;
display: none;
border: 1px solid rgba(14, 165, 233, 0.2);
}
.progress-info.active {
display: block;
}
.progress-bar {
width: 100%;
height: 6px;
background: rgba(255, 255, 255, 0.1);
border-radius: 3px;
overflow: hidden;
margin-top: 10px;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #0ea5e9 0%, #06b6d4 100%);
width: 0%;
transition: width 0.3s;
box-shadow: 0 0 10px rgba(14, 165, 233, 0.5);
}
.progress-text {
font-size: 13px;
color: #0ea5e9;
margin-bottom: 6px;
font-weight: 600;
}
.eta-text {
font-size: 11px;
color: #888;
margin-top: 6px;
}
.sort-control {
display: flex;
gap: 8px;
align-items: center;
}
.sort-control label {
font-size: 12px;
color: #888;
font-weight: 600;
}
.sort-control select {
padding: 8px 12px;
border: 1px solid #3a3a3a;
border-radius: 6px;
font-size: 13px;
background: #2a2a2a;
color: #e0e0e0;
}
.result-item {
background: #242424;
margin: 12px;
border-radius: 8px;
overflow: hidden;
cursor: pointer;
transition: all 0.2s;
border: 1px solid #2a2a2a;
}
.result-item:hover {
border-color: #0ea5e9;
box-shadow: 0 4px 16px rgba(14, 165, 233, 0.2);
transform: translateY(-2px);
}
.result-item.selected {
border-color: #0ea5e9;
box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.3);
}
.result-image {
width: 100%;
height: 180px;
object-fit: cover;
background: #1a1a1a;
}
.result-content {
padding: 14px;
}
.result-title {
font-weight: 600;
color: #e0e0e0;
margin-bottom: 10px;
font-size: 14px;
line-height: 1.4;
}
.result-price {
color: #0ea5e9;
font-weight: 700;
font-size: 20px;
margin-bottom: 10px;
}
.result-meta {
display: flex;
justify-content: space-between;
font-size: 12px;
color: #888;
}
.result-location {
display: flex;
align-items: center;
gap: 4px;
}
.result-date {
font-style: italic;
}
.map-container {
position: relative;
height: 100%;
background: #1a1a1a;
}
#map {
width: 100%;
height: 100%;
filter: brightness(0.9) contrast(1.1);
}
.status-bar {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: #242424;
padding: 14px 24px;
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0,0,0,0.4);
z-index: 1000;
display: none;
border: 1px solid #3a3a3a;
}
.status-bar.visible {
display: block;
}
.status-bar.loading {
background: rgba(14, 165, 233, 0.2);
color: #0ea5e9;
border-color: rgba(14, 165, 233, 0.3);
}
.status-bar.success {
background: rgba(34, 197, 94, 0.2);
color: #22c55e;
border-color: rgba(34, 197, 94, 0.3);
}
.status-bar.error {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
border-color: rgba(239, 68, 68, 0.3);
}
.no-results {
text-align: center;
padding: 60px 20px;
color: #666;
font-size: 14px;
}
.loading-spinner {
display: inline-block;
width: 14px;
height: 14px;
border: 2px solid #0ea5e9;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.8s linear infinite;
margin-right: 10px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 1024px) {
.container {
grid-template-columns: 320px 1fr;
}
.search-bar {
grid-template-columns: 1fr;
}
.price-inputs input {
width: 100px;
}
}
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
grid-template-rows: auto auto 1fr;
}
.results-panel {
max-height: 300px;
}
}
</style>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div class="container">
<div class="search-bar">
<div class="form-group">
<label>Suchbegriff</label>
<input type="text" id="searchTerm" placeholder="z.B. Fahrrad" value="Fahrrad">
<input type="text" id="searchTerm" placeholder="z.B. Gravelbike">
</div>
<div class="form-group">
<label>Preisspanne</label>
<div class="price-inputs">
@ -397,7 +25,7 @@
<input type="number" id="maxPrice" placeholder="∞ €" value="" min="0" max="1000000000">
</div>
</div>
<div class="form-group">
<label>Anzahl Inserate</label>
<select id="numListings">
@ -407,7 +35,7 @@
<option value="250">250 Inserate</option>
</select>
</div>
<button id="searchBtn">Suchen</button>
<button id="cancelBtn" class="cancel" style="display: none;">Abbrechen</button>
</div>
@ -415,7 +43,7 @@
<div class="results-panel">
<div class="results-header">
<div class="results-count">Keine Ergebnisse</div>
<div id="progressInfo" class="progress-info">
<div class="progress-text">Inserate werden geladen...</div>
<div class="progress-bar">
@ -443,410 +71,94 @@
</div>
</div>
<script>
const API_BASE_URL = 'http://localhost:5000';
let map;
let markers = [];
let allListings = [];
let selectedListingId = null;
let currentSessionId = null;
let scrapeStartTime = null;
let isScrapingActive = false;
<footer class="footer">
<div class="footer-content">
<div class="footer-links">
<a href="https://www.mosad.xyz/html/privacy.html" target="_blank">Impressum</a>
<a href="#" id="privacyLink">Datenschutz</a>
<a href="https://git.mosad.xyz/localhorst/kleinanzeigen-boosted" target="_blank">Source Code</a>
</div>
<div class="footer-info">
kleinanzeigen.mosad.xyz © 2025
</div>
</div>
</footer>
// Initialize map
function initMap() {
map = L.map('map').setView([51.1657, 10.4515], 6);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
maxZoom: 19
}).addTo(map);
<div id="privacyModal" class="modal">
<div class="modal-content">
<span class="modal-close">&times;</span>
<h2>Datenschutzerklärung</h2>
<div class="modal-body">
<h3>1. Verantwortlicher</h3>
<p>Siehe <a href="https://www.mosad.xyz/html/privacy.html" target="_blank">Impressum</a></p>
// Try to get user's location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
// Add user location marker
const userIcon = L.divIcon({
html: '<div style="width: 16px; height: 16px; background: #0ea5e9; border: 3px solid white; border-radius: 50%; box-shadow: 0 0 10px rgba(14, 165, 233, 0.6);"></div>',
className: '',
iconSize: [16, 16],
iconAnchor: [8, 8]
});
L.marker([lat, lon], { icon: userIcon })
.addTo(map)
.bindPopup('<div style="background: #1a1a1a; color: #e0e0e0; padding: 8px;"><strong>Dein Standort</strong></div>');
console.log('User location:', lat, lon);
},
(error) => {
console.log('Geolocation error:', error.message);
}
);
}
}
<h3>2. Datenverarbeitung</h3>
<p>Diese Anwendung verarbeitet folgende Daten:</p>
<ul>
<li><strong>Suchanfragen:</strong> Ihre Suchbegriffe und Filter werden temporär auf dem Server
verarbeitet, um Ergebnisse von Kleinanzeigen.de abzurufen.</li>
<li><strong>Standortdaten:</strong> Wenn Sie die Standortfreigabe in Ihrem Browser erlauben, wird
Ihre Position verwendet, um sie auf der Karte anzuzeigen. Diese Daten werden nicht gespeichert
oder übertragen.</li>
<li><strong>Technische Daten:</strong> IP-Adresse und Zeitstempel werden in Server-Logs zu
Debugging-Zwecken gespeichert.</li>
</ul>
// Show status message
function showStatus(message, type = 'loading') {
const statusBar = document.getElementById('statusBar');
statusBar.className = `status-bar visible ${type}`;
if (type === 'loading') {
statusBar.innerHTML = `<span class="loading-spinner"></span>${message}`;
} else {
statusBar.textContent = message;
}
<h3>3. Externe Dienste</h3>
<p>Diese Anwendung nutzt folgende externe Dienste:</p>
if (type !== 'loading') {
setTimeout(() => {
statusBar.classList.remove('visible');
}, 3000);
}
}
<h4>3.1 Kleinanzeigen.de</h4>
<p>Die Anwendung ruft öffentlich verfügbare Inserate von kleinanzeigen.de ab. Es gelten die
Datenschutzbestimmungen von <a href="https://www.kleinanzeigen.de/datenschutzerklaerung/"
target="_blank">Kleinanzeigen.de</a>.</p>
// Update progress
function updateProgress(current, total) {
const progressInfo = document.getElementById('progressInfo');
const progressFill = progressInfo.querySelector('.progress-fill');
const progressText = progressInfo.querySelector('.progress-text');
const etaText = progressInfo.querySelector('.eta-text');
if (total === 0) {
progressInfo.classList.remove('active');
return;
}
progressInfo.classList.add('active');
const percentage = (current / total) * 100;
progressFill.style.width = percentage + '%';
progressText.textContent = `Inserate werden geladen: ${current}/${total}`;
// Calculate ETA
if (scrapeStartTime && current > 0) {
const elapsed = (Date.now() - scrapeStartTime) / 1000;
const avgTimePerListing = elapsed / current;
const remaining = total - current;
const etaSeconds = Math.round(avgTimePerListing * remaining);
const minutes = Math.floor(etaSeconds / 60);
const seconds = etaSeconds % 60;
if (minutes > 0) {
etaText.textContent = `Noch ca. ${minutes}m ${seconds}s`;
} else {
etaText.textContent = `Noch ca. ${seconds}s`;
}
}
}
<h4>3.2 OpenStreetMap (Leaflet.js v1.9.4)</h4>
<p>Für die Kartendarstellung wird Leaflet.js verwendet. Kartenkacheln werden von CARTO und OpenStreetMap
bereitgestellt. Beim Laden der Karte werden Anfragen an diese Server gesendet, die Ihre IP-Adresse
enthalten können.</p>
<ul>
<li>OpenStreetMap Datenschutz: <a href="https://wiki.osmfoundation.org/wiki/Privacy_Policy"
target="_blank">Privacy Policy</a></li>
<li>CARTO Datenschutz: <a href="https://carto.com/privacy/" target="_blank">Privacy Policy</a></li>
</ul>
// Clear all markers from map
function clearMarkers() {
markers.forEach(marker => map.removeLayer(marker));
markers = [];
}
<h4>3.3 Nominatim Geocoding API</h4>
<p>Postleitzahlen werden über die Nominatim-API von OpenStreetMap in Koordinaten umgewandelt. Die
Anfragen werden zwischengespeichert, um die Anzahl der API-Aufrufe zu minimieren.</p>
<ul>
<li>Nominatim Nutzungsbedingungen: <a
href="https://operations.osmfoundation.org/policies/nominatim/" target="_blank">Usage
Policy</a></li>
</ul>
// Add marker to map
function addMarker(listing) {
if (!listing.lat || !listing.lon) return;
<h4>3.4 CDN-Dienste (cdnjs.cloudflare.com)</h4>
<p>JavaScript- und CSS-Bibliotheken werden über Cloudflare CDN geladen. Cloudflare kann dabei Ihre
IP-Adresse verarbeiten.</p>
<ul>
<li>Cloudflare Datenschutz: <a href="https://www.cloudflare.com/privacypolicy/"
target="_blank">Privacy Policy</a></li>
</ul>
const marker = L.marker([listing.lat, listing.lon]).addTo(map);
const imageHtml = listing.image
? `<img src="${listing.image}" style="width: 100%; max-height: 150px; object-fit: cover; margin: 8px 0;" alt="${listing.title}">`
: '';
const popupContent = `
<div style="min-width: 200px; 8px;">
<strong style="font-size: 14px;">${listing.title}</strong><br>
${imageHtml}
<span style="color: #0066cc; font-weight: bold; font-size: 16px;">${listing.price} €</span><br>
<span style="color: #666; font-size: 12px;">${listing.address}</span><br>
<a href="${listing.url}" target="_blank" style="color: #0066cc; text-decoration: none; font-weight: 600;">Link öffnen →</a>
</div>
`;
marker.bindPopup(popupContent);
marker.on('click', () => {
selectedListingId = listing.id;
highlightSelectedListing();
});
<h3>4. Browser-Speicher</h3>
<p>Diese Anwendung nutzt <strong>keine</strong> Cookies, localStorage oder sessionStorage. Alle Daten
werden nur während der aktiven Sitzung im Arbeitsspeicher gehalten.</p>
markers.push(marker);
}
<h3>5. Kontakt</h3>
<p>Bei Fragen zum Datenschutz wenden Sie sich bitte an die im <a
href="https://www.mosad.xyz/html/privacy.html" target="_blank">Impressum</a> angegebenen
Kontaktdaten.</p>
// Highlight selected listing in results list
function highlightSelectedListing() {
document.querySelectorAll('.result-item').forEach(item => {
const itemId = parseInt(item.dataset.id);
if (itemId === selectedListingId) {
item.classList.add('selected');
item.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
} else {
item.classList.remove('selected');
}
});
}
<p><small>Stand: November 2025</small></p>
</div>
</div>
</div>
// Format date
function formatDate(dateString) {
if (!dateString) return 'Unbekanntes Datum';
const date = new Date(dateString);
return date.toLocaleDateString('de-DE');
}
// Render results list
function renderResults(listings) {
const resultsList = document.getElementById('resultsList');
const resultsCount = document.querySelector('.results-count');
if (listings.length === 0) {
resultsList.innerHTML = '<div class="no-results">Keine Inserate gefunden</div>';
resultsCount.textContent = 'Keine Ergebnisse';
return;
}
resultsCount.textContent = `${listings.length} Inserat${listings.length !== 1 ? 'e' : ''}`;
resultsList.innerHTML = listings.map(listing => `
<div class="result-item" data-id="${listing.id}">
${listing.image ? `<img src="${listing.image}" class="result-image" alt="${listing.title}">` : '<div class="result-image"></div>'}
<div class="result-content">
<div class="result-title">${listing.title}</div>
<div class="result-price">${listing.price} €</div>
<div class="result-meta">
<div class="result-location">
<span>📍</span>
<span>${listing.address || listing.zip_code}</span>
</div>
<div class="result-date">${formatDate(listing.date_added)}</div>
</div>
</div>
</div>
`).join('');
// Add click handlers
document.querySelectorAll('.result-item').forEach(item => {
item.addEventListener('click', () => {
const id = parseInt(item.dataset.id);
const listing = listings.find(l => l.id === id);
if (listing) {
selectedListingId = id;
highlightSelectedListing();
if (listing.lat && listing.lon) {
map.setView([listing.lat, listing.lon], 13);
const marker = markers.find(m =>
m.getLatLng().lat === listing.lat &&
m.getLatLng().lng === listing.lon
);
if (marker) {
marker.openPopup();
}
}
window.open(listing.url, '_blank');
}
});
});
}
// Sort listings
function sortListings(listings, sortBy) {
const sorted = [...listings];
switch(sortBy) {
case 'price-asc':
sorted.sort((a, b) => a.price - b.price);
break;
case 'price-desc':
sorted.sort((a, b) => b.price - a.price);
break;
case 'date-asc':
sorted.sort((a, b) => new Date(a.date_added || 0) - new Date(b.date_added || 0));
break;
case 'date-desc':
sorted.sort((a, b) => new Date(b.date_added || 0) - new Date(a.date_added || 0));
break;
}
return sorted;
}
// Scrape next listing
async function scrapeNextListing() {
if (!currentSessionId || !isScrapingActive) {
console.log('Scraping stopped: session or active flag cleared');
return false;
}
try {
const response = await fetch(`${API_BASE_URL}/api/scrape/${currentSessionId}`);
const data = await response.json();
if (data.cancelled) {
console.log('Scraping cancelled by backend');
return false;
}
if (data.listing) {
allListings.push(data.listing);
addMarker(data.listing);
// Update display
const sortBy = document.getElementById('sortSelect').value;
const sortedListings = sortListings(allListings, sortBy);
renderResults(sortedListings);
// Fit map to markers
if (markers.length > 0) {
const group = L.featureGroup(markers);
map.fitBounds(group.getBounds().pad(0.1));
}
}
updateProgress(data.progress.current, data.progress.total);
if (data.complete) {
console.log('Scraping complete, finalizing...');
isScrapingActive = false;
document.getElementById('searchBtn').disabled = false;
document.getElementById('cancelBtn').style.display = 'none';
updateProgress(0, 0);
showStatus(`Fertig! ${allListings.length} Inserate geladen`, 'success');
console.log('Final listings count:', allListings.length);
return false;
}
return true;
} catch (error) {
console.error('Scrape error:', error);
isScrapingActive = false;
document.getElementById('searchBtn').disabled = false;
document.getElementById('cancelBtn').style.display = 'none';
showStatus('Fehler beim Laden der Inserate', 'error');
return false;
}
}
// Start scraping loop
async function startScrapingLoop() {
while (isScrapingActive && currentSessionId) {
const shouldContinue = await scrapeNextListing();
if (!shouldContinue) {
break;
}
await new Promise(resolve => setTimeout(resolve, 100));
}
}
// Search listings
async function searchListings() {
const searchTerm = document.getElementById('searchTerm').value.trim();
const minPrice = parseInt(document.getElementById('minPrice').value) || 0;
const maxPriceInput = document.getElementById('maxPrice').value;
const maxPrice = maxPriceInput ? parseInt(maxPriceInput) : 1000000000;
const numListings = parseInt(document.getElementById('numListings').value) || 25;
if (!searchTerm) {
showStatus('Bitte Suchbegriff eingeben', 'error');
return;
}
document.getElementById('searchBtn').disabled = true;
clearMarkers();
allListings = [];
selectedListingId = null;
document.getElementById('resultsList').innerHTML = '';
showStatus('Suche nach Inseraten...', 'loading');
try {
const response = await fetch(`${API_BASE_URL}/api/search`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
search_term: searchTerm,
min_price: minPrice,
max_price: maxPrice,
num_listings: numListings
})
});
if (!response.ok) {
throw new Error('API request failed');
}
const data = await response.json();
currentSessionId = data.session_id;
if (data.total === 0) {
showStatus('Keine Inserate gefunden', 'error');
document.getElementById('searchBtn').disabled = false;
return;
}
showStatus(`${data.total} Inserate gefunden. Lade Details...`, 'success');
// Show cancel button
document.getElementById('cancelBtn').style.display = 'inline-block';
// Start scraping
isScrapingActive = true;
scrapeStartTime = Date.now();
updateProgress(0, data.total);
startScrapingLoop();
} catch (error) {
console.error('Search error:', error);
showStatus('Fehler: Verbindung zum Server fehlgeschlagen', 'error');
document.getElementById('searchBtn').disabled = false;
}
}
// Cancel scraping
async function cancelScraping() {
if (!currentSessionId) return;
try {
await fetch(`${API_BASE_URL}/api/scrape/${currentSessionId}/cancel`, {
method: 'POST'
});
isScrapingActive = false;
document.getElementById('searchBtn').disabled = false;
document.getElementById('cancelBtn').style.display = 'none';
updateProgress(0, 0);
showStatus(`Abgebrochen. ${allListings.length} Inserate geladen`, 'error');
} catch (error) {
console.error('Cancel error:', error);
}
}
// Event listeners
document.getElementById('searchBtn').addEventListener('click', searchListings);
document.getElementById('cancelBtn').addEventListener('click', cancelScraping);
document.getElementById('searchTerm').addEventListener('keypress', (e) => {
if (e.key === 'Enter') searchListings();
});
document.getElementById('sortSelect').addEventListener('change', (e) => {
if (allListings.length > 0) {
const sortedListings = sortListings(allListings, e.target.value);
renderResults(sortedListings);
}
});
// Initialize
initMap();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.js"></script>
<script src="./js/config.js"></script>
<script src="./js/map.js"></script>
<script src="./js/ui.js"></script>
<script src="./js/api.js"></script>
<script src="./js/app.js"></script>
</body>
</html>

151
web/js/api.js Normal file
View File

@ -0,0 +1,151 @@
// API communication functions
async function scrapeNextListing() {
if (!AppState.currentSessionId || !AppState.isScrapingActive) {
console.log('Scraping stopped: session or active flag cleared');
return false;
}
try {
const response = await fetch(`${API_BASE_URL}/api/scrape/${AppState.currentSessionId}`);
const data = await response.json();
if (data.cancelled) {
console.log('Scraping cancelled by backend');
return false;
}
if (data.listing) {
AppState.allListings.push(data.listing);
addMarker(data.listing);
// Update display
const sortBy = document.getElementById('sortSelect').value;
const sortedListings = sortListings(AppState.allListings, sortBy);
renderResults(sortedListings);
// Fit map to markers
if (AppState.markers.length > 0) {
const group = L.featureGroup(AppState.markers);
AppState.map.fitBounds(group.getBounds().pad(0.1));
}
}
updateProgress(data.progress.current, data.progress.total);
if (data.complete) {
console.log('Scraping complete, finalizing...');
AppState.isScrapingActive = false;
document.getElementById('searchBtn').disabled = false;
document.getElementById('cancelBtn').style.display = 'none';
updateProgress(0, 0);
showStatus(`Fertig! ${AppState.allListings.length} Inserate geladen`, 'success');
console.log('Final listings count:', AppState.allListings.length);
return false;
}
return true;
} catch (error) {
console.error('Scrape error:', error);
AppState.isScrapingActive = false;
document.getElementById('searchBtn').disabled = false;
document.getElementById('cancelBtn').style.display = 'none';
showStatus('Fehler beim Laden der Inserate', 'error');
return false;
}
}
async function startScrapingLoop() {
while (AppState.isScrapingActive && AppState.currentSessionId) {
const shouldContinue = await scrapeNextListing();
if (!shouldContinue) {
break;
}
await new Promise(resolve => setTimeout(resolve, 100));
}
}
async function searchListings() {
const searchTerm = document.getElementById('searchTerm').value.trim();
const minPrice = parseInt(document.getElementById('minPrice').value) || 0;
const maxPriceInput = document.getElementById('maxPrice').value;
const maxPrice = maxPriceInput ? parseInt(maxPriceInput) : 1000000000;
const numListings = parseInt(document.getElementById('numListings').value) || 25;
if (!searchTerm) {
showStatus('Bitte Suchbegriff eingeben', 'error');
return;
}
document.getElementById('searchBtn').disabled = true;
clearMarkers();
AppState.allListings = [];
AppState.selectedListingId = null;
document.getElementById('resultsList').innerHTML = '';
showStatus('Suche nach Inseraten...', 'loading');
try {
const response = await fetch(`${API_BASE_URL}/api/search`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
search_term: searchTerm,
min_price: minPrice,
max_price: maxPrice,
num_listings: numListings
})
});
if (!response.ok) {
throw new Error('API request failed');
}
const data = await response.json();
AppState.currentSessionId = data.session_id;
if (data.total === 0) {
showStatus('Keine Inserate gefunden', 'error');
document.getElementById('searchBtn').disabled = false;
return;
}
showStatus(`${data.total} Inserate gefunden. Lade Details...`, 'success');
// Show cancel button
document.getElementById('cancelBtn').style.display = 'inline-block';
// Start scraping
AppState.isScrapingActive = true;
AppState.scrapeStartTime = Date.now();
updateProgress(0, data.total);
startScrapingLoop();
} catch (error) {
console.error('Search error:', error);
showStatus('Fehler: Verbindung zum Server fehlgeschlagen', 'error');
document.getElementById('searchBtn').disabled = false;
}
}
async function cancelScraping() {
if (!AppState.currentSessionId) return;
try {
await fetch(`${API_BASE_URL}/api/scrape/${AppState.currentSessionId}/cancel`, {
method: 'POST'
});
AppState.isScrapingActive = false;
document.getElementById('searchBtn').disabled = false;
document.getElementById('cancelBtn').style.display = 'none';
updateProgress(0, 0);
showStatus(`Abgebrochen. ${AppState.allListings.length} Inserate geladen`, 'error');
} catch (error) {
console.error('Cancel error:', error);
}
}

24
web/js/app.js Normal file
View File

@ -0,0 +1,24 @@
// Main application initialization and event handlers
// Event listeners
document.getElementById('searchBtn').addEventListener('click', searchListings);
document.getElementById('cancelBtn').addEventListener('click', cancelScraping);
document.getElementById('searchTerm').addEventListener('keypress', (e) => {
if (e.key === 'Enter') searchListings();
});
document.getElementById('sortSelect').addEventListener('change', (e) => {
if (AppState.allListings.length > 0) {
const sortedListings = sortListings(AppState.allListings, e.target.value);
renderResults(sortedListings);
}
});
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
initMap();
initPrivacyModal();
console.log('Kleinanzeigen Karten-Suche initialized');
console.log('API Base URL:', API_BASE_URL);
});

15
web/js/config.js Normal file
View File

@ -0,0 +1,15 @@
// Auto-detect API base URL from current domain
const API_BASE_URL = window.location.protocol + '//' + window.location.host;
//const API_BASE_URL = 'http://localhost:5000'; //used for development
// Application state
const AppState = {
map: null,
markers: [],
allListings: [],
selectedListingId: null,
currentSessionId: null,
scrapeStartTime: null,
isScrapingActive: false
};

70
web/js/map.js Normal file
View File

@ -0,0 +1,70 @@
// Map initialization and marker management
function initMap() {
AppState.map = L.map('map').setView([51.1657, 10.4515], 6);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
maxZoom: 19,
}).addTo(AppState.map);
// Try to get user's location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
// Add user location marker
const userIcon = L.divIcon({
html: '<div style="width: 16px; height: 16px; background: #0ea5e9; border: 3px solid white; border-radius: 50%; box-shadow: 0 0 10px rgba(14, 165, 233, 0.6);"></div>',
className: '',
iconSize: [16, 16],
iconAnchor: [8, 8]
});
L.marker([lat, lon], { icon: userIcon })
.addTo(AppState.map)
.bindPopup('<div style="background: #1a1a1a; color: #e0e0e0; padding: 8px;"><strong>Dein Standort</strong></div>');
console.log('User location:', lat, lon);
},
(error) => {
console.log('Geolocation error:', error.message);
}
);
}
}
function clearMarkers() {
AppState.markers.forEach(marker => AppState.map.removeLayer(marker));
AppState.markers = [];
}
function addMarker(listing) {
if (!listing.lat || !listing.lon) return;
const marker = L.marker([listing.lat, listing.lon]).addTo(AppState.map);
const imageHtml = listing.image
? `<img src="${listing.image}" style="width: 100%; max-height: 150px; object-fit: cover; margin: 8px 0;" alt="${listing.title}">`
: '';
const popupContent = `
<div style="min-width: 200px; 8px;">
<strong style="font-size: 14px;">${listing.title}</strong><br>
${imageHtml}
<span style="color: #0066cc; font-weight: bold; font-size: 16px;">${listing.price} €</span><br>
<span style="color: #666; font-size: 12px;">${listing.address}</span><br>
<a href="${listing.url}" target="_blank" style="color: #0066cc; text-decoration: none; font-weight: 600;">Link öffnen →</a>
</div>
`;
marker.bindPopup(popupContent);
marker.on('click', () => {
AppState.selectedListingId = listing.id;
highlightSelectedListing();
});
AppState.markers.push(marker);
}

168
web/js/ui.js Normal file
View File

@ -0,0 +1,168 @@
// UI management functions
function showStatus(message, type = 'loading') {
const statusBar = document.getElementById('statusBar');
statusBar.className = `status-bar visible ${type}`;
if (type === 'loading') {
statusBar.innerHTML = `<span class="loading-spinner"></span>${message}`;
} else {
statusBar.textContent = message;
}
if (type !== 'loading') {
setTimeout(() => {
statusBar.classList.remove('visible');
}, 3000);
}
}
function updateProgress(current, total) {
const progressInfo = document.getElementById('progressInfo');
const progressFill = progressInfo.querySelector('.progress-fill');
const progressText = progressInfo.querySelector('.progress-text');
const etaText = progressInfo.querySelector('.eta-text');
if (total === 0) {
progressInfo.classList.remove('active');
return;
}
progressInfo.classList.add('active');
const percentage = (current / total) * 100;
progressFill.style.width = percentage + '%';
progressText.textContent = `Inserate werden geladen: ${current}/${total}`;
// Calculate ETA
if (AppState.scrapeStartTime && current > 0) {
const elapsed = (Date.now() - AppState.scrapeStartTime) / 1000;
const avgTimePerListing = elapsed / current;
const remaining = total - current;
const etaSeconds = Math.round(avgTimePerListing * remaining);
const minutes = Math.floor(etaSeconds / 60);
const seconds = etaSeconds % 60;
if (minutes > 0) {
etaText.textContent = `Noch ca. ${minutes}m ${seconds}s`;
} else {
etaText.textContent = `Noch ca. ${seconds}s`;
}
}
}
function highlightSelectedListing() {
document.querySelectorAll('.result-item').forEach(item => {
const itemId = parseInt(item.dataset.id);
if (itemId === AppState.selectedListingId) {
item.classList.add('selected');
item.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
} else {
item.classList.remove('selected');
}
});
}
function formatDate(dateString) {
if (!dateString) return 'Unbekanntes Datum';
const date = new Date(dateString);
return date.toLocaleDateString('de-DE');
}
function renderResults(listings) {
const resultsList = document.getElementById('resultsList');
const resultsCount = document.querySelector('.results-count');
if (listings.length === 0) {
resultsList.innerHTML = '<div class="no-results">Keine Inserate gefunden</div>';
resultsCount.textContent = 'Keine Ergebnisse';
return;
}
resultsCount.textContent = `${listings.length} Inserat${listings.length !== 1 ? 'e' : ''}`;
resultsList.innerHTML = listings.map(listing => `
<div class="result-item" data-id="${listing.id}">
${listing.image ? `<img src="${listing.image}" class="result-image" alt="${listing.title}">` : '<div class="result-image"></div>'}
<div class="result-content">
<div class="result-title">${listing.title}</div>
<div class="result-price">${listing.price} €</div>
<div class="result-meta">
<div class="result-location">
<span>📍</span>
<span>${listing.address || listing.zip_code}</span>
</div>
<div class="result-date">${formatDate(listing.date_added)}</div>
</div>
</div>
</div>
`).join('');
// Add click handlers
document.querySelectorAll('.result-item').forEach(item => {
item.addEventListener('click', () => {
const id = parseInt(item.dataset.id);
const listing = listings.find(l => l.id === id);
if (listing) {
AppState.selectedListingId = id;
highlightSelectedListing();
if (listing.lat && listing.lon) {
AppState.map.setView([listing.lat, listing.lon], 13);
const marker = AppState.markers.find(m =>
m.getLatLng().lat === listing.lat &&
m.getLatLng().lng === listing.lon
);
if (marker) {
marker.openPopup();
}
}
window.open(listing.url, '_blank');
}
});
});
}
function sortListings(listings, sortBy) {
const sorted = [...listings];
switch (sortBy) {
case 'price-asc':
sorted.sort((a, b) => a.price - b.price);
break;
case 'price-desc':
sorted.sort((a, b) => b.price - a.price);
break;
case 'date-asc':
sorted.sort((a, b) => new Date(a.date_added || 0) - new Date(b.date_added || 0));
break;
case 'date-desc':
sorted.sort((a, b) => new Date(b.date_added || 0) - new Date(a.date_added || 0));
break;
}
return sorted;
}
// Privacy modal
function initPrivacyModal() {
const modal = document.getElementById('privacyModal');
const link = document.getElementById('privacyLink');
const close = document.querySelector('.modal-close');
link.addEventListener('click', (e) => {
e.preventDefault();
modal.classList.add('show');
});
close.addEventListener('click', () => {
modal.classList.remove('show');
});
window.addEventListener('click', (e) => {
if (e.target === modal) {
modal.classList.remove('show');
}
});
}