diff --git a/src/config.mjs b/src/config.mjs index 4011ddb..f64a8db 100644 --- a/src/config.mjs +++ b/src/config.mjs @@ -72,7 +72,16 @@ export const defaultConfig = { // others activeSelectionTools: Object.keys(toolsConfig), - activeSiteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'], + activeSiteAdapters: [ + 'bilibili', + 'github', + 'gitlab', + 'quora', + 'reddit', + 'youtube', + 'zhihu', + 'stackoverflow', + ], accessToken: '', tokenSavedOn: 0, @@ -81,7 +90,16 @@ export const defaultConfig = { userLanguage: navigator.language.substring(0, 2), selectionTools: Object.keys(toolsConfig), // importing configuration will result in gpt-3-encoder being packaged into the output file - siteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'], + siteAdapters: [ + 'bilibili', + 'github', + 'gitlab', + 'quora', + 'reddit', + 'youtube', + 'zhihu', + 'stackoverflow', + ], } export async function getUserLanguage() { diff --git a/src/content-script/site-adapters/index.mjs b/src/content-script/site-adapters/index.mjs index 5a14b30..709fa84 100644 --- a/src/content-script/site-adapters/index.mjs +++ b/src/content-script/site-adapters/index.mjs @@ -6,6 +6,7 @@ import gitlab from './gitlab' import zhihu from './zhihu' import reddit from './reddit' import quora from './quora' +import stackoverflow from './stackoverflow' /** * @typedef {object} SiteConfigAction @@ -164,4 +165,10 @@ export const config = { appendContainerQuery: [], resultsContainerQuery: ['.q-box.PageContentsLayout___StyledBox-d2uxks-0'], }, + stackoverflow: { + inputQuery: stackoverflow.inputQuery, + sidebarContainerQuery: ['#sidebar'], + appendContainerQuery: [], + resultsContainerQuery: ['#sidebar'], + }, } diff --git a/src/content-script/site-adapters/stackoverflow/index.mjs b/src/content-script/site-adapters/stackoverflow/index.mjs index 8ad1dfb..c23be20 100644 --- a/src/content-script/site-adapters/stackoverflow/index.mjs +++ b/src/content-script/site-adapters/stackoverflow/index.mjs @@ -1 +1,26 @@ -//TODO +import { cropText } from '../../../utils' + +export default { + inputQuery: async () => { + try { + const title = document.querySelector('#question-header .question-hyperlink')?.textContent + if (title) { + const description = document.querySelector('.postcell .s-prose')?.textContent + let answer = '' + const answers = document.querySelectorAll('.answercell .s-prose') + if (answers.length > 0) + for (let i = 1; i <= answers.length && i <= 2; i++) { + answer += `answer${i}: ${answers[i - 1].textContent}|` + } + + return cropText( + `Below is the content from a developer Q&A platform. Analyze answers and provide a brief solution that can solve the question first,` + + `then give an overview of all answers. The question is: "${title}", and the further description of the question is: "${description}".` + + `The answers are as follows:\n${answer}`, + ) + } + } catch (e) { + console.log(e) + } + }, +}