Last active
August 29, 2015 14:18
-
-
Save withinboredom/45fcb336c0661de7d9ab to your computer and use it in GitHub Desktop.
Winning Auctions
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
(function() { | |
var checkBid = true; | |
// run a function if the bid button is | |
var isButtonEnabled = function(callback) { | |
console.log('checking for new bids'); | |
// if the place bid button is not disabled and we are ok to check a bid | |
if (!$('.place-bid').hasClass('disabled') && checkBid) { | |
// make it so we won't place a bid twice | |
checkBid = false; | |
// output debug information | |
console.log('placing bid'); | |
// place the bid | |
callback(); | |
} | |
}; | |
var placeBid = function() { | |
// wait somewhere between 1 and 4 seconds, so its not obvious we are automating this | |
var wait = (Math.random() * 3 + 1)*1000; | |
setTimeout(function() { | |
// click the button | |
$('.place-bid').click(); | |
// output debug information | |
console.log('placed bid'); | |
// and set our race condition preventer that its ok to check the button now | |
checkBid = true; | |
}, wait); | |
}; | |
// check the button to see if its been enabled every 5 seconds | |
setInterval(function() { | |
isButtonEnabled(placeBid); | |
}, 5000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment