Skip to content

Commit

Permalink
fix: improve search results observer and remove unused variable
Browse files Browse the repository at this point in the history
- Enhance search results observer to properly detect new video titles
  • Loading branch information
YouG-o committed Jan 10, 2025
1 parent 3aef2b1 commit 08e143f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "No More Translations",
"version": "1.1.4",
"version": "1.1.5",
"description": "A firefox extension that prevents auto-translation on YouTube (titles, dubbing)",

"icons": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nmt",
"version": "1.1.4",
"version": "1.1.5",
"description": "A firefox extension that prevents auto-translation on YouTube (titles, dubbing)",
"scripts": {
"clean": "rimraf dist/*",
Expand Down
33 changes: 28 additions & 5 deletions src/content/titleTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function initializeTitleTranslation() {

// Observers Setup
function setupTitleObserver() {
// Observer pour la page watch
// Observer for watch page
waitForElement('ytd-watch-flexy').then((watchFlexy) => {
titleObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
Expand All @@ -156,7 +156,7 @@ function setupTitleObserver() {
});
});

// Observer pour la page d'accueil
// Observer for home page
waitForElement('#contents.ytd-rich-grid-renderer').then((contents) => {
const gridObserver = new MutationObserver(() => {
refreshOtherTitles();
Expand All @@ -167,7 +167,7 @@ function setupTitleObserver() {
});
});

// Observer pour les vidéos recommandées
// Observer for recommended videos
waitForElement('#secondary-inner ytd-watch-next-secondary-results-renderer #items').then((contents) => {
console.log('[Extension-Debug] Setting up recommended videos observer');
const recommendedObserver = new MutationObserver(() => {
Expand All @@ -178,13 +178,36 @@ function setupTitleObserver() {
childList: true
});
});

// Observer for search results
waitForElement('ytd-section-list-renderer #contents').then((contents) => {
console.log('[Extension-Debug] Setting up search results observer');
const searchObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type === 'childList' &&
mutation.addedNodes.length > 0 &&
mutation.target instanceof HTMLElement) {
const titles = mutation.target.querySelectorAll('#video-title');
if (titles.length > 0) {
refreshOtherTitles();
break;
}
}
}
});

searchObserver.observe(contents, {
childList: true,
subtree: true
});
});
}

// Nouvelle fonction pour gérer les résultats de recherche
// New function to handle search results
async function handleSearchResults(): Promise<void> {
console.log('[Extension-Debug] Processing search results');

// Sélectionner tous les titres de vidéos non traités
// Select all untreated video titles
const videoTitles = document.querySelectorAll('ytd-video-renderer #video-title:not([translate="no"])') as NodeListOf<HTMLAnchorElement>;

console.log('[Extension-Debug] Found video titles:', videoTitles.length);
Expand Down
2 changes: 1 addition & 1 deletion src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2 class="text-sm font-medium text-gray-900">Original Audio</h2>
</div>
</main>
<footer class="pt-4 border-t border-gray-200 flex items-center justify-between">
<p class="text-xs text-gray-400">v1.1.4</p>
<p class="text-xs text-gray-400">v1.1.5</p>
<div class="flex items-center gap-1 text-xs text-gray-400">
Created by YouGo
<a href="https://github.com/YouG-o" target="_blank" rel="noopener noreferrer">
Expand Down

0 comments on commit 08e143f

Please sign in to comment.