Run Greasemonkey script on the same page, multiple times?

前端 未结 2 1745
一生所求
一生所求 2020-11-22 06:00

I\'m totally new to Greasemonkey, javascript, in fact all the UI stuff.

Requirement: Userscript is run by GS once after the page loads. However, I need the same scr

2条回答
  •  猫巷女王i
    2020-11-22 06:30

    The simplest, most robust way is to use the waitForKeyElements() utility.

    Here is a complete script that uses jQuery and waitForKeyElements to alter Amazon search results:

    // ==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 (
            '
    Buy my stuff, instead!
    ' ); } waitForKeyElements ("#atfResults", addCustomSearchResult);

提交回复
热议问题