wait something loaded befero execute a acript.

waitForJ = function(fn, attemptsLeft) {
    var tick = attemptsLeft || 30; 

    if (typeof(updatePhoneNew) == 'undefined' ) {
        //_gaq isn't registered yet
        if (tick > 1) {
            //recurse
            setTimeout(function() {
                waitForJ(fn, tick - 1);
            }, 100);
        }
        else {
            //no ticks left, log error
            console.log('failed to load window.gaq');
        }
    }
    else {
        //gaq is loaded, fire fn
        fn();
    }
};

waitForJ(function() {
    //here's all my code...
  $J( '#phone_link' ).trigger('click');
});
this script can be used on vivastreet to show the phone number automatically by chrome extension.

评论

热门博文