From 111e3ee0489139069be4db10608d606363d63747 Mon Sep 17 00:00:00 2001 From: Lexical Bits Date: Thu, 17 Jul 2025 09:34:35 -0400 Subject: [PATCH] Recognize the project page --- src/main.js | 2 +- src/project_meta.js | 32 ++++++++++++++++++++++++++------ src/scraper.js | 23 +++++++++++++++++++---- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/main.js b/src/main.js index 705ad6b..71811db 100644 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,7 @@ async function main() { console.log('Running artifact collector'); - if (!ProjectMeta.isProjectChat()) { + if (!ProjectMeta.isInProject()) { console.log('Not in a project chat, exiting'); return; } diff --git a/src/project_meta.js b/src/project_meta.js index 581bf47..86e298c 100644 --- a/src/project_meta.js +++ b/src/project_meta.js @@ -1,14 +1,22 @@ const ProjectMeta = { getProjectName() { + // First try to get from project link (chat pages) const projectLink = document.querySelector('a[href*="/project/"]'); - if (!projectLink) { - return null; + if (projectLink) { + // Get the full text and strip trailing spaces and forward slashes + const projectName = projectLink.innerText.replace(/\s*\/.*$/, '').trim(); + if (projectName) { + return projectName; + } } - // Get the full text and strip trailing spaces and forward slashes - const projectName = projectLink.innerText.replace(/\s*\/.*$/, '').trim(); + // Fallback: try to get from H1 (project pages) + const projectH1 = document.querySelector('h1.font-ui-serif'); + if (projectH1) { + return projectH1.textContent.trim() || null; + } - return projectName || null; + return null; }, getChatName() { @@ -22,7 +30,19 @@ const ProjectMeta = { isProjectChat() { return Boolean(this.getProjectName()) && Boolean(this.getChatName()); + }, + + isProjectPage() { + const h2Elements = document.getElementsByTagName('h2'); + const hasProjectKnowledge = Array.from(h2Elements).some(h2 => + h2.textContent.trim() === 'Project knowledge' + ); + return Boolean(this.getProjectName()) && hasProjectKnowledge; + }, + + isInProject() { + return this.isProjectChat() || this.isProjectPage(); } }; -// No exports needed - will be in same scope after build;// No exports needed - will be in same scope after build +// No exports needed - will be in same scope after build diff --git a/src/scraper.js b/src/scraper.js index 3b98ae7..272dcf8 100644 --- a/src/scraper.js +++ b/src/scraper.js @@ -233,13 +233,28 @@ const ChatArtifactScraper = { } }; +const ProjectArtifactScraper = { + + async collectArtifacts() { + // TODO: Implement project page artifact collection + console.log('Project page artifact collection not yet implemented'); + return { artifacts: {}, fileMap: null }; + } + +}; + const ArtifactScraper = { async collectArtifacts() { - // For now, delegate to ChatArtifactScraper - // In the future, this will check if we're on project homepage or chat - // and call the appropriate scraper - return await ChatArtifactScraper.collectArtifacts(); + if (ProjectMeta.isProjectChat()) { + console.log('Detected project chat - using ChatArtifactScraper'); + return await ChatArtifactScraper.collectArtifacts(); + } else if (ProjectMeta.isProjectPage()) { + console.log('Detected project page - using ProjectArtifactScraper'); + return await ProjectArtifactScraper.collectArtifacts(); + } else { + throw new Error('Unknown page type - not a project chat or project page'); + } } };