Initial commit
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
(async () => {
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
const getAllDocuments = () => {
|
||||
const docs = [document];
|
||||
|
||||
const scan = doc => {
|
||||
[...doc.querySelectorAll("iframe, frame")].forEach(frame => {
|
||||
try {
|
||||
if (frame.contentDocument) {
|
||||
docs.push(frame.contentDocument);
|
||||
scan(frame.contentDocument);
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
};
|
||||
|
||||
scan(document);
|
||||
return docs;
|
||||
};
|
||||
|
||||
const waitForElement = async (selector, timeout = 30000) => {
|
||||
const start = Date.now();
|
||||
|
||||
while (Date.now() - start < timeout) {
|
||||
for (const doc of getAllDocuments()) {
|
||||
const el = doc.querySelector(selector);
|
||||
if (el) return el;
|
||||
}
|
||||
|
||||
await sleep(300);
|
||||
}
|
||||
|
||||
throw new Error(`No se encontró: ${selector}`);
|
||||
};
|
||||
|
||||
const waitForEnabledDownload = async (timeout = 10 * 60 * 1000) => {
|
||||
const start = Date.now();
|
||||
|
||||
while (Date.now() - start < timeout) {
|
||||
for (const doc of getAllDocuments()) {
|
||||
const button = doc.querySelector("#id_pub_button_download");
|
||||
|
||||
if (
|
||||
button &&
|
||||
button.offsetParent !== null &&
|
||||
!button.classList.contains("disabled") &&
|
||||
button.getAttribute("disabled") === null
|
||||
) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
throw new Error("El botón Download no se habilitó dentro del tiempo esperado");
|
||||
};
|
||||
|
||||
const click = async el => {
|
||||
el.scrollIntoView({ block: "center", inline: "center" });
|
||||
el.focus();
|
||||
await sleep(500);
|
||||
|
||||
const view = el.ownerDocument.defaultView || window;
|
||||
["mouseover", "mousedown", "mouseup", "click"].forEach(type => {
|
||||
el.dispatchEvent(
|
||||
new view.MouseEvent(type, {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
view
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
el.click();
|
||||
};
|
||||
|
||||
const clickAndWait = async (selector, nextSelector) => {
|
||||
const el = await waitForElement(selector);
|
||||
await click(el);
|
||||
await sleep(1200);
|
||||
|
||||
if (nextSelector) {
|
||||
await waitForElement(nextSelector);
|
||||
}
|
||||
};
|
||||
|
||||
const deploy = await waitForElement("#id_menu_prj_deploy");
|
||||
await click(deploy);
|
||||
|
||||
await sleep(1500);
|
||||
|
||||
await clickAndWait(
|
||||
'input[name="avancar"][value="Next"][onclick="nm_next()"]',
|
||||
'input[name="avancar"][value="Next"][onclick*="esquema"]'
|
||||
);
|
||||
|
||||
await clickAndWait(
|
||||
'input[name="avancar"][value="Next"][onclick*="esquema"]',
|
||||
'input[name="avancar"][value="Next"][onclick*="perfil"]'
|
||||
);
|
||||
|
||||
await clickAndWait(
|
||||
'input[name="avancar"][value="Next"][onclick*="perfil"]',
|
||||
'input[name="avancar"][value="Next"][onclick*="create_dir"]'
|
||||
);
|
||||
|
||||
const lastNext = await waitForElement(
|
||||
'input[name="avancar"][value="Next"][onclick*="create_dir"]'
|
||||
);
|
||||
|
||||
await click(lastNext);
|
||||
|
||||
console.log("Esperando que se habilite Download...");
|
||||
|
||||
const downloadButton = await waitForEnabledDownload();
|
||||
|
||||
console.log("Download habilitado:", downloadButton);
|
||||
await sleep(1500);
|
||||
await click(await waitForEnabledDownload(30000));
|
||||
console.log("Download clickeado.");
|
||||
})();
|
||||
Reference in New Issue
Block a user