Skip to content

Instantly share code, notes, and snippets.

@sachalifs
Created November 28, 2021 00:36
Show Gist options
  • Save sachalifs/48c994afbb46e7d95e6e52acc9843c62 to your computer and use it in GitHub Desktop.
Save sachalifs/48c994afbb46e7d95e6e52acc9843c62 to your computer and use it in GitHub Desktop.
/* eslint-disable func-style */
const InputEvent = window.Event || window.InputEvent;
const ONE_MINUTE = 60_000;
const TEN_SECONDS = 10_000;
const CONFIG = {
GLOBAL_INTERVAL: ONE_MINUTE,
MESSAGES_INTERVAL: TEN_SECONDS,
};
const DNI = "TU_DNI_ACÁ"; // ejemplo: 34870572
const BotiMessages = {
Init: "resultado test",
Yes: "sí",
};
const GET_COVID_TEST_RESULT_MESSAGES = [
BotiMessages.Init,
BotiMessages.Yes,
BotiMessages.Yes,
DNI,
];
function sendMessage(message) {
const messageInput = document.querySelector("[title='Type a message']");
const event = new InputEvent("input", {
bubbles: true,
});
messageInput.textContent = message;
messageInput.dispatchEvent(event);
const sendButton =
messageInput.parentElement.parentElement.parentElement.querySelector(
"div button"
);
sendButton.click();
}
const sendMessages = (messages, config) => {
if (!messages.length) {
return;
}
const [message, ...rest] = messages;
sendMessage(message);
setTimeout(() => {
sendMessages(rest, config);
}, config.interval);
};
function start(config = CONFIG) {
setInterval(() => {
sendMessages(GET_COVID_TEST_RESULT_MESSAGES, {
interval: config.MESSAGES_INTERVAL,
});
}, config.GLOBAL_INTERVAL);
}
start();
@jmanuoz
Copy link

jmanuoz commented Nov 29, 2021

estaria bueno agregarle algún aviso cuando el resultado ya esta disponible y que deje de mandar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment