Skip to content

Commit 94aa37c

Browse files
committed
feat: support for stackoverflow
1 parent bffff55 commit 94aa37c

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/config.mjs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ export const defaultConfig = {
7272
// others
7373

7474
activeSelectionTools: Object.keys(toolsConfig),
75-
activeSiteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'],
75+
activeSiteAdapters: [
76+
'bilibili',
77+
'github',
78+
'gitlab',
79+
'quora',
80+
'reddit',
81+
'youtube',
82+
'zhihu',
83+
'stackoverflow',
84+
],
7685
accessToken: '',
7786
tokenSavedOn: 0,
7887

@@ -81,7 +90,16 @@ export const defaultConfig = {
8190
userLanguage: navigator.language.substring(0, 2),
8291
selectionTools: Object.keys(toolsConfig),
8392
// importing configuration will result in gpt-3-encoder being packaged into the output file
84-
siteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'],
93+
siteAdapters: [
94+
'bilibili',
95+
'github',
96+
'gitlab',
97+
'quora',
98+
'reddit',
99+
'youtube',
100+
'zhihu',
101+
'stackoverflow',
102+
],
85103
}
86104

87105
export async function getUserLanguage() {

src/content-script/site-adapters/index.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import gitlab from './gitlab'
66
import zhihu from './zhihu'
77
import reddit from './reddit'
88
import quora from './quora'
9+
import stackoverflow from './stackoverflow'
910

1011
/**
1112
* @typedef {object} SiteConfigAction
@@ -164,4 +165,10 @@ export const config = {
164165
appendContainerQuery: [],
165166
resultsContainerQuery: ['.q-box.PageContentsLayout___StyledBox-d2uxks-0'],
166167
},
168+
stackoverflow: {
169+
inputQuery: stackoverflow.inputQuery,
170+
sidebarContainerQuery: ['#sidebar'],
171+
appendContainerQuery: [],
172+
resultsContainerQuery: ['#sidebar'],
173+
},
167174
}
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
//TODO
1+
import { cropText } from '../../../utils'
2+
3+
export default {
4+
inputQuery: async () => {
5+
try {
6+
const title = document.querySelector('#question-header .question-hyperlink')?.textContent
7+
if (title) {
8+
const description = document.querySelector('.postcell .s-prose')?.textContent
9+
let answer = ''
10+
const answers = document.querySelectorAll('.answercell .s-prose')
11+
if (answers.length > 0)
12+
for (let i = 1; i <= answers.length && i <= 2; i++) {
13+
answer += `answer${i}: ${answers[i - 1].textContent}|`
14+
}
15+
16+
return cropText(
17+
`Below is the content from a developer Q&A platform. Analyze answers and provide a brief solution that can solve the question first,` +
18+
`then give an overview of all answers. The question is: "${title}", and the further description of the question is: "${description}".` +
19+
`The answers are as follows:\n${answer}`,
20+
)
21+
}
22+
} catch (e) {
23+
console.log(e)
24+
}
25+
},
26+
}

0 commit comments

Comments
 (0)