Fixing GKWP a bit more.

This commit is contained in:
Lord_Devi 2024-11-21 08:26:45 -05:00
parent 6dd616fcba
commit e43d9b9987

View file

@ -483,6 +483,36 @@
return false;
}
// Helper function to check if pagination is needed
function shouldHandlePagination(options) {
try {
// First check if user wants all pages
if (!options.extractAllPages) {
console.log('Skipping pagination: extractAllPages is false');
return false;
}
// Get current page info
const pageInfo = getCurrentPageInfo();
if (!pageInfo) {
console.log('Skipping pagination: could not get page info');
return false;
}
// If total is less than or equal to 100, no need for pagination
if (pageInfo.total <= 100) {
console.log(`Skipping pagination: only ${pageInfo.total} total items`);
return false;
}
console.log(`Pagination needed: ${pageInfo.total} total items`);
return true;
} catch (error) {
console.error('Error checking pagination:', error);
return false;
}
}
// Since this is an Angular app, content might load dynamically
// Let's try to wait for the content to load
function waitForContent() {
@ -519,26 +549,32 @@
// Main function to extract keywords
async function extractKeywords() {
try {
// First set the rows to 500 if possible
const rowsSet = await setShowRows500();
if (!rowsSet) {
console.log('Warning: Could not set rows to 500');
}
// Add a delay and wait for pagination to update
await new Promise(resolve => setTimeout(resolve, 2000));
await waitForPaginationUpdate();
// Ensure content is fully loaded
await ensureContentVisible();
await loadAllRows();
// Get the options passed from the popup
const options = window.keywordGrabberOptions || { includeHeaders: true, extractAllPages: true };
// Create a Map to store unique keywords with their volumes and sources
const processedKeywords = new Map(); // Using Map to store keyword -> { volume, source } pairs
// Check if we need pagination
const needsPagination = shouldHandlePagination(options);
// Only try to set rows to 500 if we need pagination
if (needsPagination) {
// First set the rows to 500 if possible
const rowsSet = await setShowRows500();
if (!rowsSet) {
console.log('Warning: Could not set rows to 500');
}
// Add a delay and wait for pagination to update
await new Promise(resolve => setTimeout(resolve, 2000));
await waitForPaginationUpdate();
}
// Ensure content is fully loaded
await ensureContentVisible();
await loadAllRows();
// Get current page info
const pageInfo = getCurrentPageInfo();
if (!pageInfo) {