Created
November 28, 2021 00:36
-
-
Save sachalifs/48c994afbb46e7d95e6e52acc9843c62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
estaria bueno agregarle algún aviso cuando el resultado ya esta disponible y que deje de mandar