feat: support for stackoverflow

This commit is contained in:
josc146
2023-03-19 21:41:19 +08:00
parent b5af1dc00b
commit bb8e61366b
3 changed files with 53 additions and 3 deletions
@@ -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'],
},
}
@@ -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)
}
},
}