From 5f596e2e00c0abfcadec36fa487a550b8cd120ec Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Sun, 16 Mar 2025 00:18:09 +0100 Subject: [PATCH] =?UTF-8?q?Dodano=20obs=C5=82ug=C4=99=20metody=20wysy?= =?UTF-8?q?=C5=82ki=20D2D=20Apaczka=20oraz=20zaktualizowano=20funkcje=20zw?= =?UTF-8?q?i=C4=85zane=20z=20wyborem=20typu=20paczki=20i=20ustawieniem=20z?= =?UTF-8?q?awarto=C5=9Bci.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apilo.js | 89 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/apilo.js b/apilo.js index d31c03f..2378715 100644 --- a/apilo.js +++ b/apilo.js @@ -1,19 +1,4 @@ - - - - - - - - - - - - - - const currentUrl = window.location.href; -console.log(currentUrl); const patterns = [ /^https:\/\/projectpro\.apilo\.com\/order\/order\/news\/?$/, /^https:\/\/projectpro\.apilo\.com\/order\/order\/in-progress\/?$/, @@ -195,9 +180,11 @@ if (pattern.test(currentUrl2)) { const buttonD2D = createButton('Inpost D2D', '#ff7800', 'D2D.inpostkurier'); const buttonD2P = createButton('Inpost D2P', '#28a745', 'D2P.inpost'); const buttonP2P = createButton('Inpost P2P', '#ffc107', 'P2P.inpost', 'RZE14N||RZE14N'); + const buttonD2Dapaczka = createButton('D2D Apaczka', '#ff7800', 'D2D.apaczka'); buttonContainer.appendChild(buttonP2D); - buttonContainer.appendChild(buttonD2D); + buttonContainer.appendChild(buttonD2Dapaczka); + // buttonContainer.appendChild(buttonD2D); buttonContainer.appendChild(buttonD2P); buttonContainer.appendChild(buttonP2P); } @@ -223,11 +210,12 @@ function createButton(text, backgroundColor, method, dropoffPoint = null) { async function handleShipment(method, dropoffPoint = null) { try { - await selectPackageType(); + await selectPackageType(method); await setShipmentMethod(method); if (dropoffPoint) { await setDropoffPoint(dropoffPoint); } + await setContent( method ); await setParcelWeight('1'); await submitShipment(); } catch (error) { @@ -235,7 +223,7 @@ async function handleShipment(method, dropoffPoint = null) { } } -function retryUntilSuccess(fn, interval = 500, retries = 10) { +function retryUntilSuccess(fn, interval = 1000, retries = 10) { return new Promise((resolve, reject) => { const attempt = async () => { try { @@ -256,24 +244,75 @@ function retryUntilSuccess(fn, interval = 500, retries = 10) { }); } -function selectPackageType() { - return retryUntilSuccess(() => { - return new Promise((resolve, reject) => { - const selectElement = document.getElementById('warehousebundle_shipment_packageType'); - if (selectElement) { - selectElement.value = 'package'; +function setContent( method ) { + if ( method == 'D2D.apaczka' ) { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + const selectElement = document.getElementById('warehousebundle_shipment_preferences_content'); + selectElement.value = 'prezent'; const event = document.createEvent('HTMLEvents'); event.initEvent('change', true, false); selectElement.dispatchEvent(event); resolve(); + }); + }); + } +} + +function selectPackageType(method) { + return retryUntilSuccess(() => { + return new Promise((resolve, reject) => { + + if ( method == 'D2D.apaczka' ) { + + const selectElement = document.getElementById('warehousebundle_shipment_carrierAccount'); + selectElement.value = 17; + const event = document.createEvent('HTMLEvents'); + event.initEvent('change', true, false); + selectElement.dispatchEvent(event); + + // settimeout + setTimeout(() => { + const selectElement2 = document.getElementById('warehousebundle_shipment_method'); + selectElement2.value = 42; + const event2 = document.createEvent('HTMLEvents'); + event2.initEvent('change', true, false); + selectElement2.dispatchEvent(event2); + + // settimeout + setTimeout(() => { + const selectElement3 = document.getElementById('warehousebundle_shipment_preferences_packageType'); + selectElement3.value = 'PACZKA'; + const event3 = document.createEvent('HTMLEvents'); + event3.initEvent('change', true, false); + selectElement3.dispatchEvent(event3); + resolve(); + + }, 1000); + }, 1000); + } else { - reject('Nie znaleziono elementu packageType'); + const selectElement = document.getElementById('warehousebundle_shipment_packageType'); + if (selectElement) { + selectElement.value = 'package'; + const event = document.createEvent('HTMLEvents'); + event.initEvent('change', true, false); + selectElement.dispatchEvent(event); + resolve(); + } else { + reject('Nie znaleziono elementu packageType'); + } } }); }); } function setShipmentMethod(method) { + if ( method == 'D2D.apaczka' ) { + return new Promise((resolve, reject) => { + resolve(); + }); + } return retryUntilSuccess(() => { return new Promise((resolve, reject) => { const methodElement = document.getElementById('warehousebundle_shipment_method');