This code snippet is specifically designed for a shoe website, where it automatically adds the shoe in the desired size to your cart as soon as the page loads.
The "skuAndSize" variable represents the shoe size used by the website. In this case, a selectedIndex value of 7 corresponds to size 10.
var size_i_want = "10";
var how_many = 1;
function addToCart()
{
var sizesList=document.getElementsByName("skuAndSize")[0];
function setSizeValue()
{
document.getElementsByName("skuAndSize")[0].selectedIndex = 7;
}
if(sizesList != undefined)
{
setSizeValue();
document.getElementsByClassName("add-to-cart")[0].click();
}
else
{
setTimeout("addToCart()", 5);
}
}
setTimeout("addToCart()", 5);
Is there a way to optimize this code for faster execution? It is input via a Chrome extension, and below is the manifest.json file. Although it may not directly impact the program's speed, any suggestions for improvement are welcome:
{
"name": "shoe_program",
"version": "1.0",
"manifest_version": 2,
"description": "",
"permissions": [
"tabs",
"contentSettings"
],
"icons": {
"128": "icon.png"
},
"browser_action": {
"default_icon": "icon.png",
"default_title": "SneakerATC extension [SIZE-10]"
},
"content_scripts": [
{
"matches": [
"http://*.nike.com/*"
],
"js": [
"testing.js"
]
}
],
"web_accessible_resources": [
"script.js"
]
}