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 bd02e02

Browse files
committed
fix solution to description tab not showing company tags
1 parent 60a9a01 commit bd02e02

File tree

2 files changed

+58
-69
lines changed

2 files changed

+58
-69
lines changed

‎src/background/background.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
155155
let descriptionTabUpdated = result.descriptionTabUpdated || false;
156156
let solutionsTabUpdated = result.solutionsTabUpdated || false;
157157

158-
// Only update description if we're in problem view and not updated
159-
if (!descriptionTabUpdated&&currentView === 'problem') {
158+
// Always update description tab when in problem view
159+
if (currentView === 'problem') {
160160
chrome.storage.local.set({ 'descriptionTabUpdated': true });
161161
chrome.tabs.sendMessage(tabId, { action: 'updateDescription', title: tab.title || 'title' });
162162
}
163163

164-
// Only update solutions if we're in solutions view and not updated or if view just changed to solutions
165-
if ((!solutionsTabUpdated||(isViewChange&&currentView==='solutions'))&&currentView === 'solutions') {
164+
// Always update solutions tab when in solutions view
165+
if (currentView === 'solutions') {
166166
chrome.storage.local.set({ 'solutionsTabUpdated': true });
167167
chrome.tabs.sendMessage(tabId, { action: 'updateSolutions', title: tab.title || 'title' });
168168
}

‎src/content-script/update-description-tab.ts

Lines changed: 54 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,7 @@ function showRating(problemTitle: string) {
144144
// show the company tags if the user has enabled it in the settings
145145
function showCompanyTags(problemTitle: string) {
146146
chrome.storage.local.get(['showCompanyTags'], (result) => {
147-
const showCompanyTags = result.showCompanyTags;
148-
let companyTagContainer = document.getElementById('companyTagContainer');
149-
150-
// First handle visibility
151-
if (!showCompanyTags) {
152-
if (companyTagContainer) {
153-
companyTagContainer.style.display = 'none';
154-
}
155-
return;
156-
} else if (companyTagContainer && companyTagContainer instanceof HTMLElement) {
157-
companyTagContainer.style.display = 'flex';
158-
// If container exists and is visible, just update styles
159-
chrome.storage.local.get(['isDarkTheme'], (result) => {
160-
const isDark = result.isDarkTheme;
161-
const tags = companyTagContainer?.querySelectorAll('.company-tag');
162-
if (tags) {
163-
tags.forEach(tag => {
164-
if (tag instanceof HTMLElement) {
165-
updateCompanyTagStyle(tag, isDark);
166-
}
167-
});
168-
}
169-
});
147+
if (!result.showCompanyTags) {
170148
return;
171149
}
172150

@@ -175,6 +153,26 @@ function showCompanyTags(problemTitle: string) {
175153
const baseDelay = 300;
176154
let retryCount = 0;
177155

156+
const insertCompanyTags = (description: Element) => {
157+
// Double check for existing container before inserting
158+
if (document.getElementById('companyTagContainer')) {
159+
return;
160+
}
161+
162+
// Create new container
163+
const newCompanyTagContainer = document.createElement('div');
164+
newCompanyTagContainer.id = 'companyTagContainer';
165+
newCompanyTagContainer.style.display = 'flex';
166+
newCompanyTagContainer.style.flexDirection = 'row';
167+
newCompanyTagContainer.style.marginBottom = '20px';
168+
newCompanyTagContainer.style.gap = '5px';
169+
170+
description.insertBefore(newCompanyTagContainer, description.firstChild);
171+
172+
// Load and inject company tags
173+
loadCompanyTags(problemTitle, newCompanyTagContainer);
174+
};
175+
178176
const tryInsertCompanyTags = () => {
179177
// First check if container already exists to prevent duplicates
180178
if (document.getElementById('companyTagContainer')) {
@@ -219,30 +217,11 @@ function showCompanyTags(problemTitle: string) {
219217
return;
220218
}
221219

220+
// If we found the description element, insert the company tags
222221
insertCompanyTags(description);
223222
};
224223

225-
const insertCompanyTags = (description: Element) => {
226-
// Double check for existing container before inserting
227-
if (document.getElementById('companyTagContainer')) {
228-
return;
229-
}
230-
231-
// Create new container
232-
const newCompanyTagContainer = document.createElement('div');
233-
newCompanyTagContainer.id = 'companyTagContainer';
234-
newCompanyTagContainer.style.display = 'flex';
235-
newCompanyTagContainer.style.flexDirection = 'row';
236-
newCompanyTagContainer.style.marginBottom = '20px';
237-
newCompanyTagContainer.style.gap = '5px';
238-
239-
description.insertBefore(newCompanyTagContainer, description.firstChild);
240-
241-
// Load and inject company tags
242-
loadCompanyTags(problemTitle, newCompanyTagContainer);
243-
};
244-
245-
// Start the retry process
224+
// Start the process
246225
tryInsertCompanyTags();
247226
});
248227
}
@@ -401,31 +380,41 @@ function initializeContentScript() {
401380
}
402381

403382
function onDOMReady() {
404-
// Check if we're on a LeetCode problem's description page
405-
constisProblemPage=/^https:\/\/leetcode\.com\/problems\/.*\/description\/?/.test(window.location.href);
383+
// Set up theme detection and synchronization
384+
setupDescriptionThemeListener();
406385

407-
if (isProblemPage) {
408-
console.log('LeetCode problem page detected, initializing content script...');
409-
410-
// Extract the problem title from the page title
411-
const pageTitle = document.title;
412-
const problemTitle = pageTitle.split('-')[0].trim();
413-
414-
// Detect theme on first load of a problem page
415-
detectAndSyncTheme();
416-
showExamples();
417-
showCompanyTags(problemTitle);
418-
showDifficulty();
419-
showRating(problemTitle);
420-
421-
// Add theme change listener after creating company tags
422-
setupDescriptionThemeListener();
423-
424-
console.log('Description tab content script initialized for problem:', problemTitle);
386+
// Get the problem title from the page
387+
const problemTitle = document.title.replace(' - LeetCode', '');
388+
389+
// Apply all enhancements
390+
showDifficulty();
391+
showRating(problemTitle);
392+
showCompanyTags(problemTitle);
393+
showExamples();
394+
395+
// Set up a MutationObserver to detect tab changes
396+
const observer = new MutationObserver((mutations) => {
397+
mutations.forEach((mutation) => {
398+
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
399+
// Check if we're on the description tab
400+
const descriptionTab = document.querySelector('[data-cy="description-tab"]');
401+
if (descriptionTab && descriptionTab.classList.contains('active')) {
402+
// Re-apply company tags when switching to description tab
403+
const problemTitle = document.title.replace(' - LeetCode', '');
404+
showCompanyTags(problemTitle);
405+
}
406+
}
407+
});
408+
});
409+
410+
// Start observing the tab container
411+
const tabContainer = document.querySelector('[role="tablist"]');
412+
if (tabContainer) {
413+
observer.observe(tabContainer, { childList: true, subtree: true });
425414
}
426415
}
427416
}
428417

429-
// Run the initialization
418+
// Initialize the content script
430419
initializeContentScript();
431420

0 commit comments

Comments
(0)

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