You can actually simplify the logic for the main charms function ( doTargetInfo() ) quite a bit with a regular expression and the knowledge that .replace() can take a function as the second argument: function doTargetInfo(content, TargetList) {
// PARSE FOR TARGET INFO REPLACEMENT CHARMS
var Token = getObj("graphic", TargetList[0]);
if (Token === undefined) return content;
var Character = getObj("character", Token.get("represents"));
// TOKEN CHARMS
return content.replace(/%%(.*?)%%/g,function(m,charm){
var attr;
switch(charm){
case 'token_name':
return Token.get('name');
case 'bar1':
case 'bar2':
case 'bar3':
return Token.get(charm+'_value');
case 'bar1_max':
case 'bar2_max':
case 'bar3_max':
return Token.get(charm);
default:
return (Character && (attr=getAttrByName(Character.id, charm)) && '[['+attr+']]') || 'ERROR';
}
});
}