【问题标题】:How do you make Greasemonkey Click a link that has specified text?你如何让 Greasemonkey 单击具有指定文本的链接?
【发布时间】:2011-06-29 12:49:27
【问题描述】:

好吧,基本上我想单击一个更改但始终具有相同文本名称的链接。 这是代码可能是什么的示例

<a href="unlock.php?confirm=MD5hashere">Click Here</a>

【问题讨论】:

    标签: javascript hyperlink click greasemonkey


    【解决方案1】:

    这是一个执行此操作的启动脚本。请注意,它使用 jQuery 并假设您正在运行 Firefox 或使用 Tampermonkey,如果您使用的是 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
    


    另见:

    【讨论】:

      【解决方案2】:

      使用 XPath 的 Vanilla JS 版本:

      document.evaluate("//a[text()='Click Here']", document).iterateNext().click()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-20
        相关资源
        最近更新 更多