<commit_before><!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="underscore-min.js"></script>
    <script type="text/javascript" src="coffee-script.js"></script>
    <script type="text/coffeescript">

      $.ajaxSetup
        crossDomain: true
        dataType: 'json'

      class Fetcher

        totalPR: 0

        accessToken: null

        repositories: []

        port: null

        constructor: ->
          @accessToken = localStorage.getItem('accessToken')

          @port = chrome.extension.connect name: 'connection'

          chrome.extension.onConnect.addListener (port) =>
            port.onMessage.addListener (msg) =>
              console.log msg
              @fetch(port) if msg.refresh?

        fetch: (port = null) ->
          @totalPR = 0
          @repositories = JSON.parse(localStorage.getItem('repositories'))

          dfds = []
          _(@repositories).each (repo) =>
            dfds.push $.ajax
              type: 'get'
              url: "https://api.github.com/repos/#{repo}/pulls?access_token=#{@accessToken}"
              success: (data) =>
                @store(repo, data)
              error: =>
                debugger

          $.when.apply($, dfds).done =>
            if port
              port.postMessage success: true

        store: (repo, data) ->
          repos = JSON.parse(localStorage.getItem('repos')) or {}
          repos[repo] = data
          localStorage.setItem('repos', JSON.stringify(repos))
          @totalPR += data.length
          @updateBadge()

        updateBadge: =>
          if @totalPR > 0
            chrome.browserAction.setBadgeText text: "#{@totalPR}"
          else
            chrome.browserAction.setBadgeText text: ''

      fetcher = new Fetcher<commit_msg>Moved access token loading to the right place<commit_after><!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="underscore-min.js"></script>
    <script type="text/javascript" src="coffee-script.js"></script>
    <script type="text/coffeescript">

      $.ajaxSetup
        crossDomain: true
        dataType: 'json'

      class Fetcher

        totalPR: 0

        accessToken: null

        repositories: []

        port: null

        constructor: ->

          @port = chrome.extension.connect name: 'connection'

          chrome.extension.onConnect.addListener (port) =>
            port.onMessage.addListener (msg) =>
              console.log msg
              @fetch(port) if msg.refresh?

        fetch: (port = null) ->
          @totalPR = 0
          @accessToken = localStorage.getItem('accessToken')
          @repositories = JSON.parse(localStorage.getItem('repositories'))

          dfds = []
          _(@repositories).each (repo) =>
            dfds.push $.ajax
              type: 'get'
              url: "https://api.github.com/repos/#{repo}/pulls?access_token=#{@accessToken}"
              success: (data) =>
                @store(repo, data)
              error: =>
                debugger

          $.when.apply($, dfds).done =>
            if port
              port.postMessage success: true

        store: (repo, data) ->
          repos = JSON.parse(localStorage.getItem('repos')) or {}
          repos[repo] = data
          localStorage.setItem('repos', JSON.stringify(repos))
          @totalPR += data.length
          @updateBadge()

        updateBadge: =>
          if @totalPR > 0
            chrome.browserAction.setBadgeText text: "#{@totalPR}"
          else
            chrome.browserAction.setBadgeText text: ''

      fetcher = new Fetcher
{'fraction_non_alphanumeric': 0.13090128755364808, 'fraction_numerical': 0.003218884120171674, 'mean_word_length': 1.8509174311926606, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '1251010', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1030, 'n_words': 206}