Created
April 23, 2020 01:16
-
-
Save codesandtags/df425afa9c670e210c39a9b5b03791ec 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
// Probabilities | |
const getRandomNumberOneToHundred = () => Math.random() * 100; | |
const keys = { | |
arrowLeft : { key : "ArrowLeft", keyCode : 37, code: 37 }, | |
arrowUp : { key : "ArrowUp", keyCode : 38, code: 38 }, | |
arrowRight : { key : "ArrowRight", keyCode : 39, code: 39 }, | |
arrowDown : { key : "ArrowDown", keyCode : 40, code: 40 }, | |
one : { key : "1", keyCode : 49, code: 49 }, | |
two : { key : "2", keyCode : 50, code: 50 } | |
} | |
const simulateKeyEvent = (eventName, eventData) => { | |
var keyEvent = new KeyboardEvent(eventName, { | |
char : "", | |
shiftKey: false, | |
bubbles : true, | |
cancelable : true, | |
...eventData | |
}); | |
document.body.dispatchEvent(keyEvent); | |
} | |
// The logic | |
const createLike = () => { | |
getRandomNumberOneToHundred() <= 70 | |
? simulateKeyEvent('keyup', keys.one) | |
: simulateKeyEvent('keyup', keys.two); | |
} | |
// Here is where magic happens | |
setInterval(createLike, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment