Skip to content

Commit 558e5b7

Browse files
committed
bug fix for xhr status
1 parent b177403 commit 558e5b7

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

scripts/welcome.js

+39-35
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ $("#hook_button").on('click', ()=>{
8282
/* Detect mode type */
8383
chrome.storage.sync.get("mode_type", data=>{
8484
const mode = data.mode_type;
85+
8586
if(mode && mode == "commit")
8687
{
8788
/* Check if still access to repo */
@@ -171,47 +172,50 @@ var create_repo = (token, name)=>{
171172
*/
172173
var link_repo = (token, name)=>{
173174
const AUTHENTICATION_URL = "https://api.github.com/repos/" + name;
174-
175+
175176
var xhr = new XMLHttpRequest();
176177
xhr.addEventListener('readystatechange', function(event) {
177178
if(xhr.readyState == 4) {
178179
const res = JSON.parse(xhr.responseText);
179-
var bool = link_status_code(res, xhr.status, name);
180-
if(!bool) //unable to gain access to repo in commit mode. Must switch to hook mode.
180+
var bool = link_status_code(xhr.status, name);
181+
if(xhr.status == 200) //BUG FIX
181182
{
182-
/* Set mode type to hook */
183-
chrome.storage.sync.set({"mode_type": "hook"}, data=>{
184-
console.log(`Error linking ${name} to LeetHub`);
185-
});
186-
/* Set Repo Hook to NONE */
187-
chrome.storage.sync.set({"leethub_hook": null}, data=>{
188-
console.log("Defaulted repo hook to NONE");
189-
});
183+
if(!bool) //unable to gain access to repo in commit mode. Must switch to hook mode.
184+
{
185+
/* Set mode type to hook */
186+
chrome.storage.sync.set({"mode_type": "hook"}, data=>{
187+
console.log(`Error linking ${name} to LeetHub`);
188+
});
189+
/* Set Repo Hook to NONE */
190+
chrome.storage.sync.set({"leethub_hook": null}, data=>{
191+
console.log("Defaulted repo hook to NONE");
192+
});
190193

191-
/* Hide accordingly */
192-
document.getElementById("hook_mode").style.display = "inherit";
193-
document.getElementById("commit_mode").style.display = "none";
194-
}
195-
else
196-
{
197-
/* Change mode type to commit */
198-
chrome.storage.sync.set({"mode_type": "commit"}, data=>{
199-
$("#error").hide();
200-
$("#success").html(`Successfully linked <a target="blank" href="${res['html_url']}">${name}</a> to LeetHub. Start <a href="http://leetcode.com">LeetCoding</a> now!`);
201-
$("#success").show();
202-
});
203-
/* Set Repo Hook */
204-
chrome.storage.sync.set({"leethub_hook": res['full_name']}, data=>{
205-
console.log("Successfully set new repo hook");
206-
/* Get problems solved count */
207-
chrome.storage.sync.get("stats", psolved=>{
208-
psolved = psolved.stats;
209-
if(psolved && psolved["solved"])
210-
{
211-
$("#p_solved").text(psolved["solved"]);
212-
}
194+
/* Hide accordingly */
195+
document.getElementById("hook_mode").style.display = "inherit";
196+
document.getElementById("commit_mode").style.display = "none";
197+
}
198+
else
199+
{
200+
/* Change mode type to commit */
201+
chrome.storage.sync.set({"mode_type": "commit"}, data=>{
202+
$("#error").hide();
203+
$("#success").html(`Successfully linked <a target="blank" href="${res['html_url']}">${name}</a> to LeetHub. Start <a href="http://leetcode.com">LeetCoding</a> now!`);
204+
$("#success").show();
213205
});
214-
});
206+
/* Set Repo Hook */
207+
chrome.storage.sync.set({"leethub_hook": res['full_name']}, data=>{
208+
console.log("Successfully set new repo hook");
209+
/* Get problems solved count */
210+
chrome.storage.sync.get("stats", psolved=>{
211+
psolved = psolved.stats;
212+
if(psolved && psolved["solved"])
213+
{
214+
$("#p_solved").text(psolved["solved"]);
215+
}
216+
});
217+
});
218+
}
215219
}
216220
}
217221
});
@@ -223,7 +227,7 @@ var link_repo = (token, name)=>{
223227
}
224228

225229
/* Status codes for linking of repo */
226-
var link_status_code = (res, status, name)=>{
230+
var link_status_code = (status, name)=>{
227231
let bool = false;
228232
switch (status)
229233
{

0 commit comments

Comments
 (0)