Here's my custom placeholders BugMonkey script:
name: Custom Placeholders
description: Adds some helpful values to the rgPlaceholders list.
author: Rich Armstrong
version: 1.0.0.4
js:
$(function(){
// if we're not on the case page, don't do anything
if (!$('#bugviewContainer').length) return;
/* To Title Case 1.1.1
* David Gouch <http://individed.com>
* 23 May 2008
* License: http://individed.com/code/to-title-case/license.txt
*
* In response to John Gruber's call for a Javascript version of his script:
* http://daringfireball.net/2008/05/title_case
*/
String.prototype.toTitleCase = function() {
return this.replace(/([\w&`'‘’"“.@:\/\{\(\[<>_]+-? *)/g, function(match, p1, index, title) {
if (index > 0 && title.charAt(index - 2) !== ":" &&
match.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ \-]/i) > -1)
return match.toLowerCase();
if (title.substring(index - 1, index + 1).search(/['"_{(\[]/) > -1)
return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);
if (match.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1 ||
title.substring(index - 1, index + 1).search(/[\])}]/) > -1)
return match;
return match.charAt(0).toUpperCase() + match.substr(1);
});
};
var addCustomPlaceholders = function(){
if (!window.goBug) return;
var oMyFirstName = new Object();
oMyFirstName.sPlaceHolder = "{myfirstname}";
var oMyLastName = new Object();
oMyLastName.sPlaceHolder = "{mylastname}";
var oMyName = new Object();
oMyName.sPlaceHolder = "{myname}";
oMyName.sValue = GetFullName(); // this placeholder already exists as {username}
// I just did this for consistency.
sMyName = GetFullName().match(/(\w+) (\w+)/);
if (sMyName[1]) {
oMyFirstName.sValue = sMyName[1];
oMyLastName.sValue = sMyName[2];
}
rgPlaceHolders.push(oMyFirstName);
rgPlaceHolders.push(oMyLastName);
if (window['goBug'] != undefined) {
if (goBug.sCustomerEmail == "") {
return;
}
var oFirstName = new Object();
oFirstName.sPlaceHolder = "{firstname}";
sFirstName = goBug.sCustomerEmail.match(/^"?(([\w'\-\(\)]+), )?([\w\'\-]+)( [\w'\-\(\)\.]+)*(, [SsJj]r.)?"? <[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,4})?>$/);
if (sFirstName) {
oFirstName.sValue = sFirstName[3].toTitleCase();
} else {
oFirstName.sValue = "[[name]]";
}
rgPlaceHolders.push(oFirstName);
}
} //end function addCustomPlaceholders
addCustomPlaceholders();
});
It adds {name}, {myfirstname}, {mylastname}.
Notes:
- If we don't know the first name, we replace with
[[name]] which will be highlighted for you to replace.
Caveats:
- Not tested in IE. Works in Chrome and Firefox.
- Sometimes when we start typing, this script hasn't run yet.
- Doesn't work with "Last, First" yet.
- Is broken by names with accents in them.
- Only works with snippets, not with autoresponses.
- It pulls from the Correspondent every time. If others chime in, it'll still fill in the correspondent name.