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

梦想的初衷 提交于 2019-12-18 15:16:56

问题


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

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

回答1:


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


来源:https://stackoverflow.com/questions/5036737/how-do-you-make-greasemonkey-click-a-link-that-has-specified-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!