Created
April 23, 2020 01:13
-
-
Save codesandtags/848abd5cbda4cd1134c74185867d9f42 to your computer and use it in GitHub Desktop.
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
// 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.arrowRight) | |
: simulateKeyEvent('keyup', keys.arrowLeft); | |
} | |
// 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