Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e5c7dd8

Browse files
committed
fix switching videos causing container to reset
1 parent a4c9d0c commit e5c7dd8

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

‎src/background/background.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ chrome.runtime.onMessage.addListener((request) => {
7373
// Keep track of the last state to avoid duplicate updates
7474
let lastState = {
7575
problemPath: '',
76-
view: '' // 'problem' or 'solutions'
76+
view: '', // 'problem' or 'solutions'
77+
lastPathname: '' // Track full pathname to detect real navigation
7778
};
7879

7980
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
@@ -85,34 +86,42 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
8586
if (url.match(problemUrl)) {
8687
// Extract the problem path from the URL
8788
const problemPath = url.match(/\/problems\/([^/]+)/)?.[1];
89+
const pathname = new URL(url).pathname;
8890

8991
// Determine the current view - now only distinguishing between problem view and solutions
9092
let currentView = url.includes('/solutions') ? 'solutions' : 'problem';
9193

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;
9496
const isProblemChange = problemPath !== lastState.problemPath;
9597
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');
96103

97-
if (isProblemChange || isViewChange || isPageRefresh) {
104+
// Only update if there's a real navigation or problem change
105+
if ((isProblemChange || (isViewChange && isRealNavigation) || isPageLoad) && problemPath) {
98106
console.log(`State change detected - ${
99107
isProblemChange ? 'New Problem' :
100108
isViewChange ? 'View Changed' :
101-
'Page Refresh'
109+
'Page Load'
102110
}`);
103111

104112
// Update last state
105-
lastState.problemPath = problemPath||'';
113+
lastState.problemPath = problemPath;
106114
lastState.view = currentView;
115+
lastState.lastPathname = pathname;
107116

108117
chrome.storage.local.get(['currentLeetCodeProblem', 'currentLeetCodeProblemTitle', 'descriptionTabUpdated', 'solutionsTabUpdated'], (result) => {
109118
let lastProblem = result.currentLeetCodeProblem || '';
110119
let lastTitle = result.currentLeetCodeProblemTitle || '';
111120
let descriptionTabUpdated = result.descriptionTabUpdated || false;
112121
let solutionsTabUpdated = result.solutionsTabUpdated || false;
113122

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)) {
116125
console.log('Updating problem state:', problemPath);
117126
chrome.storage.local.set({
118127
'currentLeetCodeProblem': problemPath,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /