Executing Greasemonkey Scripts Multiple Times on the Same Page
In this inquiry, a novice user seeks guidance on running a Greasemonkey script multiple times on the same page, without the need for page refresh. They desire to insert custom elements into Amazon.com search results as they appear dynamically via Ajax.
Solution: Leveraging waitForKeyElements() Utility
The most effective approach for this task involves utilizing the waitForKeyElements() utility, which monitors for specific HTML elements to become available on the page. Here's a complete script that demonstrates how to implement this technique with jQuery and waitForKeyElements():
// ==UserScript== // @name _Amazon Search, alter results // @include http://www.amazon.com/s/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a design change introduced in GM 1.0. It restores the sandbox. */ function addCustomSearchResult(jNode) { //***** YOUR CODE HERE ***** jNode.prepend("<div>
In this script:
Upon execution, the script will inject custom content into the search results whenever they appear, fulfilling the requirement of running the same script multiple times on the same page without refresh.
The above is the detailed content of How do I execute a Greasemonkey script multiple times on the same page without refreshing, specifically for dynamically generated content on Amazon.com search results?. For more information, please follow other related articles on the PHP Chinese website!