Skip to content

Commit

Permalink
Merge pull request #415 from AZCodingAccount/main
Browse files Browse the repository at this point in the history
feat: Copilot输入框自动聚焦&更改初始化后的提示文本
  • Loading branch information
NB-Group authored May 8, 2024
2 parents ad59473 + ebc6c2f commit 7c31b00
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,13 @@ function decodeHtml(s) {
$('#translater').text(s);
return $('#translater').html().replace(/\n/g, '<br>').replace(/ /g, '&nbsp;');
}
function msgDoneOperate(){
$("#copilot>.inputbox").removeClass("disable");
setTimeout(() => {
$("#copilot>.inputbox>.input").focus();
}, 100); // 延迟0.1s以避免与blur方法冲突
}
let isFirstChat=true; // 标记是否是刚进来时服务端返回的消息
let copilot = {
history: [],
init: () => {
Expand Down Expand Up @@ -2945,15 +2952,15 @@ let copilot = {
// 2.在浏览器中打开链接、搜索<br>
// 3.发送对系统、ai助手的反馈
// 注意:请勿滥用本ai助手,否则将下个版本将撤销此功能,影响所有人。</p></div>`);
$('#copilot>.chat').append(`<div class="line system"><p class="text">正在初始化...</p></div>`);
$('#copilot>.chat').append(`<div class="line system"><p class="text" id="init-message">正在初始化...</p></div>`);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
},
send: (t, showusr = true,role="user") => {
$('#copilot>.inputbox').addClass('disable');
if (t.length == 0) {
$('#copilot>.chat').append(`<div class="line system"><p class="text">系统表示请发一些有意义的东西</p></div>`);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
$('#copilot>.inputbox').removeClass('disable');
msgDoneOperate();
return;
}
if (copilot.history.length > 3){ // 万年代码,千万不要改
Expand All @@ -2968,11 +2975,17 @@ let copilot = {
contentType: 'application/json',
data: JSON.stringify({ msg: copilot.history }),
}).then(rt => {
msgDoneOperate();
// 替换初始化完成的文本内容
if (isFirstChat) {
$("#init-message").html(`初始化完成!`);
isFirstChat = false;
}
console.log(rt);
if (rt == '请求过于频繁,等待10秒再试...') {
$('#copilot>.chat').append(`<div class="line system"><p class="text">api繁忙,过一会儿再试(实在不行刷新重新开始对话)</p></div>`);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
$('#copilot>.inputbox').removeClass('disable');
msgDoneOperate();
return;
}
let rtt = rt; let r = [];
Expand Down Expand Up @@ -3014,12 +3027,12 @@ let copilot = {
}
copilot.history.push({ role: 'assistant', content: rtt });
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
$('#copilot>.inputbox').removeClass('disable');
msgDoneOperate();
}).fail(r => {
console.log(r);
$('#copilot>.chat').append(`<div class="line system"><p class="text">发生错误,请查看控制台输出或重试</p></div>`);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
$('#copilot>.inputbox').removeClass('disable');
msgDoneOperate();
});
}
}
Expand Down

0 comments on commit 7c31b00

Please sign in to comment.