Tylon

Summerize AliExpress

Nov 14th, 2024
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Extrahiert alle relevanten Elemente auf der Seite, die Einzelpreise enthalten
  2. const itemElements = Array.from(document.querySelectorAll('.order-item-content-info-number'));
  3.  
  4. // Berechnet den Gesamtpreis und die Anzahl der Artikel (Einzelpreise * Menge) und die Anzahl der Positionen
  5. const itemResult = itemElements.reduce((acc, element) => {
  6.     // Extrahiere das div-Element, das die Preiszahlen enthält
  7.     const priceContainer = element.querySelector('.es--wrap--2p8eS4Q');
  8.  
  9.     if (priceContainer) {
  10.         // Extrahiere alle relevanten Zeichen in den verschachtelten span-Tags und setze sie zu einem String zusammen
  11.         const priceString = Array.from(priceContainer.querySelectorAll('.es--char--1Qcd3D7'))
  12.             .map(span => span.innerText || span.textContent)
  13.             .join('');
  14.  
  15.         // Ersetze das Komma durch einen Punkt, damit parseFloat funktioniert
  16.         const price = parseFloat(priceString.replace(',', '.'));
  17.  
  18.         // Extrahiere die Menge des Artikels
  19.         const quantityElement = element.querySelector('.order-item-content-info-number-quantity');
  20.         let quantity = 1; // Standardmenge falls nichts gefunden
  21.  
  22.         if (quantityElement) {
  23.             // Extrahiere die Menge aus dem Text, z.B. "x1"
  24.             const quantityMatch = quantityElement.innerText.match(/x(\d+)/);
  25.             if (quantityMatch) {
  26.                 quantity = parseInt(quantityMatch[1], 10);
  27.             }
  28.         }
  29.  
  30.         // Falls der Preis erfolgreich extrahiert wurde, addiere ihn zum Gesamtpreis und erhöhe die Artikelanzahl
  31.         if (!isNaN(price)) {
  32.             acc.totalPrice += price * quantity; // Gesamtpreis addieren (Preis * Anzahl)
  33.             acc.totalItems += quantity; // Gesamtanzahl der Artikel addieren
  34.             acc.totalPositions += 1; // Artikelposition erhöhen
  35.         }
  36.     }
  37.  
  38.     return acc;
  39. }, { totalPrice: 0, totalItems: 0, totalPositions: 0 });
  40.  
  41. // Extrahiert alle Gesamtpreise inkl. Versandkosten
  42. const totalElements = Array.from(document.querySelectorAll('.order-item-content-opt-price-total .es--wrap--2p8eS4Q'));
  43.  
  44. // Berechnet die Summe aller Gesamtpreise inkl. Versandkosten
  45. let totalOrderPrice = totalElements.reduce((total, element) => {
  46.     // Extrahiere alle relevanten Zeichen in den verschachtelten span-Tags und setze sie zu einem String zusammen
  47.     const totalPriceString = Array.from(element.querySelectorAll('.es--char--1Qcd3D7'))
  48.         .map(span => span.innerText || span.textContent)
  49.         .join('');
  50.  
  51.     // Ersetze das Komma durch einen Punkt, damit parseFloat funktioniert
  52.     const price = parseFloat(totalPriceString.replace(',', '.'));
  53.  
  54.     // Falls der Preis erfolgreich extrahiert wurde, addiere ihn zur Gesamtsumme
  55.     if (!isNaN(price)) {
  56.         total += price;
  57.     }
  58.  
  59.     return total;
  60. }, 0);
  61.  
  62. // Berechnet die Summe der Versandkosten
  63. const shippingCosts = totalOrderPrice - itemResult.totalPrice;
  64.  
  65. // Extrahiert alle Elemente mit Bestelldatum
  66. const dateElements = Array.from(document.querySelectorAll('.order-item-header-right-info'));
  67.  
  68. // Findet das früheste Bestelldatum
  69. let earliestDate = null;
  70.  
  71. dateElements.forEach(element => {
  72.     // Suchen nach dem Div, das das Bestelldatum enthält
  73.     const dateContainer = element.querySelector('div[data-spm-anchor-id]');
  74.  
  75.     if (dateContainer) {
  76.         // Extrahiere das Bestelldatum als String, z.B. "Bestellung aufgegeben am: 27. Sep 2015"
  77.         const dateText = dateContainer.innerText || dateContainer.textContent;
  78.  
  79.         // Extrahiere das tatsächliche Datum mithilfe eines regulären Ausdrucks
  80.         const dateMatch = dateText.match(/am: (\d{1,2}\.?\s?\w+\s\d{4})/);
  81.         if (dateMatch) {
  82.             const dateString = dateMatch[1];
  83.             const currentDate = new Date(dateString);
  84.  
  85.             // Setze das früheste Datum, falls es noch nicht gesetzt wurde, oder falls das aktuelle Datum früher ist
  86.             if (!earliestDate || currentDate < earliestDate) {
  87.                 earliestDate = currentDate;
  88.             }
  89.         }
  90.     }
  91. });
  92.  
  93. // Zeige die fünf gewünschten Ergebnisse in der Konsole
  94. console.log(`Total Items: ${itemResult.totalItems}`);
  95. console.log(`Total Positions: ${itemResult.totalPositions}`);
  96. console.log(`Total Price (without shipping): €${itemResult.totalPrice.toFixed(2)}`);
  97. console.log(`Total Shipping Costs: €${shippingCosts.toFixed(2)}`);
  98. console.log(`Total Order Price (with shipping): €${totalOrderPrice.toFixed(2)}`);
  99. if (earliestDate) {
  100.     console.log(`Earliest Order Date: ${earliestDate.toLocaleDateString('de-DE')}`);
  101. } else {
  102.     console.log('Earliest Order Date: Not found');
  103. }
Advertisement
Add Comment
Please, Sign In to add comment