Created
September 9, 2008 06:48
-
-
Save monjudoh/9626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($,templateStr){ | |
var MiniTemplate = function(template){ | |
this.template = eval(['([\'',template.replace(/\$\{([^${}]+)\}/g,'\',{key:\'$1\'},\''),'\'])'].join('')); | |
}; | |
MiniTemplate.prototype.merge = function(context){ | |
var template = this.template || []; | |
var temp = []; | |
for(var i = 0; i < template.length; i++){ | |
if(typeof template[i] == 'string'){ | |
temp.push(template[i]); | |
}else if(typeof template[i] == 'object' && typeof template[i]['key'] == 'string'){ | |
temp.push(context[ template[i]['key'] ]); | |
} | |
} | |
return temp.join(''); | |
} | |
var text = []; | |
var template = new MiniTemplate(templateStr); | |
$('#container .doing tr.hentry:visible') | |
.map(function(){ | |
var entry = $(this); | |
return { | |
statusId:entry.attr('id') | |
,url:entry.find('.entry-date').attr('href') | |
,userId:entry.find('.content strong a').text() | |
,message:$.trim(entry.find('.entry-content').text()) | |
}; | |
}) | |
.get() | |
.sort(function(a,b){ | |
if(a.statusId > b.statusId){ | |
return 1; | |
}else if(b.statusId > a.statusId){ | |
return -1; | |
}else{ | |
return 0; | |
} | |
}).forEach(function(e){ | |
text.push(template.merge(e)); | |
}); | |
copy(text.join('\n')); | |
})(jQuery,'|[${url}:title=${userId}]|${message}|'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment