show/hide this revision's text 3 Attempted to put in BugMonkey 2.0 format

Here's some sample javascript which can be used to replace text in bug events. I'm currently using this for creating links and replacing long urls with shorter ones within bug events.

In this sample there are two objects which I use as a poor man's replacement for hashes:

  • aRegExps contains regular expressions to match in the text of the bug event
  • aReplacements contains the replacement texts for the corresponding regexps

What these replacements do:

  • svnlink - This replaces a string in the form of SVN#revision with a link to our svn viewVC server
  • shortenlink - Replaces a very long url (we have a lot of those here) with a shorter one (note that this doesn't modify the href in the anchor tag, just the text that is displayed)
  • replaceurl - Replaces one url with another

To add more replacements just add a matching pair of aRegExps and aReplacements objects.

A couple of notes about this sample:

  • The regular expressions in the sample are obviously examples which I replaced before posting here and need to be customized.
  • Remember to escape special characters in the regexps
  • It's grossly untested and probably
  • It has a few nasty bugsbeen mostly tested in Chrome and Firefox. No guarantees on other browsers.

Here's the sample:

Note that you need to edit the below js code to adit/add your keywords and corresponding replacements.

name:          Replace links
description:   Replaces keywords with links in BugEvents
author:        Roman Hernandez
version:       1.0

js:

var aRegExps = new Object();
var aReplacements = new Object();

aRegExps["svnlink"] = RegExp(/SVN#(\d+)/g);
aReplacements["svnlink"] = "<a href=\"http://your.svn.url/viewvc?view=rev&revision=$1\">SVN#$1</a>";

aRegExps["shortenlink"] = RegExp(/>http:\/\/some\.common\.url\/path\?link=something/g);
aReplacements["shortenlink"] = ">SVN#";

aRegExps["replaceurl"] = RegExp(/http:\/\/url\.to\.replace/g);
aReplacements["replaceurl"] = "http://replacement.url.here";

// Find all the bugevent body elements
$("div.body").each(
  function (){
     var content = $(this).html();
     var replace = false;
     for (var key in aRegExps){
       if (aRegExps[key].test(content)){
        replace = true;
        content = content.replace(aRegExps[key], aReplacements[key]);
       }    
     }
     if (replace)
       $(this).html(content);
  }
);    
show/hide this revision's text 2 Original version did not work on IE. Switched sample to use jquery for cross-browser support.

Here's some sample javascript which can be used to replace text in bug events. I'm currently using this for creating links and replacing long urls with shorter ones within bug events.

In this sample there are two objects which I use as a poor man's replacement for hashes:

  • aRegExps contains regular expressions to match in the text of the bug event
  • aReplacements contains the replacement texts for the corresponding regexps

What these replacements do:

  • svnlink - This replaces a string in the form of SVN#revision with a link to our svn viewVC server
  • shortenlink - Replaces a very long url (we have a lot of those here) with a shorter one (note that this doesn't modify the href in the anchor tag, just the text that is displayed)
  • replaceurl - Replaces one url with another

To add more replacements just add a matching pair of aRegExps and aReplacements objects.

A couple of notes about this sample:

  • The regular expressions in the sample are obviously examples which I replaced before posting here and need to be customized.
  • Remember to escape special characters in the regexps
  • It's grossly untested and probably has a few nasty bugs

Here's the sample:

var aRegExps = new Object();
var aReplacements = new Object();

aRegExps["svnlink"] = RegExp(/SVN#(\d+)/g);
aReplacements["svnlink"] = "<a href=\"http://your.svn.url/viewvc?view=rev&revision=$1\">SVN#$1</a>";

aRegExps["shortenlink"] = RegExp(/>http:\/\/some\.common\.url\/path\?link=something/g);
aReplacements["shortenlink"] = ">SVN#";

aRegExps["replaceurl"] = RegExp(/http:\/\/url\.to\.replace/g);
aReplacements["replaceurl"] = "http://replacement.url.here";

// Find all the bugevent body elements
$("div.body").each(
  function (){
     var bugEvents content = document.getElementsByClassName("body");
for(var i=0; i < bugEvents.length; i++){
  //console.log("BugEvent ",i);
  $(this).html();
     var event replace = bugEvents[i]false;
     for (var key in aRegExps){
       if (aRegExps[key].test(event.innerHTML)){
      //console.log("Found match for " + key)aRegExps[key].test(content)){
        replace = true;
        var str content = event.innerHTML.replace(aRegExps[key]content.replace(aRegExps[key], aReplacements[key]);
      event.innerHTML = str;
       }    
     }
     if (replace)
       $(this).html(content);
  }
);    
show/hide this revision's text 1

Here's some sample javascript which can be used to replace text in bug events. I'm currently using this for creating links and replacing long urls with shorter ones within bug events.

In this sample there are two objects which I use as a poor man's replacement for hashes:

  • aRegExps contains regular expressions to match in the text of the bug event
  • aReplacements contains the replacement texts for the corresponding regexps

What these replacements do:

  • svnlink - This replaces a string in the form of SVN#revision with a link to our svn viewVC server
  • shortenlink - Replaces a very long url (we have a lot of those here) with a shorter one (note that this doesn't modify the href in the anchor tag, just the text that is displayed)
  • replaceurl - Replaces one url with another

To add more replacements just add a matching pair of aRegExps and aReplacements objects.

A couple of notes about this sample:

  • The regular expressions in the sample are obviously examples which I replaced before posting here and need to be customized.
  • Remember to escape special characters in the regexps
  • It's grossly untested and probably has a few nasty bugs

Here's the sample:

var aRegExps = new Object();
var aReplacements = new Object();

aRegExps["svnlink"] = RegExp(/SVN#(\d+)/g);
aReplacements["svnlink"] = "<a href=\"http://your.svn.url/viewvc?view=rev&revision=$1\">SVN#$1</a>";

aRegExps["shortenlink"] = RegExp(/>http:\/\/some\.common\.url\/path\?link=something/g);
aReplacements["shortenlink"] = ">SVN#";

aRegExps["replaceurl"] = RegExp(/http:\/\/url\.to\.replace/g);
aReplacements["replaceurl"] = "http://replacement.url.here";

// Find all the bugevent body elements
var bugEvents = document.getElementsByClassName("body");
for(var i=0; i < bugEvents.length; i++){
  //console.log("BugEvent ",i);
  var event = bugEvents[i];
  for (var key in aRegExps){
    if (aRegExps[key].test(event.innerHTML)){
      //console.log("Found match for " + key);
      var str = event.innerHTML.replace(aRegExps[key], aReplacements[key]);
      event.innerHTML = str;
    }    
  }
}