Skip to content

Instantly share code, notes, and snippets.

@raboof
Created October 27, 2015 07:41
Show Gist options
  • Save raboof/2c82709d734ecb8a8014 to your computer and use it in GitHub Desktop.
Save raboof/2c82709d734ecb8a8014 to your computer and use it in GitHub Desktop.
Poor man's Xebia name-trainer
/*
* Usage:
* - open https://updates.xebia.com/smoelenboek/
* - paste this file into chrome developer tools js console
* - look at the picture in the top-left corner and choose from the names in the js console
*/
images = jQuery('dt.portrait img')
answer = [ , , , ]
function randomImg() {
return images[Math.floor(Math.random() * images.size())]
}
function show(target) {
images.css('z-index', 0)
target.style.position = 'absolute'
target.style.top = '30px'
target.style.left = '0px'
target.style.zIndex = 2
}
function next() {
target = randomImg()
show(target)
var correct = Math.floor(Math.random() * 4);
answer = [ , , , ]
answer[0] = randomImg().alt
answer[1] = randomImg().alt
answer[2] = randomImg().alt
answer[3] = randomImg().alt
answer[correct] = target.alt
console.log('a: ' + answer[0])
console.log('s: ' + answer[1])
console.log('d: ' + answer[2])
console.log('f: ' + answer[3])
}
jQuery('body').keypress(function(e) {
switch (e.keyCode) {
case 97:
guess(0)
break
case 115:
guess(1)
break
case 100:
guess(2)
break
case 102:
guess(3)
break
}
})
function guess(n) {
if (answer[n] == target.alt)
console.log('OK')
else
console.log('Nope, that was ' + target.alt + ', not ' + answer[n])
next()
}
next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment