Searching an issue on drupal.org with jQuery.grep
Submitted by clemens on Sun, 2011/07/17 - 2:44pm
On http://drupal.org/node/686938 people are reporting a lot sloppy reports of error lines. The issue is about
Undefined index: [xyz] in line ...
But what are the names of the failing indexes?
jQuery has a nice grep so lets use it.
/* We only want lines containing "Undefined index:"*/
var lines = jQuery.grep($('body').text().split("\n"), function(value, i) {
return value.indexOf("Undefined index:") >=0
});
// Sort the lines
lines.sort();
// Filter on unique values
var last="";
lines =jQuery.grep(lines, function(value,i) {
if(value != last) {
last=value; return true}
}
);
// Grep the index names and push them on our list
var list = [];
$(lines).each(function(){
var n=this.match( /Undefined index: (\w*)/);
if (n) list.push(n[1]);
});
list.sort();
last="";
list = jQuery.grep( list, function(value,i) {
if(value != last) {
last=value; return true}
}
);
// Stuff it into comment field
var result = list.join("\n");
$('#edit-comment').val(result);
Add new comment