Created
September 22, 2009 09:03
-
-
Save straps/190937 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Monitor bidders and bid for you; use jQuery ajax events capabilities | |
console.clear(); | |
(function($){ | |
$('#header_container') | |
.add('div.auction_related_list') | |
.add('div#footer_container') | |
.remove(); | |
var id=parseInt($('div.auction_top_cont td:last').text().match(/[0-9]+/)[0],10), | |
u='straps', | |
$a=$('div#auction_bid_button_'+id+' a'); | |
window.bidstart=true; | |
if (window.tt) { clearTimeout(window.tt); } | |
var clog=console.log, cdir=console.dir,oldet=0,oldbid=null,oldnow=0,connlost=0; | |
if (window.checkNowInterval) clearInterval(window.checkNowInterval); | |
window.checkNowInterval=setInterval(function(){ | |
var now=parseInt(Math.round(new Date().getTime()/1000),10); | |
//clog(now-oldnow); | |
if (oldnow>0 && now-oldnow>2) { | |
console.warn('Connessione Persa?'); | |
connlost=0; | |
} | |
},1000); | |
window.onBidAjax=function(e,x,o){ | |
if ($('div.auction_sold:visible').size()) { | |
window.$strx.unbind('ajaxSuccess'); | |
return false; | |
} | |
connlost++; | |
var now=parseInt(Math.round(new Date().getTime()/1000),10); | |
oldnow=now; | |
if (oldet-now<4){ //Periodo CALDO | |
if (o.url==='http://www.bidrivals.com/robot/getData.php?sid=13'){ | |
//var bid=jLinq.from(eval('('+x.responseText+')')).equals('id',id).select()[0]; | |
var bid=eval('('+x.responseText+')'); | |
while(bid[0].id!==id) { bid.splice(0,1); } | |
bid=bid[0]; | |
var left=(bid.et-now); | |
if (oldet!==bid.et){ | |
var bidplan=((left-1)*1000)-800; | |
if (window.tt) { clearTimeout(window.tt); } | |
window.users=bid.l.split(',').reverse(); | |
oldet=bid.et; | |
oldbid=bid; | |
if (window.users[0]!==u){ | |
if (window.users[0]===window.users[1] && window.users[1]===u){ | |
//Siamo rimasti in 2, accorcio il timeout per il bid per essere sicuro di non | |
//perder l'oggetto | |
bidplan-=500; | |
} | |
console.info('Nuova Offerta a '+(bid.p/100)+' da '+users.join(',')+', bid tra '+(left-1)+'s, connlost='+connlost); | |
window.tt=setTimeout(checkForBid,bidplan); | |
}else{ | |
console.info('Sei il MIGLIORE'); | |
} | |
}else{ | |
clog('et='+bid.et+', now='+now+', remain='+left); | |
} | |
} | |
} | |
}; | |
function checkForBid(){ | |
console.info('checkForBid connlost='+connlost+', bidstart='+window.bidstart+', visual time left='+$('#auction_'+id+' .auction_timeleft').text()); | |
if (connlost>1 && window.bidstart){ | |
console.info('BID BID BID BID BID'); | |
$a=$('div#auction_bid_button_'+id+' a'); | |
$a.click(); | |
} | |
} | |
if (window.$strx){ | |
window.$strx.unbind('ajaxSuccess').bind('ajaxSuccess',window.onBidAjax); | |
}else{ | |
window.$strx=$('<span id="strx"><strong>bind started, click to STOP</strong></span>').appendTo('body').bind('ajaxSuccess',window.onBidAjax).click(function(){ | |
var $this=$(this); | |
window.bidstart!=window.bidstart; | |
$this.text(window.bidstart?'STOP':'START'); | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment