Skip to content

Commit

Permalink
fix: prevent title duplication during slow page load
Browse files Browse the repository at this point in the history
- Add check to detect if original title is already present
- Clean up element content if duplicate is found
- Maintain single instance of title text
- Handle race condition between extension and YouTube translation
  • Loading branch information
YouG-o committed Jan 9, 2025
1 parent c7a1fa4 commit 69c131f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/content/titleTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ async function handleTitleTranslation(isEnabled: boolean): Promise<void> {
// Utility functions
function updateTitleElement(element: HTMLElement, title: string): void {
console.log('[Extension-Debug] Updating element with title:', title);
element.textContent = title;

// Check if the element already contains the original title
if (element.textContent?.includes(title)) {
console.log('[Extension-Debug] Title already present, cleaning up');
element.textContent = title; // Clean up any duplicate
} else {
element.textContent = title;
}

element.setAttribute('translate', 'no');
element.style.setProperty('translate', 'no', 'important');
titleCache.setElement(element, title);
Expand Down

0 comments on commit 69c131f

Please sign in to comment.