<commit_before>$(document).ready(function(){  
  if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
    alert('There is a problem, please contact us at <EMAIL>');
  }
  
  $('#email').on('input', function() {
      $('#contact img').attr('src', "http://www.gravatar.com/avatar/"+md5($(this).val())+"?s=200");
  });
  
  $('#save, #save_no_img').on('click', function(event){
    //Stop form submittion
    event.preventDefault();
    
    var name = $('#name').val();
    var phone = $('#phone').val();
    var email = $('#email').val();
    var imgURL = $('#contact img').attr('src');
    
    var data = {
      name: name,
      phone: phone,
      email: email,
      imgURL: imgURL
    };
    
    if ($(this).attr('id') == 'save_no_img') {
      data.imgURL = null;
    }
    
    saveContact(data);
  });
});

function saveContact(data, blob){
  var person = new mozContact();
  person.name  = [data.name];
  person.givenName = [data.name];
  
  person.tel = [];
  person.tel[0]  = {type:['mobile'], value:data.phone};
  
  person.email = [];
  person.email[0]  = {type:['work'], value:data.email};
  
  if (data.imgURL) {
    var oReq = new XMLHttpRequest();
//     console.log(oReq);
    oReq.onload = function (e) {
//       console.log(0, person);
//       console.log(this.response);
      var arrayBufferView = new Uint8Array(this.response);
      person.photo  = [];
      person.photo[0] = new Blob([arrayBufferView], {type: 'image/png'});
//       console.log(1, person);
      savePerson(person)
    };

    oReq.onerror = function (e) {
      alert('Error could not get your contact image');
      $('#save_no_img').attr('style','display:table');
    }

    oReq.open("GET", data.imgURL, true);
    oReq.responseType = "arraybuffer";
    oReq.send();
  } else {
    savePerson(person)
  }
  
  
//   console.log(2, person);
}

function savePerson(person) {
  // save the new contact
  var saving = navigator.mozContacts.save(person);

  saving.onsuccess = function() {
    alert('New contact saved');
    init();
  };

  saving.onerror = function(err) {
    alert('Error: ' + err);
  };
}

function init() {
  $('#contact input').val(null);
  $('#save_no_img').hide();
}<commit_msg>v 0.3 save without image<commit_after>$(document).ready(function(){  
  if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
    alert('There is a problem, please contact us at <EMAIL>');
  }
  
  $('#email').on('input', function() {
      $('#contact img').attr('src', "http://www.gravatar.com/avatar/"+md5($(this).val())+"?s=200");
  });
  
  $('#save, #save_no_img').on('click', function(event){
    //Stop form submittion
    event.preventDefault();
    
    var name = $('#name').val();
    var phone = $('#phone').val();
    var email = $('#email').val();
    var imgURL = $('#contact img').attr('src');
    
    var data = {
      name: name,
      phone: phone,
      email: email,
      imgURL: imgURL
    };
    
    if ($(this).attr('id') == 'save_no_img') {
      data.imgURL = null;
    }
    
    saveContact(data);
  });
});

function saveContact(data, blob){
  var person = new mozContact();
  person.name  = [data.name];
  person.givenName = [data.name];
  
  person.tel = [];
  person.tel[0]  = {type:['mobile'], value:data.phone};
  
  person.email = [];
  person.email[0]  = {type:['work'], value:data.email};
  
  if (data.imgURL) {
    var oReq = new XMLHttpRequest();
//     console.log(oReq);
    oReq.onload = function (e) {
//       console.log(0, person);
//       console.log(this.response);
      var arrayBufferView = new Uint8Array(this.response);
      person.photo  = [];
      person.photo[0] = new Blob([arrayBufferView], {type: 'image/png'});
//       console.log(1, person);
      savePerson(person)
    };

    oReq.onerror = function (e) {
      alert('Error could not get your contact image');
      $('#save_no_img').attr('style','display:table');
    }

    oReq.open("GET", data.imgURL, true);
    oReq.responseType = "arraybuffer";
    oReq.send();
  } else {
    savePerson(person)
  }
  
  
//   console.log(2, person);
}

function savePerson(person) {
  // save the new contact
  var saving = navigator.mozContacts.save(person);

  saving.onsuccess = function() {
    alert('New contact saved');
    init();
  };

  saving.onerror = function(err) {
    console.log(err.target.error);
    if (err.target.error.message) {
     alert('Error: ' + err.target.error.message);
    } else if (err.target.error.name == 'PERMISSION_DENIED') {
     alert('Error: We need your permission to add new contact, please allow the app to add contacts');
    } else {
      alert('Error, Please contact us at <EMAIL>');
    }
  };
}

function init() {
  $('#contact input').val(null);
  $('#save_no_img').hide();
}
{'fraction_non_alphanumeric': 0.19629707553124343, 'fraction_numerical': 0.015148327372185988, 'mean_word_length': 2.899917965545529, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1133715', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1639, 'n_words': 322}