@@ -75,44 +75,48 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
7575 const  url  =  tab . url ; 
7676 let  problemUrl  =  / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ ? / ; 
7777
78-  // Only proceed  if this is a leetcode problem page 
78+  // Check  if this is a leetcode problem page 
7979 if  ( url . match ( problemUrl ) )  { 
8080 // Extract the problem path from the URL 
8181 const  problemPath  =  url . match ( / \/ p r o b l e m s \/ ( [ ^ / ] + ) / ) ?. [ 1 ] ; 
8282
83-  chrome . storage . local . get ( [ 'currentLeetCodeProblem' ,  'currentLeetCodeProblemTitle' ,  'descriptionTabUpdated' ,  'solutionsTabUpdated' ] ,  ( result )  =>  { 
84-  let  lastProblem  =  result . currentLeetCodeProblem  ||  '' ; 
85-  let  lastTitle  =  result . currentLeetCodeProblemTitle  ||  '' ; 
86-  let  descriptionTabUpdated  =  result . descriptionTabUpdated  ||  false ; 
87-  let  solutionsTabUpdated  =  result . solutionsTabUpdated  ||  false ; 
88- 89-  // Only reset if we've switched to a different problem 
90-  if  ( problemPath  &&  problemPath  !==  lastProblem )  { 
91-  console . log ( 'Problem changed from' ,  lastProblem ,  'to' ,  problemPath ) ; 
92-  chrome . storage . local . set ( { 
93-  'currentLeetCodeProblem' : problemPath , 
94-  'currentLeetCodeProblemTitle' : tab . title , 
95-  'descriptionTabUpdated' : false , 
96-  'solutionsTabUpdated' : false 
97-  } ) ; 
98-  descriptionTabUpdated  =  false ; 
99-  solutionsTabUpdated  =  false ; 
100-  } 
83+  // Handle both page refresh (complete status) and dynamic updates 
84+  if  ( changeInfo . status  ===  'complete'  ||  changeInfo . url )  { 
85+  console . log ( 'Tab updated or refreshed:' ,  url ) ; 
86+  chrome . storage . local . get ( [ 'currentLeetCodeProblem' ,  'currentLeetCodeProblemTitle' ,  'descriptionTabUpdated' ,  'solutionsTabUpdated' ] ,  ( result )  =>  { 
87+  let  lastProblem  =  result . currentLeetCodeProblem  ||  '' ; 
88+  let  lastTitle  =  result . currentLeetCodeProblemTitle  ||  '' ; 
89+  let  descriptionTabUpdated  =  result . descriptionTabUpdated  ||  false ; 
90+  let  solutionsTabUpdated  =  result . solutionsTabUpdated  ||  false ; 
91+ 92+  // Reset flags on problem change or page refresh 
93+  if  ( problemPath  &&  ( problemPath  !==  lastProblem  ||  changeInfo . status  ===  'complete' ) )  { 
94+  console . log ( 'Problem changed or page refreshed:' ,  problemPath ) ; 
95+  chrome . storage . local . set ( { 
96+  'currentLeetCodeProblem' : problemPath , 
97+  'currentLeetCodeProblemTitle' : tab . title , 
98+  'descriptionTabUpdated' : false , 
99+  'solutionsTabUpdated' : false 
100+  } ) ; 
101+  descriptionTabUpdated  =  false ; 
102+  solutionsTabUpdated  =  false ; 
103+  } 
101104
102-  // If the description tab has not been updated and the url matches the description page, we update the flag 
103-  let  descriptionUrl  =  / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ ( d e s c r i p t i o n \/ ) ? $ / ; 
104-  if  ( ! descriptionTabUpdated  &&  url . match ( descriptionUrl ) )  { 
105-  chrome . storage . local . set ( {  'descriptionTabUpdated' : true  } ) ; 
106-  chrome . tabs . sendMessage ( tabId ,  {  action : 'updateDescription' ,  title : tab . title  ||  'title'  } ) ; 
107-  } 
105+  // If the description tab has not been updated and the url matches the description page, we update the flag 
106+  let  descriptionUrl  =  / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ ( d e s c r i p t i o n \/ ) ? $ / ; 
107+  if  ( ! descriptionTabUpdated  &&  url . match ( descriptionUrl ) )  { 
108+  chrome . storage . local . set ( {  'descriptionTabUpdated' : true  } ) ; 
109+  chrome . tabs . sendMessage ( tabId ,  {  action : 'updateDescription' ,  title : tab . title  ||  'title'  } ) ; 
110+  } 
108111
109-  // If the solutions tab has not been updated and the url matches the solutions page, we update the flag 
110-  let  solutionsUrl  =  / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ s o l u t i o n s \/ ? $ / ; 
111-  if  ( ! solutionsTabUpdated  &&  url . match ( solutionsUrl ) )  { 
112-  chrome . storage . local . set ( {  'solutionsTabUpdated' : true  } ) ; 
113-  chrome . tabs . sendMessage ( tabId ,  {  action : 'updateSolutions' ,  title : tab . title  ||  'title'  } ) ; 
114-  } 
115-  } ) ; 
112+  // If the solutions tab has not been updated and the url matches the solutions page, we update the flag 
113+  let  solutionsUrl  =  / ^ h t t p s : \/ \/ l e e t c o d e \. c o m \/ p r o b l e m s \/ .* \/ s o l u t i o n s \/ ? $ / ; 
114+  if  ( ! solutionsTabUpdated  &&  url . match ( solutionsUrl ) )  { 
115+  chrome . storage . local . set ( {  'solutionsTabUpdated' : true  } ) ; 
116+  chrome . tabs . sendMessage ( tabId ,  {  action : 'updateSolutions' ,  title : tab . title  ||  'title'  } ) ; 
117+  } 
118+  } ) ; 
119+  } 
116120 } 
117121 } 
118122} ) ; 
0 commit comments