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:
89
apilo.js
89
apilo.js
@@ -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,24 +244,75 @@ function retryUntilSuccess(fn, interval = 500, retries = 10) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectPackageType() {
|
function setContent( method ) {
|
||||||
return retryUntilSuccess(() => {
|
if ( method == 'D2D.apaczka' ) {
|
||||||
return new Promise((resolve, reject) => {
|
return retryUntilSuccess(() => {
|
||||||
const selectElement = document.getElementById('warehousebundle_shipment_packageType');
|
return new Promise((resolve, reject) => {
|
||||||
if (selectElement) {
|
const selectElement = document.getElementById('warehousebundle_shipment_preferences_content');
|
||||||
selectElement.value = 'package';
|
selectElement.value = 'prezent';
|
||||||
const event = document.createEvent('HTMLEvents');
|
const event = document.createEvent('HTMLEvents');
|
||||||
event.initEvent('change', true, false);
|
event.initEvent('change', true, false);
|
||||||
selectElement.dispatchEvent(event);
|
selectElement.dispatchEvent(event);
|
||||||
resolve();
|
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 {
|
} 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) {
|
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');
|
||||||
|
|||||||
Reference in New Issue
Block a user