Fix active element selector, isolate final handler
This commit is contained in:
47
content.js
47
content.js
@ -101,8 +101,10 @@
|
||||
const filenameDiv = item.querySelector('div.line-clamp-2');
|
||||
if (filenameDiv) {
|
||||
const filename = filenameDiv.textContent.trim();
|
||||
const isSelected = item.classList.contains('border-accent-secondary-100') ||
|
||||
item.getAttribute('class').includes('border-accent-secondary-100');
|
||||
// Check for aria-selected attribute or other indicators of selection
|
||||
const isSelected = item.getAttribute('aria-selected') === 'true' ||
|
||||
item.classList.contains('bg-accent-secondary-100') ||
|
||||
item.classList.contains('border-accent-secondary-100');
|
||||
|
||||
artifactHash[filename] = isSelected;
|
||||
console.log(`Found artifact: ${filename} (${isSelected ? 'selected' : 'unselected'})`);
|
||||
@ -155,9 +157,10 @@
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// If not currently selected, we need to select it
|
||||
if (!isCurrentlySelected) {
|
||||
// Open menu if not already open
|
||||
// Check if menu is already open
|
||||
const menuOpen = document.querySelector('li[role="none"] div[role="menuitem"]');
|
||||
if (!menuOpen) {
|
||||
// Menu is not open, so open it
|
||||
try {
|
||||
await this.openArtifactList();
|
||||
} catch (error) {
|
||||
@ -193,8 +196,9 @@
|
||||
async collectArtifacts() {
|
||||
console.log('Starting artifact collection...');
|
||||
|
||||
// Initialize empty collection
|
||||
// Initialize empty collection and fileMap
|
||||
const artifactCollection = {};
|
||||
let fileMap = null;
|
||||
|
||||
// Open artifact list
|
||||
await this.openArtifactList();
|
||||
@ -204,7 +208,7 @@
|
||||
|
||||
if (Object.keys(artifactList).length === 0) {
|
||||
console.log('No artifacts found in list');
|
||||
return;
|
||||
return { artifacts: artifactCollection, fileMap: fileMap };
|
||||
}
|
||||
|
||||
console.log(`Found ${Object.keys(artifactList).length} artifacts to collect`);
|
||||
@ -215,8 +219,15 @@
|
||||
|
||||
try {
|
||||
const content = await this.getArtifact(filename, isSelected);
|
||||
artifactCollection[filename] = content;
|
||||
console.log(`✓ Collected: ${filename}`);
|
||||
|
||||
// Check if this is files.txt
|
||||
if (filename === 'files.txt') {
|
||||
fileMap = content;
|
||||
console.log(`✓ Found files.txt - storing in fileMap`);
|
||||
} else {
|
||||
artifactCollection[filename] = content;
|
||||
console.log(`✓ Collected: ${filename}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`✗ Failed to collect: ${filename} - ${error.message}`);
|
||||
}
|
||||
@ -225,15 +236,22 @@
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
// Log final collection
|
||||
console.log('=== ARTIFACT COLLECTION COMPLETE ===');
|
||||
console.log(`Collected ${Object.keys(artifactCollection).length} artifacts:`);
|
||||
console.log(artifactCollection);
|
||||
|
||||
return artifactCollection;
|
||||
return { artifacts: artifactCollection, fileMap: fileMap };
|
||||
}
|
||||
};
|
||||
|
||||
// Export function to handle logging of collected artifacts
|
||||
function exportArtifacts(artifactCollection, fileMap) {
|
||||
console.log('=== ARTIFACT COLLECTION COMPLETE ===');
|
||||
console.log(`Collected ${Object.keys(artifactCollection).length} artifacts:`);
|
||||
console.log(artifactCollection);
|
||||
|
||||
if (fileMap) {
|
||||
console.log('=== FILE MAP ===');
|
||||
console.log(fileMap);
|
||||
}
|
||||
}
|
||||
|
||||
// Main function
|
||||
async function main() {
|
||||
console.log('Running artifact collector');
|
||||
@ -242,7 +260,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
await ArtifactScraper.collectArtifacts();
|
||||
const result = await ArtifactScraper.collectArtifacts();
|
||||
exportArtifacts(result.artifacts, result.fileMap);
|
||||
}
|
||||
|
||||
// Run the main function
|
||||
|
||||
Reference in New Issue
Block a user