mardi 5 mai 2015

How to buy something on Amazon when it goes below a certain price (using tampermonkey + javascript)

I am attempting to buy a product when it gets restocked on amazon and will therefore be back down to its retail value.

Here is how I am considering doing it but am not sure if the price can easily be detected and determined if it is below a certain number. (I have also never really used javascript before, I'm more familiar with java/c++)

    // ==UserScript==
    // @name Amazon restock buyer
    // @description Refreshes current page until price is below $14 (retail is 12.99) and performs 1 click purchase
    // @include http://ift.tt/1c3gmSB
    // @version 1
    // @grant none
    // ==/UserScript==

    var time = 8000; //number of milliseconds to wait before refreshing. Default = 40 seconds.

    function refresh() {
      location.reload(true); //reload, bypass cache.
    }

    price = document.querySelector(".priceLarge);
    button = document.querySelector(".s_bbBuyNow1Click");
    if (button !== null && price < $14.00) {
      alert("IT'S HAPPENING!!");
      button.click();
    }
   else {
     setTimeout(refresh, time);
    }

I have another script that I got elsewhere to run which is similar except it is to pre order an item, so all it has to do is hit the one click button. The new and needed additions are setting the price variable and doing the and boolean check of whether the price is under 14. What I'm unsure about (and can't/don't want to test in fear of buying it for $50 from a scalper) is if it will properly locate the price value and be able to treat it as a number and easily do the less than check.

Thanks.




Aucun commentaire:

Enregistrer un commentaire