Dodano obsługę metody wysyłki D2D Apaczka oraz zaktualizowano funkcje związane z wyborem typu paczki i ustawieniem zawartości.

This commit is contained in:
2025-03-16 00:18:09 +01:00
parent e350f92f68
commit 5f596e2e00

View File

@@ -1,19 +1,4 @@
const currentUrl = window.location.href; const currentUrl = window.location.href;
console.log(currentUrl);
const patterns = [ const patterns = [
/^https:\/\/projectpro\.apilo\.com\/order\/order\/news\/?$/, /^https:\/\/projectpro\.apilo\.com\/order\/order\/news\/?$/,
/^https:\/\/projectpro\.apilo\.com\/order\/order\/in-progress\/?$/, /^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 buttonD2D = createButton('Inpost D2D', '#ff7800', 'D2D.inpostkurier');
const buttonD2P = createButton('Inpost D2P', '#28a745', 'D2P.inpost'); const buttonD2P = createButton('Inpost D2P', '#28a745', 'D2P.inpost');
const buttonP2P = createButton('Inpost P2P', '#ffc107', 'P2P.inpost', 'RZE14N||RZE14N'); const buttonP2P = createButton('Inpost P2P', '#ffc107', 'P2P.inpost', 'RZE14N||RZE14N');
const buttonD2Dapaczka = createButton('D2D Apaczka', '#ff7800', 'D2D.apaczka');
buttonContainer.appendChild(buttonP2D); buttonContainer.appendChild(buttonP2D);
buttonContainer.appendChild(buttonD2D); buttonContainer.appendChild(buttonD2Dapaczka);
// buttonContainer.appendChild(buttonD2D);
buttonContainer.appendChild(buttonD2P); buttonContainer.appendChild(buttonD2P);
buttonContainer.appendChild(buttonP2P); buttonContainer.appendChild(buttonP2P);
} }
@@ -223,11 +210,12 @@ function createButton(text, backgroundColor, method, dropoffPoint = null) {
async function handleShipment(method, dropoffPoint = null) { async function handleShipment(method, dropoffPoint = null) {
try { try {
await selectPackageType(); await selectPackageType(method);
await setShipmentMethod(method); await setShipmentMethod(method);
if (dropoffPoint) { if (dropoffPoint) {
await setDropoffPoint(dropoffPoint); await setDropoffPoint(dropoffPoint);
} }
await setContent( method );
await setParcelWeight('1'); await setParcelWeight('1');
await submitShipment(); await submitShipment();
} catch (error) { } 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) => { return new Promise((resolve, reject) => {
const attempt = async () => { const attempt = async () => {
try { try {
@@ -256,9 +244,54 @@ function retryUntilSuccess(fn, interval = 500, retries = 10) {
}); });
} }
function selectPackageType() { function setContent( method ) {
if ( method == 'D2D.apaczka' ) {
return retryUntilSuccess(() => { return retryUntilSuccess(() => {
return new Promise((resolve, reject) => { 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 {
const selectElement = document.getElementById('warehousebundle_shipment_packageType'); const selectElement = document.getElementById('warehousebundle_shipment_packageType');
if (selectElement) { if (selectElement) {
selectElement.value = 'package'; selectElement.value = 'package';
@@ -269,11 +302,17 @@ function selectPackageType() {
} else { } else {
reject('Nie znaleziono elementu packageType'); reject('Nie znaleziono elementu packageType');
} }
}
}); });
}); });
} }
function setShipmentMethod(method) { function setShipmentMethod(method) {
if ( method == 'D2D.apaczka' ) {
return new Promise((resolve, reject) => {
resolve();
});
}
return retryUntilSuccess(() => { return retryUntilSuccess(() => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const methodElement = document.getElementById('warehousebundle_shipment_method'); const methodElement = document.getElementById('warehousebundle_shipment_method');