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 af563b2

Browse files
committed
fix solutions tab elements getting readded when switching tabs
1 parent edbaff2 commit af563b2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,24 @@ function updateAllElements(isDark: boolean) {
573573

574574
// Function to update the solutions tab content
575575
function updateSolutionsTab(title: string) {
576+
// Check if we're actually on the solutions tab before proceeding
577+
const isSolutionsPage = /^https:\/\/leetcode\.com\/problems\/.*\/solutions\/?/.test(window.location.href);
578+
if (!isSolutionsPage) return;
579+
576580
chrome.storage.local.get(['leetcodeProblems'], (result) => {
577581
// Try to find the search bar with retries
578582
const maxRetries = 10;
579583
const baseDelay = 300;
580584
let retryCount = 0;
581585

582586
const tryInsertContent = () => {
587+
// First check if we already have a wrapper to prevent duplicates
588+
const existingWrapper = document.querySelector('.leetcode-explained-wrapper');
589+
if (existingWrapper) {
590+
console.log('Content already exists, skipping insertion');
591+
return;
592+
}
593+
583594
const searchBar = document.querySelectorAll('input.block')[0]?.parentElement?.parentElement?.parentElement;
584595

585596
if (!searchBar && retryCount < maxRetries) {
@@ -596,6 +607,12 @@ function updateSolutionsTab(title: string) {
596607

597608
// If still not found, set up a MutationObserver to watch for DOM changes
598609
const observer = new MutationObserver((mutations, obs) => {
610+
// Check again for existing wrapper before proceeding
611+
if (document.querySelector('.leetcode-explained-wrapper')) {
612+
obs.disconnect();
613+
return;
614+
}
615+
599616
const searchBar = document.querySelectorAll('input.block')[0]?.parentElement?.parentElement?.parentElement;
600617
if (searchBar) {
601618
obs.disconnect(); // Stop observing once we find the element

0 commit comments

Comments
(0)

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