-
Notifications
You must be signed in to change notification settings - Fork 855
Expand file tree
/
Copy pathindex.mjs
More file actions
51 lines (48 loc) · 1.99 KB
/
index.mjs
File metadata and controls
51 lines (48 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { cropText } from '../../../utils'
export default {
inputQuery: async () => {
try {
const title = document.querySelector('.QuestionHeader-title')?.textContent
if (title) {
const description = document.querySelector('.QuestionRichText')?.textContent
const answerQuery = '.AnswerItem .RichText'
let answer = ''
if (location.pathname.includes('answer')) {
answer = document.querySelector(answerQuery)?.textContent
return await cropText(
`You are an insightful analyst of Q&A discussions. ` +
`Below is content from Zhihu, a Q&A platform. Please provide a summary of the question and answer, and your opinion on them.\n` +
`Question: "${title}"\n` +
`Description: "${description}"\n` +
`Answer:\n${answer}`,
)
} else {
const answers = document.querySelectorAll(answerQuery)
for (let i = 1; i <= answers.length && i <= 4; i++) {
answer += `answer${i}: ${answers[i - 1].textContent}|`
}
return await cropText(
`You are an insightful analyst of Q&A discussions. ` +
`Below is content from Zhihu, a Q&A platform. Please provide a summary of the question and answers, and your opinion on them.\n` +
`Question: "${title}"\n` +
`Description: "${description}"\n` +
`Answers:\n${answer}`,
)
}
} else {
const title = document.querySelector('.Post-Title')?.textContent
const description = document.querySelector('.Post-RichText')?.textContent
if (title) {
return await cropText(
`You are an expert article analyst. ` +
`Below is an article from Zhihu. Please provide a summary of the article and your opinion on it.\n` +
`Title: "${title}"\n` +
`Content:\n"${description}"`,
)
}
}
} catch (e) {
console.log(e)
}
},
}