Skip to content

Instantly share code, notes, and snippets.

@eai04191
Created September 13, 2021 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eai04191/9a7af45af539c20502d95abc47e24671 to your computer and use it in GitHub Desktop.
Save eai04191/9a7af45af539c20502d95abc47e24671 to your computer and use it in GitHub Desktop.
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