質問

I am trying to create essentially a bot that can add a product on Foot Action to my cart. I have this code but it does not work. Can anybody debug it and just explain what I've done incorrectly. My browser is Chrome and I use TamperMonkey. This an example of the product page: Footaction product

window.addEventListener('load'
, function() {

var added = false;

function interval1(){
    return  window.setInterval(function(){
            if(document.getElementById("addToCart") !=  null){
                added = true;
                window.location = "http://www.footaction.com/checkout/";
            }
            else if(added == false){
                var cartbtn = document.getElementById("addToCartLink");
                cartbtn.click();
            }
        }, 1000);
}

var id1 = interval1();

window.setInterval(function(){
    if(added == true){
        window.clearInterval(id1);
    }
}, 100);
役に立ちましたか?

解決

looks like you are missing the last closing squiggly bracket for window.load event

window.addEventListener('load', function() {

var added = false;

function interval1(){
return  window.setInterval(function(){
        if(document.getElementById("addToCart") !=  null){
            added = true;
            window.location = "http://www.footaction.com/checkout/";
        }
        else if(added == false){
            var cartbtn = document.getElementById("addToCartLink");
            cartbtn.click();
        }
    }, 1000);
}

var id1 = interval1();

window.setInterval(function(){
   if(added == true){
    window.clearInterval(id1);
   }
}, 100);

}; // you were missing this line .. the ending squiggly bracket 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top