This is a classic issue with pages that change their content through AJAX.
@run-at no effect, because the target content loads long after the load event. And the "new" pages are actually being rewritten through AJAX - until you refresh the page, at least.
Change the script to @run-at document-end (or omit the line), and then, depending on the landing page and how you use it, it may be enough to disable hashchange , as shown in "I need to refresh the page for my Greasemonkey script to run? " or as shown in this other answer .
waitForKeyElements Tool More . Your script may be as simple as:
// ==UserScript== // @name _YOUR_SCRIPT_NAME // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // ==/UserScript== waitForKeyElements ("[name='skuAndSize']", setSizeIndex); waitForKeyElements (".button-container.add-to-cart", clickAddToCart); function setSizeIndex (jNode) { var node = jNode[0]; for (var J = node.options.length - 1; J >= 0; --J) { if (node.options[J].text == "11") { node.selectedIndex = J; break; } } } function clickAddToCart (jNode) { var clickEvent = document.createEvent ('MouseEvents'); clickEvent.initEvent ('click', true, true); jNode[0].dispatchEvent (clickEvent); }
See Also, “Selecting and Activating the Right Controls on an AJAX-Managed Site” .
Brock adams
source share