From 8f15cb8001eb5c12f0f717d6da4d5bc6a2ca7637 Mon Sep 17 00:00:00 2001 From: renato97 Date: Tue, 4 Nov 2025 05:38:35 +0000 Subject: [PATCH] Add debug button to detect page counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New button added: - 🔍 Debug: Contar Páginas (purple button) - Scans ALL manga on the page - Fetches each manga's gallery page - Detects page count using the same logic - Shows detailed results in console - Lists: Title, URL, and detected page count Usage: 1. Click the purple 'Debug: Contar Páginas' button 2. Check console for detailed results 3. Share the console output This will show exactly what page counts are being detected! --- content.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/content.js b/content.js index bd531a1..f56cd82 100644 --- a/content.js +++ b/content.js @@ -51,6 +51,7 @@ + @@ -73,6 +74,7 @@ const btnDownloadSelected = document.getElementById('btn-download-selected'); const btnDownloadAll = document.getElementById('btn-download-all'); const btnClearSelection = document.getElementById('btn-clear-selection'); + const btnDebugPages = document.getElementById('btn-debug-pages'); if (btnDownloadSelected) { btnDownloadSelected.addEventListener('click', (e) => { @@ -106,6 +108,15 @@ console.error('❌ btnClearSelection not found!'); } + if (btnDebugPages) { + btnDebugPages.addEventListener('click', (e) => { + console.log('🎯 BUTTON CLICKED: Debug Contar Páginas'); + debugCountPagesForAllManga(); + }); + } else { + console.error('❌ btnDebugPages not found!'); + } + // Actualizar contador inicialmente const countEl = document.getElementById('selected-count'); if (countEl) countEl.textContent = selectedMangas.size.toString(); @@ -760,6 +771,69 @@ }, 2000); } + // Debug: Contar páginas para todos los manga en la página + async function debugCountPagesForAllManga() { + console.log('\n========== 🔍 DEBUG: PAGE COUNT DETECTION =========='); + console.log('🔍 Scanning all manga on page...'); + + const allMangas = extractAllMangasFromPage(); + console.log(`📦 Found ${allMangas.length} manga on page`); + + const results = []; + + for (let i = 0; i < allMangas.length; i++) { + const manga = allMangas[i]; + console.log(`\n--- 🔍 MANGA ${i + 1}/${allMangas.length}: ${manga.title} ---`); + console.log(`🔗 URL: ${manga.baseUrl}`); + + try { + const response = await fetch(manga.baseUrl, { + credentials: 'include' + }); + + if (!response.ok) { + console.error(`❌ Error ${response.status} fetching page`); + continue; + } + + const html = await response.text(); + const parser = new DOMParser(); + const doc = parser.parseFromString(html, 'text/html'); + + // Usar la misma lógica de detección + let detectedPages = 'UNKNOWN'; + const allDivs = doc.querySelectorAll('div'); + + for (let div of allDivs) { + const text = div.textContent.trim(); + const pageMatch = text.match(/^(\d+)\s+pages?$/i); + if (pageMatch) { + detectedPages = parseInt(pageMatch[1]); + console.log(`✓ Found: "${text}" = ${detectedPages} pages (class: ${div.className})`); + break; + } + } + + results.push({ + title: manga.title, + url: manga.baseUrl, + pages: detectedPages + }); + + console.log(`📊 Result: ${detectedPages} pages`); + + } catch (error) { + console.error(`❌ Error processing manga:`, error); + } + } + + console.log('\n========== 📊 FINAL RESULTS =========='); + results.forEach((result, idx) => { + console.log(`${idx + 1}. ${result.pages} pages - ${result.title}`); + }); + console.log('========================================\n'); + } + function init() { if (window.location.href.includes('/g/')) return;