How do you make Greasemonkey Click a link that has specified text?

前端 未结 1 2032
离开以前
离开以前 2021-01-02 05:00

Alright basically i want to click a link that changes but always has the same text name. Heres an example of what the code might be



        
1条回答
  •  一整个雨季
    2021-01-02 05:18

    Here is a starter script that does that. Note that it uses jQuery and assumes you are running Firefox or using Tampermonkey, if you are on Chrome.

    // ==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
    // @grant    GM_addStyle
    // ==/UserScript==
    /*- The @grant directive is needed to work around a design change
        introduced in GM 1.0.   It restores the sandbox.
    */
    
    //--- Note that the contains() text is case-sensitive.
    var TargetLink = $("a:contains('Click Here')")
    
    if (TargetLink.length)
        window.location.href = TargetLink[0].href
    


    See also:

    • Adding keylistener and using javascript to click a link in Greasemonkey
    • "Normal" button-clicking approaches are not working in Greasemonkey script?
    • Choosing and activating the right controls on an AJAX-driven site

    0 讨论(0)
提交回复
热议问题