Skip to content

Instantly share code, notes, and snippets.

@aapzu
Created June 15, 2021 14:28
Show Gist options
  • Save aapzu/a5f19a14c720502a12ae16e757775e9f to your computer and use it in GitHub Desktop.
Save aapzu/a5f19a14c720502a12ae16e757775e9f to your computer and use it in GitHub Desktop.
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