This script assists in a checkout process at an online store. All is working correctly, except the need to refresh the page to get the program to run initially.
I wonder if it is a cache problem because it works on other products that have been previously viewed. I also tried tinkering with the @run-at
to no avail. I'm using the Scriptish extension and it is a standalone .js
file.
// ==UserScript==
// @id proper-id
// @name proper-name
// @version 1.0
// @namespace
// @description
// @include proper-url-here
// @include about:blank
// @run-at window-load
// ==/UserScript==
for (var i=0; i<document.getElementsByName("skuAndSize")[0].length; i++){
if(document.getElementsByName("skuAndSize")[0].options[i].text == 11) {
document.getElementsByName("skuAndSize")[0].selectedIndex = i;
}
}
document.getElementsByClassName("button-container add-to-cart")[0].click();
Why does this userscript only run on refresh?