Skip to content

Instantly share code, notes, and snippets.

@revenkroz
Last active October 25, 2020 21:28
Show Gist options
  • Select an option

  • Save revenkroz/18e7aea28d5fa17ab4452ef304cee07c to your computer and use it in GitHub Desktop.

Select an option

Save revenkroz/18e7aea28d5fa17ab4452ef304cee07c to your computer and use it in GitHub Desktop.
Just init in the browser console and spam what you want
class Spammer {
chatInput = null;
sendButton = null;
valueSetter = null;
constructor() {
this.chatInput = document.querySelector('[data-a-target="chat-input"]');
this.sendButton = document.querySelector('[data-a-target="chat-send-button"]');
this._setupValueSetter();
}
/*
* Some browsers don't support private methods,
* replace this with `#setupValueSetter()` in the future
*/
_setupValueSetter() {
const valueSetter = Object.getOwnPropertyDescriptor(this.chatInput, 'value').set;
const proto = Object.getPrototypeOf(this.chatInput);
const prototypeValueSetter = Object.getOwnPropertyDescriptor(proto, 'value').set;
if (valueSetter && valueSetter !== prototypeValueSetter) {
this.valueSetter = prototypeValueSetter;
} else {
this.valueSetter = valueSetter;
}
}
send(value, numberOfTimes = 1) {
for (let i = 0; i < numberOfTimes; i++) {
this.valueSetter.call(this.chatInput, value);
this.chatInput.dispatchEvent(new Event('input', { bubbles: true }));
this.sendButton.click();
}
}
}
/* USAGE:
const spammer = new Spammer();
spammer.send('๐Ÿ˜Ž'); // to send one time
spammer.send('๐Ÿ˜Ž', 10); // to send 10 times
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment