$.ajaxSetup({
    beforeSend: function(req) {
        console.log("setting headers");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json");
    },
    error: function(req, text, errorThrown) {
        console.log("XHR ERROR: " + text);
    },
    type:"GET",
    dataType: "text"
});

var searchURL = "https://bugzilla.mozilla.org/buglist.cgi?quicksearch=sw:[orange] ";
var bugURL = "https://bugzilla.mozilla.org/show_bug.cgi?id=";

jetpack.tabs.onReady(function(doc){

  // Only run on tinderbox logs
  if(!this.url.match(/showlog.cgi/)) return;

  $(doc).find("a[href^='#err']").each(function() {
      var a = $(this);
      a.text().split(" "). // split error text
              filter(function(a) /\//.test(a)). // filter out lines w/o slashes
              map(function(a) { return a.split("/").pop(); }). // get file name only
      forEach(function(file) {
          $.get(searchURL + file, function(text) {
              var matches = (/\?id=(.*)"/gm).exec(text);
              if (matches) {
                  matches.shift(); // remove full match
                  matches.forEach(function(match) {
                      a.after(" (maybe <a href='" +
                          bugURL + match + "'>bug " + match + "</a>?)<br>");
                  });
              }
          });
          
      });
  });

});

