Friday, 9 August 2013

Need a few extra lines of code in a Chrome Extension?

Need a few extra lines of code in a Chrome Extension?

I actually saw this question come up once before on the site (Nike Updated
website and my script isn't working?), but it closed cause the guy wasn't
asking specific questions; let me break it down for y'all.
So there's been a Chrome extension that's been floating around that
automatically added specified sizes and quantities of whatever Nike shoe
link you opened to your cart as soon as you visited the site. The coding
is as follows:
var size_i_want = "9.5";
var how_many = 1;
function addToCart() {
var sizesList=document.getElementsByName("skuAndSize")[0];
function setQuantity() {
document.getElementsByName("qty")[0].selectedIndex = how_many-1;
}
function setSizeValue() {
for (var i=0; i<sizesList.length; i++){
if(sizesList.options[i].text == size_i_want) {
document.getElementsByName("skuAndSize")[0].selectedIndex = i;
setQuantity();
}
}
}
if(sizesList != undefined) {
setSizeValue();
document.getElementsByClassName("button-container
add-to-cart")[0].click();
} else {
setTimeout("addToCart()", 250);
}
}
setTimeout("addToCart()", 250);
While I'm not really a code guy, I can assume from looking at the code
that skuAndSize is size and the variable you control is size_i_want, etc,
same goes for quantity with how_many, blah blah.
Now Nike recently updated the website, changing the layout and cart
system, as well as changing up the way the size and quantity selection
works. Now the code is inept. That is, it no longer does anything, but I
can't identify what was added to the site to cause the code to become more
useless than a chicken with a million dollars. From a few members on a
forum I frequent (who decided they'd rather be trivial than helpful), they
mentioned that it only took a couple code lines to fix the code, and that
the old code might not necessarily need editing.
So I took a look at the site code, particularly the size and quantity
selection portion:

I'm pretty sure the culprit is skuID, but hey. I'm not particularly
bright. I'm also totally devoid of coding knowledge. If it's not too much
trouble, could anyone shed some light, or at least give me a
not-so-cryptic point in the correct direction?

No comments:

Post a Comment