How do you do Greasemonkey Click the link with the specified text?

In general, I want to click a link that changes, but always has the same text name. Here is a sample code

<a href="unlock.php?confirm=MD5hashere">Click Here</a> 
+6
javascript greasemonkey hyperlink click
source share
1 answer

Here is a starter script that does this. Please note that it uses jQuery and assumes you are using Firefox or using Tampermonkey if you are in 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 a keylistener and using javascript to link to a link in Greasemonkey
  • "Normal" mouse buttons do not work in Greasemonkey script?
  • Choosing and Activating the Right Controls on an AJAX-Managed Site
+9
source share

All Articles