{"action":"created","comment":{"url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/comments/90672295","pull_request_review_id":11191779,"id":90672295,"diff_hunk":"@@ -1,79 +1,107 @@\n-username = \"\";\n+var username = \"\";\n \n+/**\n+ * Grab the user from github\n+ * Then parse the response html with the DOMParser to extract the username\n+ * @param callback if it's set, it will be executed after the username is retrieved.\n+ */\n function get_username(callback) {\n-    var url = \"https://github.com/\";\n-    var xhr = new XMLHttpRequest();\n-    xhr.onreadystatechange = function(){\n-        if (xhr.readyState == 4) {\n+    request('get', \"https://github.com\")\n+        .then(function(res) {\n             var parser = new DOMParser();\n-            var dom = parser.parseFromString(xhr.responseText, \"text/html\");\n+            var dom = parser.parseFromString(res.responseText, \"text/html\");\n             parse_username(dom);\n-            if (callback) {\n-                callback();\n-            }\n-        }\n-    };\n-    xhr.open(\"GET\", url, true);\n-    xhr.send();\n+        })\n+        .then(callback);\n }\n-\n+/**\n+ * Get the username from a meta tag named user-login.\n+ */\n function parse_username(content) {\n     var user_meta = content.getElementsByName(\"user-login\");\n     username = user_meta[0].getAttribute('content');\n }\n-\n+/**\n+ * This method will create a canvas later to be used as the icon in\n+ * the chrome menu. Once created, it will set the image data for chrome.\n+ * @param color A hexadecimal color formatted in hex.\n+ * @param contributions The number of contributions for a given day.\n+ */\n function draw(color, contributions) {\n-  var canvas = document.createElement('canvas');\n-  canvas.width = 19;\n-  canvas.height = 19;\n+    var canvas = document.createElement('canvas');\n+    canvas.width = 19;\n+    canvas.height = 19;\n \n-  var context = canvas.getContext('2d');\n-  context.fillStyle = color;\n-  context.fillRect(0, 0, 19, 19);\n+    var context = canvas.getContext('2d');\n+    context.fillStyle = color;\n+    context.fillRect(0, 0, 19, 19);\n \n-  color_hex = parseInt(\"0x\" + color.slice(1));\n-  if (color_hex < 0x44a340) {\n-      text_color = \"#FFFFFF\";\n-  } else {\n-      text_color = \"#000000\";\n-  }\n-  context.fillStyle = text_color;\n-  context.textAlign = \"center\";\n-  context.textBaseline = \"middle\";\n-  context.font = \"11px Arial\";\n-  context.fillText(contributions, 10, 10);\n+    var color_hex = parseInt(\"0x\" + color.slice(1));\n+    // Ternary operator to determine the fill style.\n+    context.fillStyle = color_hex < 0x44a340 ? \"#FFFFFF\" : \"#000000\";\n+    context.textAlign = \"center\";\n+    context.textBaseline = \"middle\";\n+    context.font = \"11px Arial\";\n+    context.fillText(contributions, 10, 10);\n \n-  chrome.browserAction.setIcon({\n-    imageData: context.getImageData(0, 0, 19, 19)\n-  });\n+    chrome.browserAction.setIcon({\n+        imageData: context.getImageData(0, 0, 19, 19)\n+    });\n }\n \n+/**\n+ * Handle the contributions data by parsing through the temporary dom\n+ * Then calls draw to build the icon for the extension icon\n+ * @param response_dom\n+ */\n function handle_contrib_data(response_dom) {\n     var weeks = response_dom.getElementsByTagName(\"g\");\n-    weeks = weeks[weeks.length-1];\n+    weeks = weeks[weeks.length - 1];\n     var days = weeks.getElementsByTagName(\"rect\");\n-    var last_day = days[days.length-1];\n+    var last_day = days[days.length - 1];\n \n     var todays_contributions = last_day.getAttribute(\"data-count\");\n     var color = last_day.getAttribute(\"fill\");\n     draw(color, todays_contributions);\n }\n \n-\n+/**\n+ * Get the contributions for the given user and parse the data\n+ */\n function get_contrib() {\n-    console.log(username);\n-    var contrib_url = \"https://github.com/users/\" + username + \"/contributions\";\n-    var xhr = new XMLHttpRequest();\n-    xhr.onreadystatechange = function(){\n-        if (xhr.readyState == 4) {\n+    request('get', \"https://github.com/users/\" + username + \"/contributions\")\n+        .then(function (xhr) {\n+            console.log(username);\n+\n             var parser = new DOMParser();\n             var dom = parser.parseFromString(xhr.responseText, \"text/html\");\n             handle_contrib_data(dom);\n-        }\n-    };\n-    xhr.open(\"GET\", contrib_url, true);\n-    xhr.send();\n+        });\n }\n \n+/**\n+ * Make AJax request and call closure when ready.","path":"extension/background.js","position":130,"original_position":130,"commit_id":"c24975ccdf23a6cf34a27a581f1813bb0a06611e","original_commit_id":"c24975ccdf23a6cf34a27a581f1813bb0a06611e","user":{"login":"daspecster","id":192456,"avatar_url":"https://avatars.githubusercontent.com/u/192456?v=3","gravatar_id":"","url":"https://api.github.com/users/daspecster","html_url":"https://github.com/daspecster","followers_url":"https://api.github.com/users/daspecster/followers","following_url":"https://api.github.com/users/daspecster/following{/other_user}","gists_url":"https://api.github.com/users/daspecster/gists{/gist_id}","starred_url":"https://api.github.com/users/daspecster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daspecster/subscriptions","organizations_url":"https://api.github.com/users/daspecster/orgs","repos_url":"https://api.github.com/users/daspecster/repos","events_url":"https://api.github.com/users/daspecster/events{/privacy}","received_events_url":"https://api.github.com/users/daspecster/received_events","type":"User","site_admin":false},"body":"`/AJax/AJAX or Ajax or ajax`?","created_at":"2016-12-02T16:22:16Z","updated_at":"2016-12-02T16:25:20Z","html_url":"https://github.com/daspecster/github-contributions-chrome-extension/pull/1#discussion_r90672295","pull_request_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/comments/90672295"},"html":{"href":"https://github.com/daspecster/github-contributions-chrome-extension/pull/1#discussion_r90672295"},"pull_request":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1","id":96225443,"html_url":"https://github.com/daspecster/github-contributions-chrome-extension/pull/1","diff_url":"https://github.com/daspecster/github-contributions-chrome-extension/pull/1.diff","patch_url":"https://github.com/daspecster/github-contributions-chrome-extension/pull/1.patch","issue_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues/1","number":1,"state":"open","locked":false,"title":"Add some comments for background.js","user":{"login":"austinkregel","id":5355937,"avatar_url":"https://avatars.githubusercontent.com/u/5355937?v=3","gravatar_id":"","url":"https://api.github.com/users/austinkregel","html_url":"https://github.com/austinkregel","followers_url":"https://api.github.com/users/austinkregel/followers","following_url":"https://api.github.com/users/austinkregel/following{/other_user}","gists_url":"https://api.github.com/users/austinkregel/gists{/gist_id}","starred_url":"https://api.github.com/users/austinkregel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinkregel/subscriptions","organizations_url":"https://api.github.com/users/austinkregel/orgs","repos_url":"https://api.github.com/users/austinkregel/repos","events_url":"https://api.github.com/users/austinkregel/events{/privacy}","received_events_url":"https://api.github.com/users/austinkregel/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-02T05:49:49Z","updated_at":"2016-12-02T16:25:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ad4f0da258f4a55d5cbffc62da23fab83d8774b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1/commits","review_comments_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1/comments","review_comment_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/comments{/number}","comments_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues/1/comments","statuses_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/statuses/c24975ccdf23a6cf34a27a581f1813bb0a06611e","head":{"label":"austinkregel:patch-1","ref":"patch-1","sha":"c24975ccdf23a6cf34a27a581f1813bb0a06611e","user":{"login":"austinkregel","id":5355937,"avatar_url":"https://avatars.githubusercontent.com/u/5355937?v=3","gravatar_id":"","url":"https://api.github.com/users/austinkregel","html_url":"https://github.com/austinkregel","followers_url":"https://api.github.com/users/austinkregel/followers","following_url":"https://api.github.com/users/austinkregel/following{/other_user}","gists_url":"https://api.github.com/users/austinkregel/gists{/gist_id}","starred_url":"https://api.github.com/users/austinkregel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinkregel/subscriptions","organizations_url":"https://api.github.com/users/austinkregel/orgs","repos_url":"https://api.github.com/users/austinkregel/repos","events_url":"https://api.github.com/users/austinkregel/events{/privacy}","received_events_url":"https://api.github.com/users/austinkregel/received_events","type":"User","site_admin":false},"repo":{"id":75362795,"name":"github-contributions-chrome-extension","full_name":"austinkregel/github-contributions-chrome-extension","owner":{"login":"austinkregel","id":5355937,"avatar_url":"https://avatars.githubusercontent.com/u/5355937?v=3","gravatar_id":"","url":"https://api.github.com/users/austinkregel","html_url":"https://github.com/austinkregel","followers_url":"https://api.github.com/users/austinkregel/followers","following_url":"https://api.github.com/users/austinkregel/following{/other_user}","gists_url":"https://api.github.com/users/austinkregel/gists{/gist_id}","starred_url":"https://api.github.com/users/austinkregel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinkregel/subscriptions","organizations_url":"https://api.github.com/users/austinkregel/orgs","repos_url":"https://api.github.com/users/austinkregel/repos","events_url":"https://api.github.com/users/austinkregel/events{/privacy}","received_events_url":"https://api.github.com/users/austinkregel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/austinkregel/github-contributions-chrome-extension","description":"This extension will show the number of your GitHub contributions for today.","fork":true,"url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension","forks_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/forks","keys_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/keys{/key_id}","collaborators_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/teams","hooks_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/hooks","issue_events_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/issues/events{/number}","events_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/events","assignees_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/assignees{/user}","branches_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/branches{/branch}","tags_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/tags","blobs_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/git/refs{/sha}","trees_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/git/trees{/sha}","statuses_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/statuses/{sha}","languages_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/languages","stargazers_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/stargazers","contributors_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/contributors","subscribers_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/subscribers","subscription_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/subscription","commits_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/commits{/sha}","git_commits_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/git/commits{/sha}","comments_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/comments{/number}","issue_comment_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/issues/comments{/number}","contents_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/contents/{+path}","compare_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/compare/{base}...{head}","merges_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/merges","archive_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/downloads","issues_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/issues{/number}","pulls_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/pulls{/number}","milestones_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/milestones{/number}","notifications_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/labels{/name}","releases_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/releases{/id}","deployments_url":"https://api.github.com/repos/austinkregel/github-contributions-chrome-extension/deployments","created_at":"2016-12-02T05:10:50Z","updated_at":"2016-12-02T05:10:51Z","pushed_at":"2016-12-02T06:37:11Z","git_url":"git://github.com/austinkregel/github-contributions-chrome-extension.git","ssh_url":"git@github.com:austinkregel/github-contributions-chrome-extension.git","clone_url":"https://github.com/austinkregel/github-contributions-chrome-extension.git","svn_url":"https://github.com/austinkregel/github-contributions-chrome-extension","homepage":null,"size":7,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"daspecster:master","ref":"master","sha":"5e248686231ed5fd7c3566b4c60b5cbbbfdbdc30","user":{"login":"daspecster","id":192456,"avatar_url":"https://avatars.githubusercontent.com/u/192456?v=3","gravatar_id":"","url":"https://api.github.com/users/daspecster","html_url":"https://github.com/daspecster","followers_url":"https://api.github.com/users/daspecster/followers","following_url":"https://api.github.com/users/daspecster/following{/other_user}","gists_url":"https://api.github.com/users/daspecster/gists{/gist_id}","starred_url":"https://api.github.com/users/daspecster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daspecster/subscriptions","organizations_url":"https://api.github.com/users/daspecster/orgs","repos_url":"https://api.github.com/users/daspecster/repos","events_url":"https://api.github.com/users/daspecster/events{/privacy}","received_events_url":"https://api.github.com/users/daspecster/received_events","type":"User","site_admin":false},"repo":{"id":75362379,"name":"github-contributions-chrome-extension","full_name":"daspecster/github-contributions-chrome-extension","owner":{"login":"daspecster","id":192456,"avatar_url":"https://avatars.githubusercontent.com/u/192456?v=3","gravatar_id":"","url":"https://api.github.com/users/daspecster","html_url":"https://github.com/daspecster","followers_url":"https://api.github.com/users/daspecster/followers","following_url":"https://api.github.com/users/daspecster/following{/other_user}","gists_url":"https://api.github.com/users/daspecster/gists{/gist_id}","starred_url":"https://api.github.com/users/daspecster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daspecster/subscriptions","organizations_url":"https://api.github.com/users/daspecster/orgs","repos_url":"https://api.github.com/users/daspecster/repos","events_url":"https://api.github.com/users/daspecster/events{/privacy}","received_events_url":"https://api.github.com/users/daspecster/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/daspecster/github-contributions-chrome-extension","description":"This extension will show the number of your GitHub contributions for today.","fork":false,"url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension","forks_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/forks","keys_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/keys{/key_id}","collaborators_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/teams","hooks_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/hooks","issue_events_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues/events{/number}","events_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/events","assignees_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/assignees{/user}","branches_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/branches{/branch}","tags_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/tags","blobs_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/git/refs{/sha}","trees_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/git/trees{/sha}","statuses_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/statuses/{sha}","languages_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/languages","stargazers_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/stargazers","contributors_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/contributors","subscribers_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/subscribers","subscription_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/subscription","commits_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/commits{/sha}","git_commits_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/git/commits{/sha}","comments_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/comments{/number}","issue_comment_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues/comments{/number}","contents_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/contents/{+path}","compare_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/compare/{base}...{head}","merges_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/merges","archive_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/downloads","issues_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues{/number}","pulls_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls{/number}","milestones_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/milestones{/number}","notifications_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/labels{/name}","releases_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/releases{/id}","deployments_url":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/deployments","created_at":"2016-12-02T05:02:28Z","updated_at":"2016-12-02T05:06:39Z","pushed_at":"2016-12-02T06:37:11Z","git_url":"git://github.com/daspecster/github-contributions-chrome-extension.git","ssh_url":"git@github.com:daspecster/github-contributions-chrome-extension.git","clone_url":"https://github.com/daspecster/github-contributions-chrome-extension.git","svn_url":"https://github.com/daspecster/github-contributions-chrome-extension","homepage":null,"size":5,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1"},"html":{"href":"https://github.com/daspecster/github-contributions-chrome-extension/pull/1"},"issue":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues/1"},"comments":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/daspecster/github-contributions-chrome-extension/statuses/c24975ccdf23a6cf34a27a581f1813bb0a06611e"}}}}
{"actor":{"display_login":"daspecster"}}