Injecting Greasemonkey Script Multiple Times on the Same Page
For users new to Greasemonkey and JavaScript, a common requirement arises where a userscript needs to be executed multiple times without a page refresh. This scenario becomes essential when a request, such as an Amazon search, occurs using Ajax without triggering a complete page reload.
Solution: Utilizing waitForKeyElements() Utility
To address this need effectively, the waitForKeyElements() utility offers a robust and simple solution. This utility monitors a specified element and executes a callback function whenever the element's content changes. Below is a complete script that leverages jQuery and waitForKeyElements to modify Amazon search results:
// @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== function addCustomSearchResult (jNode) { jNode.prepend ( '<div>
Implementation Details:
Using this solution, you can now execute your Greasemonkey script multiple times on the same page without a refresh, providing you with greater flexibility and control over your browser interactions.
以上が更新せずに同じページで Greasemonkey スクリプトを複数回実行するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。