Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Extrahiert alle relevanten Elemente auf der Seite, die Einzelpreise enthalten
- const itemElements = Array.from(document.querySelectorAll('.order-item-content-info-number'));
- // Berechnet den Gesamtpreis und die Anzahl der Artikel (Einzelpreise * Menge) und die Anzahl der Positionen
- const itemResult = itemElements.reduce((acc, element) => {
- // Extrahiere das div-Element, das die Preiszahlen enthält
- const priceContainer = element.querySelector('.es--wrap--2p8eS4Q');
- if (priceContainer) {
- // Extrahiere alle relevanten Zeichen in den verschachtelten span-Tags und setze sie zu einem String zusammen
- const priceString = Array.from(priceContainer.querySelectorAll('.es--char--1Qcd3D7'))
- .map(span => span.innerText || span.textContent)
- .join('');
- // Ersetze das Komma durch einen Punkt, damit parseFloat funktioniert
- const price = parseFloat(priceString.replace(',', '.'));
- // Extrahiere die Menge des Artikels
- const quantityElement = element.querySelector('.order-item-content-info-number-quantity');
- let quantity = 1; // Standardmenge falls nichts gefunden
- if (quantityElement) {
- // Extrahiere die Menge aus dem Text, z.B. "x1"
- const quantityMatch = quantityElement.innerText.match(/x(\d+)/);
- if (quantityMatch) {
- quantity = parseInt(quantityMatch[1], 10);
- }
- }
- // Falls der Preis erfolgreich extrahiert wurde, addiere ihn zum Gesamtpreis und erhöhe die Artikelanzahl
- if (!isNaN(price)) {
- acc.totalPrice += price * quantity; // Gesamtpreis addieren (Preis * Anzahl)
- acc.totalItems += quantity; // Gesamtanzahl der Artikel addieren
- acc.totalPositions += 1; // Artikelposition erhöhen
- }
- }
- return acc;
- }, { totalPrice: 0, totalItems: 0, totalPositions: 0 });
- // Extrahiert alle Gesamtpreise inkl. Versandkosten
- const totalElements = Array.from(document.querySelectorAll('.order-item-content-opt-price-total .es--wrap--2p8eS4Q'));
- // Berechnet die Summe aller Gesamtpreise inkl. Versandkosten
- let totalOrderPrice = totalElements.reduce((total, element) => {
- // Extrahiere alle relevanten Zeichen in den verschachtelten span-Tags und setze sie zu einem String zusammen
- const totalPriceString = Array.from(element.querySelectorAll('.es--char--1Qcd3D7'))
- .map(span => span.innerText || span.textContent)
- .join('');
- // Ersetze das Komma durch einen Punkt, damit parseFloat funktioniert
- const price = parseFloat(totalPriceString.replace(',', '.'));
- // Falls der Preis erfolgreich extrahiert wurde, addiere ihn zur Gesamtsumme
- if (!isNaN(price)) {
- total += price;
- }
- return total;
- }, 0);
- // Berechnet die Summe der Versandkosten
- const shippingCosts = totalOrderPrice - itemResult.totalPrice;
- // Extrahiert alle Elemente mit Bestelldatum
- const dateElements = Array.from(document.querySelectorAll('.order-item-header-right-info'));
- // Findet das früheste Bestelldatum
- let earliestDate = null;
- dateElements.forEach(element => {
- // Suchen nach dem Div, das das Bestelldatum enthält
- const dateContainer = element.querySelector('div[data-spm-anchor-id]');
- if (dateContainer) {
- // Extrahiere das Bestelldatum als String, z.B. "Bestellung aufgegeben am: 27. Sep 2015"
- const dateText = dateContainer.innerText || dateContainer.textContent;
- // Extrahiere das tatsächliche Datum mithilfe eines regulären Ausdrucks
- const dateMatch = dateText.match(/am: (\d{1,2}\.?\s?\w+\s\d{4})/);
- if (dateMatch) {
- const dateString = dateMatch[1];
- const currentDate = new Date(dateString);
- // Setze das früheste Datum, falls es noch nicht gesetzt wurde, oder falls das aktuelle Datum früher ist
- if (!earliestDate || currentDate < earliestDate) {
- earliestDate = currentDate;
- }
- }
- }
- });
- // Zeige die fünf gewünschten Ergebnisse in der Konsole
- console.log(`Total Items: ${itemResult.totalItems}`);
- console.log(`Total Positions: ${itemResult.totalPositions}`);
- console.log(`Total Price (without shipping): €${itemResult.totalPrice.toFixed(2)}`);
- console.log(`Total Shipping Costs: €${shippingCosts.toFixed(2)}`);
- console.log(`Total Order Price (with shipping): €${totalOrderPrice.toFixed(2)}`);
- if (earliestDate) {
- console.log(`Earliest Order Date: ${earliestDate.toLocaleDateString('de-DE')}`);
- } else {
- console.log('Earliest Order Date: Not found');
- }
Advertisement
Add Comment
Please, Sign In to add comment