Created
September 13, 2021 07:23
-
-
Save eai04191/9a7af45af539c20502d95abc47e24671 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 sleep = (msec) => new Promise((resolve) => setTimeout(resolve, msec)); | |
const sendButton = document.querySelector( | |
`button[data-a-target="chat-send-button"]` | |
); | |
const send = (message) => { | |
const input = document.querySelector(`textarea[data-a-target="chat-input"]`); | |
const lastValue = input.value; | |
input.value = message; | |
const event = new Event("input", { bubbles: true }); | |
const tracker = input._valueTracker; | |
if (tracker) { | |
tracker.setValue(lastValue); | |
} | |
input.dispatchEvent(event); | |
sendButton.click(); | |
}; | |
const init = () => { | |
const button = sendButton.parentNode.cloneNode(true); | |
button.querySelector( | |
`[data-a-target="tw-core-button-label-text"]` | |
).innerText = "Bulk"; | |
button.addEventListener("click", async () => { | |
const clipboard = await navigator.clipboard.readText(); | |
const run = confirm("以下のテキストを1行ずつ送信します:\n\n" + clipboard); | |
if (!run) return; | |
clipboard.split("\n").forEach(async (line) => { | |
send(line); | |
await sleep(1000); | |
}); | |
}); | |
sendButton.parentNode.parentNode.appendChild(button); | |
}; | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment