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 b5dc3d3

Browse files
committed
fix refreshing not updating solutions tab
1 parent 21bd1b2 commit b5dc3d3

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

‎src/background/background.ts‎

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,44 +75,48 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
7575
const url = tab.url;
7676
let problemUrl = /^https:\/\/leetcode\.com\/problems\/.*\/?/;
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(/\/problems\/([^/]+)/)?.[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 = /^https:\/\/leetcode\.com\/problems\/.*\/(description\/)?$/;
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 = /^https:\/\/leetcode\.com\/problems\/.*\/(description\/)?$/;
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 = /^https:\/\/leetcode\.com\/problems\/.*\/solutions\/?$/;
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 = /^https:\/\/leetcode\.com\/problems\/.*\/solutions\/?$/;
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

Comments
(0)

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