@@ -82,6 +82,7 @@ $("#hook_button").on('click', ()=>{
82
82
/* Detect mode type */
83
83
chrome . storage . sync . get ( "mode_type" , data => {
84
84
const mode = data . mode_type ;
85
+
85
86
if ( mode && mode == "commit" )
86
87
{
87
88
/* Check if still access to repo */
@@ -171,47 +172,50 @@ var create_repo = (token, name)=>{
171
172
*/
172
173
var link_repo = ( token , name ) => {
173
174
const AUTHENTICATION_URL = "https://api.github.com/repos/" + name ;
174
-
175
+
175
176
var xhr = new XMLHttpRequest ( ) ;
176
177
xhr . addEventListener ( 'readystatechange' , function ( event ) {
177
178
if ( xhr . readyState == 4 ) {
178
179
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
181
182
{
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
+ } ) ;
190
193
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 ( ) ;
213
205
} ) ;
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
+ }
215
219
}
216
220
}
217
221
} ) ;
@@ -223,7 +227,7 @@ var link_repo = (token, name)=>{
223
227
}
224
228
225
229
/* Status codes for linking of repo */
226
- var link_status_code = ( res , status , name ) => {
230
+ var link_status_code = ( status , name ) => {
227
231
let bool = false ;
228
232
switch ( status )
229
233
{
0 commit comments