Last active
October 25, 2020 21:28
-
-
Save revenkroz/18e7aea28d5fa17ab4452ef304cee07c to your computer and use it in GitHub Desktop.
Just init in the browser console and spam what you want
This file contains hidden or 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
| 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