I want to use Greasemonkey to link Redmine issue numbers which are displayed in cgit commit messages to their issues or projects.
The HTML source of the cgit Commit messages is like this.
<a href='/editingmodule/commit/?id=49e4a33e0f8b306ded5'>refs #459 - create separate directory and repo for editingModule, lots of dif...</a>
What I want to do is to make the #459 a separate href to the Redmine issue, but leave retain the cgit links on both sides unchanged. So the URL above is transformed into something like this:
<a href='/editingmodule/commit/?id=49e4a33e0f8b306ded5'>refs</a>
<a href='http://redmine.project.com/redmine/issues/459'>#459</a>
<a href='/editingmodule/commit/?id=49e4a33e0f8b306ded5'> - create separate directory and repo for editingModule, lots of dif...</a>
It may be hard to read but the #459 in the link above is linked to the Redmine project.
The link to the Redmine issue can also be appended to the cgit link for clarity.
Use jQuery to find the links, and regex to extract the key text parts.
Here is a complete working script; see the inline comments for more info: