-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
26 lines (22 loc) · 818 Bytes
/
client.js
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
;(()=>{
const outputTarget = document.getElementById('output')
const outputTargetDiv = document.getElementById('output_div')
window.pageHandler = window.pageHandler || {}
pageHandler.handleGenerate = async ()=>{
outputTargetDiv.innerText = '生成中'
const ret = await requestGPT(outputTarget.value)
try{
outputTargetDiv.innerText = ret.data.choices[0].message.content
pageHandler.copyResult()
}catch(e){
outputTargetDiv.innerText = e + '\n' + JSON.stringify(ret)
}
}
pageHandler.copyResult = ()=>{
utools.copyText(outputTargetDiv.innerText)
}
window.utools.onPluginEnter(async ({code,type,payload})=>{
outputTarget.value = payload
pageHandler.handleGenerate()
})
})()