<commit_before>var google = new OAuth2('google', {
  clientId: '361603295265.apps.googleusercontent.com',
  clientSecret: '<KEY>',
  apiScope: 'https://www.googleapis.com/auth/userinfo.profile'
});

function buildUserData(provider) {
  // Once we have a valid token that has been scoped to userinfo.profile, 
  // we can actually request the data required here.
  $.ajax({
    type: 'GET',
    url: 'https://www.googleapis.com/userinfo/v2/me',
    headers: {'Authorization': 'OAuth ' + provider.getAccessToken()}
  }).done(function(user) {
    var q = {'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT};
    chrome.tabs.query(q, function(tabs) {
      var tile = {'pageURL': tabs[0].url,
        'pageTitle': tabs[0].title,
        'uid': user.id
      };
      var req1 = {type: 'POST', url: 'http://localhost:3000/users', data: user};
      var req2 = {type: 'POST', url: 'http://localhost:3000/tiles', data: tile};
      $.ajax(req1).done(function (data) {
        $.ajax(req2, function() { console.log('bar'); });
      });
    });
  });
}

function checkAuthorized() {
  ['google'].forEach(function(providerName) {
    var provider = window[providerName];
    var button = document.querySelector('#' + providerName);

    if (!localStorage.getItem('linkShareAuth')) {
      var result = buildUserData(provider);
      localStorage.setItem('linkShareAuth', result);
    }

    if (provider.hasAccessToken()) {
      button.classList.add('authorized');
    } else {
      button.classList.remove('authorized');
    }
  });
}

function authorize(providerName) {
  var provider = window[providerName];
  provider.authorize(checkAuthorized);
}

function clearAuthorized() {
  ['google'].forEach(function(providerName) {
    var provider = window[providerName];
    provider.clearAccessToken();
  });
  checkAuthorized();
}


document.addEventListener('DOMContentLoaded', function () {
  authorize('google');
  buildUserData(window.google);
});<commit_msg>Reworked popup.js to use initialization.js<commit_after>// At this point we shoudl just ask for profile information
var google = new OAuth2('google', {
  clientId: Skiplist.providerTokens.google.clientID,
  clientSecret: Skiplist.providerTokens.google.clientSecret,
  apiScope: 'https://www.googleapis.com/auth/userinfo.profile'
});

document.addEventListener('DOMContentLoaded', function () {
  authorize('google');
  buildUserData(window.google);
});
{'fraction_non_alphanumeric': 0.15998346424142207, 'fraction_numerical': 0.011988424968995453, 'mean_word_length': 4.105485232067511, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 3, 'lorem ipsum': 0, 'www.': 3, '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': '5262794', 'n_tokens_mistral': 757, 'n_tokens_neox': 734, 'n_words': 148}