Skip to content

Commit 3f51b5a

Browse files
committed
feat: overview for zhihu answers (#18)
1 parent d1c0330 commit 3f51b5a

File tree

1 file changed

+18
-5
lines changed
  • src/content-script/site-adapters/zhihu

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@ export default {
66
const title = document.querySelector('.QuestionHeader-title')?.textContent
77
if (title) {
88
const description = document.querySelector('.QuestionRichText')?.textContent
9-
const answer = document.querySelector('.AnswerItem .RichText')?.textContent
9+
const answerQuery = '.AnswerItem .RichText'
1010

11-
return cropText(
12-
`以下是一个问答平台的提问与回答内容,给出相应的摘要,以及你对此的看法.问题是:"${title}",问题的进一步描述是:"${description}".` +
13-
`其中一个回答如下:\n${answer}`,
14-
)
11+
let answer = ''
12+
if (location.pathname.includes('answer')) {
13+
answer = document.querySelector(answerQuery)?.textContent
14+
return cropText(
15+
`以下是一个问答平台的提问与回答内容,给出相应的摘要,以及你对此的看法.问题是:"${title}",问题的进一步描述是:"${description}".` +
16+
`其中一个回答如下:\n${answer}`,
17+
)
18+
} else {
19+
const answers = document.querySelectorAll(answerQuery)
20+
for (let i = 1; i <= answers.length && i <= 4; i++) {
21+
answer += `answer${i}: ${answers[i - 1].textContent}|`
22+
}
23+
return cropText(
24+
`以下是一个问答平台的提问与回答内容,给出相应的摘要,以及你对此的看法.问题是:"${title}",问题的进一步描述是:"${description}".` +
25+
`各个回答如下:\n${answer}`,
26+
)
27+
}
1528
} else {
1629
const title = document.querySelector('.Post-Title')?.textContent
1730
const description = document.querySelector('.Post-RichText')?.textContent

0 commit comments

Comments
 (0)