javascript 如何让 Greasemonkey 单击具有指定文本的链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5036737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you make Greasemonkey Click a link that has specified text?
提问by RayB
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>
回答by Brock Adams
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.
这是一个执行此操作的启动脚本。请注意,它使用 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
See also:
也可以看看:

