<commit_before>function $(x) {
  return document.getElementById(x);
}

var email = '',
api_key = '';

function load() {
  chrome.storage.sync.get(["b_email","b_api_key"],function(date){
    $('email').value = (date.b_email ? date.b_email : '');
    $('api_key').value = (date.b_api_key ? date.b_api_key : '<KEY>');
  });
  console.log('body loaded.');
}

function save() {
  chrome.storage.sync.set({"b_email": $('email').value, "b_api_key": $('api_key').value}, function() {
    console.log('saved.');
  });
}

function notify(text) {
  if(window.webkitNotifications) {
    if(window.webkitNotifications.checkPermission() > 0) {
      RequestPermission(notify);
    } else {
      var notification = webkitNotifications.createNotification(
        './48.png',
        'Sended',
        text
      );
      notification.ondisplay = function() {
        setTimeout('notification.cancel()', 5000);
      };
      notification.show();
    }
  }
}

function RequestPermission(callback) {
  window.webkitNotifications.requestPermission(callback);
}

function boxcar(sendmessage) {
  console.log('hah');
  var message = (sendmessage ? sendmessage : document.getElementById('message').value);

  var req = new XMLHttpRequest();
  req.onreadystatechange = function() {
    // TODO: do sth here based on failure/success.
    if (req.readyState == 4){
      // 4 = "loaded"
      if (req.status == 200) {
        console.log('Send it.');
        // notify(message).show();
        // background 不能触发 show() !?
      }
      else if(req.status == 400){
        console.log('No application/event defined');
      }
      else if(req.status == 401){
        console.log('Invalid username/password');
      }
    }
  };
  chrome.storage.sync.get(["b_email","b_api_key"], function(date){
    // email= (date.b_email ? date.b_email : chrome.tabs.create({url: "options.html#email"}));
    // api_key = (date.b_api_key ? date.b_api_key : chrome.tabs.create({url: "options.html#email"}));
    email= (date.b_email ? date.b_email : window.open({url: "options.html#email"}));
    api_key = (date.b_api_key ? date.b_api_key : window.open({url: "options.html#email"}));
    
    var params = 'email=' + email + '&notification[from_screen_name]=Chrome&notification[message]=' + message;
    req.open('POST', 'http://boxcar.io/devices/providers/' + api_key + '/notifications?' + params, true);
    req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req.send(params);
  });
  // $('console').innerHTML = 'send it!';
}

chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
  if(request.greeting == "hello") {
    boxcar(request.text);
    console.log(request.text);
  }
});<commit_msg>change chrome.tabs.create and XMLHttpRequest method<commit_after>function $(x) {
  return document.getElementById(x);
}

var email = '',
api_key = '';

function load() {
  chrome.storage.sync.get(["b_email","b_api_key"],function(date){
    $('email').value = (date.b_email ? date.b_email : '');
    $('api_key').value = (date.b_api_key ? date.b_api_key : '<KEY>');
  });
  console.log('body loaded.');
}

function save() {
  chrome.storage.sync.set({"b_email": $('email').value, "b_api_key": $('api_key').value}, function() {
    console.log('saved.');
  });
}

function notify(text) {
  if(window.webkitNotifications) {
    if(window.webkitNotifications.checkPermission() > 0) {
      RequestPermission(notify);
    } else {
      var notification = webkitNotifications.createNotification(
        './48.png',
        'Sended',
        text
      );
      notification.ondisplay = function() {
        setTimeout('notification.cancel()', 5000);
      };
      notification.show();
    }
  }
}

function RequestPermission(callback) {
  window.webkitNotifications.requestPermission(callback);
}

function boxcar(sendmessage) {
  var message = (sendmessage ? sendmessage : document.getElementById('message').value);
  console.log("boxcar:" + message);

  var req = new XMLHttpRequest();
  chrome.storage.sync.get(["b_email","b_api_key"], function(date){
    var email_page = chrome.extension.getURL('options.html#email');
    var api_key_page = chrome.extension.getURL('options.html#email');
    console.log(email_page);
    // email= (date.b_email ? date.b_email : chrome.tabs.create({url: page}));
    email= (date.b_email ? date.b_email : window.open(email_page, "popup"));
    api_key= (date.b_api_key ? date.b_api_key : window.open(api_key_page, "popup"));
    console.log(api_key);
    
    var params = 'email=' + email + '&notification[from_screen_name]=Chrome&notification[message]=' + message;
    req.open('POST', 'http://boxcar.io/devices/providers/' + api_key + '/notifications', true);
    req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    req.onreadystatechange = function() {
      // TODO: do sth here based on failure/success.
      if (req.readyState == 4){
        // 4 = "loaded"
        if (req.status == 200) {
          console.log('Send it.');
          // notify(message).show();
          // background 不能触发 show() !?
        }
        // else if(req.status == 400){
        //   console.log('No application/event defined');
        // }
        // else if(req.status == 401){
        //   console.log('Invalid username/password');
        // }
      }
    };
    req.send(params);
  });
  // $('console').innerHTML = 'send it!';
}

chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
  if(request.greeting == "hello") {
    boxcar(request.text);
    console.log(request.text);
  }
});
{'fraction_non_alphanumeric': 0.17962034383954154, 'fraction_numerical': 0.0064469914040114614, 'mean_word_length': 3.3261037955073585, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, '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': '7166705', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1799, 'n_words': 291}