Recognize the project page
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
return projectName || null;
|
||||
// Fallback: try to get from H1 (project pages)
|
||||
const projectH1 = document.querySelector('h1.font-ui-serif');
|
||||
if (projectH1) {
|
||||
return projectH1.textContent.trim() || 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
|
||||
|
||||
@ -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
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user