Skip to content

Instantly share code, notes, and snippets.

@johnolek
Last active June 8, 2018 21:00
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 johnolek/cb3ed9886416c6ea3adc97735daa37dd to your computer and use it in GitHub Desktop.
Save johnolek/cb3ed9886416c6ea3adc97735daa37dd to your computer and use it in GitHub Desktop.
This is a cheat/bot for 10fastfingers.com. Copy and paste into your browser's console when there is a game present and it should just work. Change the targetWpm value and it will try to get as close as possible to it.
class TenFastCheater {
constructor() {
const spaceEvent = $.Event('keyup')
spaceEvent.which = 32
this.spaceEvent = spaceEvent
this.adjustmentStep = 50
this.minDelay = 50
this.randomRange = 10
this.targetWpm = 157
this.charactersTyped = 0
this.startTime = 0
this.delay = 1 / (this.targetWpm / 60) * 1000
}
static currentWordSelector() {
return 'span.highlight'
}
static inputSelector() {
return '#inputfield'
}
static timerSelector() {
return '#timer'
}
currentWord() {
return $(this.constructor.currentWordSelector()).text()
}
currentWordExists() {
const word = $(this.constructor.currentWordSelector())
return word.text() !== "" && word.is(':visible')
}
pressSpace() {
$(this.constructor.inputSelector()).trigger(this.spaceEvent);
}
typeWord(word) {
$(this.constructor.inputSelector()).val(word)
this.pressSpace()
// Plus one for the space
this.charactersTyped += word.length + 1
}
typeCurrentWord() {
this.typeWord(this.currentWord())
}
nextTimeout() {
const randomDelay = (Math.random() * this.randomRange * 2) - this.randomRange
return this.delay + randomDelay
}
currentEstimatedWpm() {
if (this.secondsElapsed() <= 5) {
return 0;
}
return (60 / (this.secondsElapsed()) * this.charactersTyped) / 5
}
secondsElapsed() {
return ((new Date).getTime() - this.startTime) / 1000
}
adjustDelay() {
if (this.currentEstimatedWpm() == 0) {
return
}
const change = this.adjustmentStep
if (this.currentEstimatedWpm() > this.targetWpm) {
this.delay += change
} else if (this.delay - change >= this.minDelay ) {
this.delay -= change
}
}
cheat() {
if (this.startTime == 0) {
this.startTime = (new Date).getTime()
}
this.typeCurrentWord()
if (!this.currentWordExists()) {
this.reset()
return
}
this.adjustDelay()
const nextTimeout = this.nextTimeout()
setTimeout(this.cheat.bind(this), nextTimeout)
}
reset() {
this.startTime = 0
this.charactersTyped = 0
}
}
const cheater = new TenFastCheater
cheater.cheat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment