Skip to content

Instantly share code, notes, and snippets.

@fcamblor
Created August 8, 2012 13:22
Show Gist options
  • Save fcamblor/3294986 to your computer and use it in GitHub Desktop.
Save fcamblor/3294986 to your computer and use it in GitHub Desktop.
google doodle beaten (2)
// Execute this script in console on https://www.google.com/doodles/basketball-2012 :)
/////////////////////////////////////////////////////////////////////////////////////
// Add this prior to anything : it will allow you to use jquery in your page :)
var script = document.createElement('script');
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// Then, execute this in your browser debugger console...
// Note that to be optimal, you should be in a state where you played at least 1
// time and you're on the "play again" screen
/////////////////////////////////////////////////////////////////////////////////////
// Configure here your space charge configurations
// count corresponds to the number of times current change will be applied
// chargesEven corresponds to the number of milliseconds there will be between
// a space down then space up event
// chargesOdd corresponds to the number of milliseconds there will be between
// a space up then space down event
window.chargesConfig = [
// Dummy charge for the "play" button
{ count: 1, chargesEven: 50, chargesOdd: 300 },
// "true" charges
{ count: 14, chargesEven: 600, chargesOdd: 450 },
{ count: 8, chargesEven: 800, chargesOdd: 450 },
{ count: 8, chargesEven: 1000, chargesOdd: 450 },
{ count: 10, chargesEven: 1200, chargesOdd: 450 },
];
// useful flat allowing to skip infinite loop
// just write "window.skip=true" in your console and the infinite loop will stop
window.skip = false;
window.target = "#hplogo-c";
// Current charge count for current charge config
// Once window.chargesI == window.currentChargeConfig.count, then we shift
// up currentChrgeConfig
window.chargesI = 0;
// Number of times a space up/down is triggered. Used only for debug.
window.cpt = 0;
// Flag allowing to alternate space up / down
window.even = true;
// Current charge config used
window.currentChargeConfig = window.chargesConfig[0];
// Current charge config index
window.currentChargeConfigI = 0;
window.charge = function(){
if(window.skip){ return; }
// Triggering space event
var eventType = window.even?"keydown":"keyup";
console.log("["+window.cpt+"] Pressing "+eventType+"…");
$(target).trigger(jQuery.Event(eventType, { keyCode: 32 }));
// Calculating next charge() call timeout
var chargeTime = window.even ? window.currentChargeConfig.chargesEven:window.currentChargeConfig.chargesOdd;
setTimeout(window.charge, chargeTime);
// Computing "incremented" variables
window.even = !window.even;
window.chargesI++;
if(window.chargesI === window.chargesConfig[window.currentChargeConfigI].count
&& window.currentChargeConfigI != window.chargesConfig.length-1){
window.currentChargeConfigI++;
window.chargesI = 0;
window.currentChargeConfig = window.chargesConfig[window.currentChargeConfigI];
}
window.cpt++;
}
// latestTime is only for debug purposes (see below)
window.latestTime = new Date().getTime();
// Manually starting the charge infinite loop...
window.charge();
// For debug purposes…
// Will display current window.cpt in console when left arrow is clicked
// Useful to adjust when to switch from a chargesConfig to another
// (see "count" field in chargesConfigs) …
$("body").keyup(function(e){
if(e.keyCode === 39){
console.log("x pressed on : "+window.cpt);
}
});
// When charge() is not enabled, with these, you can track your time delta between
// space up/down when you're manually playing …
// Useful to record approximately the chargesEven and chargesOdd values in chargesConfigs.
var currentEventType = null;
$("body").keyup(function(e){
if(e.keyCode === 32 && e.type !== currentEventType){
var currentTime = new Date().getTime();
console.log("Time delta for "+e.type+" : "+(window.latestTime - currentTime));
window.latestTime = currentTime;
currentEventType = e.type;
}
});
$("body").keydown(function(e){
if(e.keyCode === 32 && e.type !== currentEventType){
var currentTime = new Date().getTime();
console.log("Time delta for "+e.type+" : "+(window.latestTime - currentTime));
window.latestTime = currentTime;
currentEventType = e.type;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment