Last active
August 29, 2015 14:20
-
-
Save yangshun/3f2e7a59f281574cdd96 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
// Hack for Kolor Game | |
// 1. Play the game at http://kolor.moro.es | |
// 2. Before clicking on "Start!", open up the JavaScript console and paste the following snippet of code. | |
// 3. WIN. | |
// Change the value for INTERVAL to have a faster refresh rate. | |
// Set AUTOPLAY to true to let the game play on its own, you lazy bum. | |
(function () { | |
var INTERVAL = 300; | |
var AUTOPLAY = false; | |
function rgbToHex(color) { | |
var bg = color.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); | |
function hex(x) { | |
return ('0' + parseInt(x).toString(16)).slice(-2); | |
} | |
return '#' + hex(bg[1]) + hex(bg[2]) + hex(bg[3]); | |
} | |
setInterval(function () { | |
var main = document.querySelectorAll('#kolor-kolor'); | |
if (main.length > 0) { | |
if (main[0].style && main[0].style.backgroundColor) { | |
var mainColor = rgbToHex(main[0].style.backgroundColor); | |
main[0].textContent = mainColor; | |
} | |
var options = document.querySelectorAll('#kolor-options li a'); | |
for (var i = 0; i < options.length; i++) { | |
var a = options[i]; | |
if (a.style && a.style.backgroundColor) { | |
var color = rgbToHex(a.style.backgroundColor); | |
a.textContent = color; | |
if (color === mainColor) { | |
a.style.border = 'red solid 5px'; | |
if (AUTOPLAY) { | |
a.click(); | |
} | |
} | |
} | |
} | |
} | |
}, INTERVAL); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment