Created
June 15, 2021 14:28
-
-
Save aapzu/a5f19a14c720502a12ae16e757775e9f 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
const send = function(content) { | |
const waitFor = (condFunc, cb, timeout = 5) => new Promise((resolve) => { | |
const f = () => { | |
if (condFunc()) { | |
resolve() | |
} else { | |
setTimeout(f, timeout) | |
} | |
} | |
setTimeout(f, timeout) | |
}) | |
const getLastMessageId = () => [...document.querySelectorAll(".c-virtual_list__item")].slice(-1)[0].id | |
document.querySelector(".ql-editor > p").textContent = content | |
const lastOtherPersonMessageId = getLastMessageId() | |
setTimeout(async () => { | |
document.querySelector("button.c-wysiwyg_container__button--send").click() | |
console.time("Slack message") | |
let lastMessageId | |
await waitFor(() => { | |
lastMessageId = getLastMessageId() | |
return !lastMessageId.includes("x") && lastMessageId !== lastOtherPersonMessageId | |
}) | |
await waitFor(() => getLastMessageId() !== lastMessageId) | |
console.timeEnd("Slack message") | |
}, 100) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment