0

脚本本身运行良好;它没有错误。然而,在运行 7,500 次中,只有 35 次成功。我将如何提高 Regex 的成功率?因为现在,它没有做这项工作。

var IDs = [136758649, 116770724, 136171998]//A lot more IDS than this
var PriceWanting = 60
var scanneditems = 0
var itemerror = 0
document.write('<p id = "title">Total number bought: 0 items for a total of 0</p>')
document.write('<p id = "scanned">Items scanned: 0</p>')
document.write('<p id = "itemerrors">Items scanned: 0</p>')
var buys = 0
var totalrobuxspent = 0
console.log("Bot started")
var loop = setInterval(function()
{
  for (var i = 0;i<IDs.length;i++) {
  $.get(" http://m.roblox.com/items/" + IDs[i] + "/privatesales",function(data) {
      var Regex = /\<span class="currency-robux">([\d,]+)\<\/span\>/;
      var PriceSelling = data.match(Regex);
      scanneditems = scanneditems + 1
      document.getElementById("scanned").innerHTML = "Scanned items: " + scanneditems
      PriceSelling = PriceSelling ? PriceSelling[1] : '';
      if (PriceSelling.length < 1) {
        itemerrors = itemerrors + 1
        document.getElementById(''itemserror'').innerHTML = ''Total errors: '' + itemerrors
        return
      }
      PriceSelling = Number(PriceSelling.replace(",",""))
      PriceSelling = PriceSelling * 1
      totalrobuxspent = totalrobuxspent + PriceSelling
      var remaining = PriceWanting - PriceSelling
      if (remaining >= -0.1) 
      {
        buys = buys + 1
        document.getElementById("title").innerHTML = "Total number of items bought: " + buys + " for a total of " + totalrobuxspent + " "
var Regex2 = /<a href="\/Catalog\/VerifyTransfer\DuserAssetOptionId=([\d,]+)\Damp;expectedPrice=([\d,]+)">/
                                var HatBuyId = data.match(Regex2)[1]
                                var HatBuyLink = "http://m.roblox.com/Catalog/VerifyPurchase?assetid=" + HatBuyId + " &type=robux&expectedPrice=" + PriceSelling
var Explorer = document.createElement('iframe');
                                function Buy(){
       Explorer.contentDocument.forms[0].submit();
       console.log("Item purchase complete, scanning again.")
       var inf = document.createElement('div');
       inf.style.fontSize = "18px";
       inf.style.background = "rgba(0,0,5,0)";
       inf.style.position = "absolute";
       inf.style.width = "100%";
       inf.style.height = "18pt";
       inf.innerText = "Bot currently running. Purchases: "+answer;
       document.body.appendChild(inf);
                                };
                                Explorer.onload = Buy;
                                Explorer.width = "100%";
                                Explorer.height = "85%";
                                Explorer.src = HatBuyLink;
                                document.body.innerHTML = "";
                                document.body.appendChild(Explorer);
    }
  })
}
},500)
4

2 回答 2

2

.get是异步的。这意味着在返回响应之前不会执行回调函数。到那时,您不再处于循环中,实际上循环已经完成。

虽然它是关于一个稍微不同的问题,但这个问题是一个很好的读物,可以理解异步调用是如何工作的。


此外,continue即使没有异步行为,这里仍然是非法的,因为函数有自己的上下文,并且与循环不在同一个上下文中。这个简单的例子也是非法的,可能更容易理解上下文问题:

for(var i=0; i<10; i++){
    someFunc();
}

function someFunc(){
    continue;  // illegal
}

尽管在您的情况下该函数是匿名函数,但同样的概念也适用。

于 2014-02-22T23:08:41.737 回答
0

请在您的代码中使用分号。

continue;

适用于循环,不适用于函数。使用

return;

关键字来脱离函数的上下文。

于 2014-02-23T00:57:47.460 回答