如何每隔10秒不连续重复一次功能?

时间:2014-03-17 21:45:25

标签: javascript

我在Chrome控制台中使用此功能。我的问题是如何编辑代码,以便每10秒执行一次。

谢谢

var minValue = 1E-8,
    maxLoss = 10000000000000,
    aimedProfit = 10,
    maxOps = 500000000000000,
    endResult = 0,
    ops = 0,
    bet = function (a, b, c) {
          var seed = window.document.getElementById('next_client_seed').value;      
        $.get("?op=double_your_btc&m=" + (b ? "lo" : "hi") + "&stake=" + a + "&multiplier=2&jackpot=0&client_seed=" + seed, function (d) {
            d = d.split(":");
            $("#balance").html(d[3]);
            c(a, b, "w" === d[1])
        })
    }, martingale = function (a, b, c) {
        c || a >= maxLoss && 0 !== maxLoss ? (b = !b, newValue = minValue) : newValue = 2 * a;
        endResult = c ? endResult + a : endResult - a;
        console.log((c ? "+" : "-") + a);
        ops++;
        (ops < maxOps || 0 === maxOps) && (endResult < aimedProfit || 0 === aimedProfit) ? bet(newValue, b, martingale) :
            (console.log("Martingale finished in " + ops + " operations!"), console.log("Result: " + endResult))
    };
martingale(minValue, !1, !1);

2 个答案:

答案 0 :(得分:2)

您可以使用setTimeoutsetInterval

使用setInterval,您的代码将如下所示:

var myFunction = function () {
    var minValue = 1E-8,
    maxLoss = 10000000000000,
    aimedProfit = 10,
    maxOps = 500000000000000,
    endResult = 0,
    ops = 0,
    bet = function (a, b, c) {
          var seed = window.document.getElementById('next_client_seed').value;      
        $.get("?op=double_your_btc&m=" + (b ? "lo" : "hi") + "&stake=" + a + "&multiplier=2&jackpot=0&client_seed=" + seed, function (d) {
            d = d.split(":");
            $("#balance").html(d[3]);
            c(a, b, "w" === d[1])
        })
    }, martingale = function (a, b, c) {
        c || a >= maxLoss && 0 !== maxLoss ? (b = !b, newValue = minValue) : newValue = 2 * a;
        endResult = c ? endResult + a : endResult - a;
        console.log((c ? "+" : "-") + a);
        ops++;
        (ops < maxOps || 0 === maxOps) && (endResult < aimedProfit || 0 === aimedProfit) ? bet(newValue, b, martingale) :
            (console.log("Martingale finished in " + ops + " operations!"), console.log("Result: " + endResult))
    };
    martingale(minValue, !1, !1);
};

setInterval(myFunction, 10000);

答案 1 :(得分:0)

尝试:

setInterval(funcion(){
  martingale(minValue, !1, !1);
}, 10000);