Recognize the project page

This commit is contained in:
2025-07-17 09:34:35 -04:00
parent 4a41a38cbc
commit 111e3ee048
3 changed files with 46 additions and 11 deletions

View File

@ -1,7 +1,7 @@
async function main() { async function main() {
console.log('Running artifact collector'); console.log('Running artifact collector');
if (!ProjectMeta.isProjectChat()) { if (!ProjectMeta.isInProject()) {
console.log('Not in a project chat, exiting'); console.log('Not in a project chat, exiting');
return; return;
} }

View File

@ -1,14 +1,22 @@
const ProjectMeta = { const ProjectMeta = {
getProjectName() { getProjectName() {
// First try to get from project link (chat pages)
const projectLink = document.querySelector('a[href*="/project/"]'); const projectLink = document.querySelector('a[href*="/project/"]');
if (!projectLink) { if (projectLink) {
return null; // 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 // Fallback: try to get from H1 (project pages)
const projectName = projectLink.innerText.replace(/\s*\/.*$/, '').trim(); const projectH1 = document.querySelector('h1.font-ui-serif');
if (projectH1) {
return projectH1.textContent.trim() || null;
}
return projectName || null; return null;
}, },
getChatName() { getChatName() {
@ -22,7 +30,19 @@ const ProjectMeta = {
isProjectChat() { isProjectChat() {
return Boolean(this.getProjectName()) && Boolean(this.getChatName()); 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

View File

@ -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 = { const ArtifactScraper = {
async collectArtifacts() { async collectArtifacts() {
// For now, delegate to ChatArtifactScraper if (ProjectMeta.isProjectChat()) {
// In the future, this will check if we're on project homepage or chat console.log('Detected project chat - using ChatArtifactScraper');
// and call the appropriate scraper return await ChatArtifactScraper.collectArtifacts();
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');
}
} }
}; };