@@ -73,7 +73,8 @@ chrome.runtime.onMessage.addListener((request) => {
73
73
// Keep track of the last state to avoid duplicate updates
74
74
let lastState = {
75
75
problemPath : '' ,
76
- view : '' // 'problem' or 'solutions'
76
+ view : '' , // 'problem' or 'solutions'
77
+ lastPathname : '' // Track full pathname to detect real navigation
77
78
} ;
78
79
79
80
chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
@@ -85,34 +86,42 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
85
86
if ( url . match ( problemUrl ) ) {
86
87
// Extract the problem path from the URL
87
88
const problemPath = url . match ( / \/ p r o b l e m s \/ ( [ ^ / ] + ) / ) ?. [ 1 ] ;
89
+ const pathname = new URL ( url ) . pathname ;
88
90
89
91
// Determine the current view - now only distinguishing between problem view and solutions
90
92
let currentView = url . includes ( '/solutions' ) ? 'solutions' : 'problem' ;
91
93
92
- // Handle page refreshes and initial loads
93
- const isPageRefresh = changeInfo . status === 'complete' ;
94
+ // Only trigger updates on actual page loads or problem changes
95
+ const isPageLoad = changeInfo . status === 'complete' && ! changeInfo . url ;
94
96
const isProblemChange = problemPath !== lastState . problemPath ;
95
97
const isViewChange = currentView !== lastState . view ;
98
+ const isRealNavigation = pathname !== lastState . lastPathname &&
99
+ ! pathname . includes ( 'playground' ) &&
100
+ ! pathname . includes ( 'editor' ) &&
101
+ ! pathname . includes ( 'interpret-solution' ) &&
102
+ ! pathname . includes ( 'submissions' ) ;
96
103
97
- if ( isProblemChange || isViewChange || isPageRefresh ) {
104
+ // Only update if there's a real navigation or problem change
105
+ if ( ( isProblemChange || ( isViewChange && isRealNavigation ) || isPageLoad ) && problemPath ) {
98
106
console . log ( `State change detected - ${
99
107
isProblemChange ? 'New Problem' :
100
108
isViewChange ? 'View Changed' :
101
- 'Page Refresh '
109
+ 'Page Load '
102
110
} `) ;
103
111
104
112
// Update last state
105
- lastState . problemPath = problemPath || '' ;
113
+ lastState . problemPath = problemPath ;
106
114
lastState . view = currentView ;
115
+ lastState . lastPathname = pathname ;
107
116
108
117
chrome . storage . local . get ( [ 'currentLeetCodeProblem' , 'currentLeetCodeProblemTitle' , 'descriptionTabUpdated' , 'solutionsTabUpdated' ] , ( result ) => {
109
118
let lastProblem = result . currentLeetCodeProblem || '' ;
110
119
let lastTitle = result . currentLeetCodeProblemTitle || '' ;
111
120
let descriptionTabUpdated = result . descriptionTabUpdated || false ;
112
121
let solutionsTabUpdated = result . solutionsTabUpdated || false ;
113
122
114
- // Reset flags on problem change or page refresh
115
- if ( isProblemChange || isPageRefresh ) {
123
+ // Reset flags on problem change or page load
124
+ if ( isProblemChange || ( isPageLoad && ! descriptionTabUpdated && ! solutionsTabUpdated ) ) {
116
125
console . log ( 'Updating problem state:' , problemPath ) ;
117
126
chrome . storage . local . set ( {
118
127
'currentLeetCodeProblem' : problemPath ,
0 commit comments