Skip to content

Commit

Permalink
修复删除侧边栏历史对话时未刷新侧边栏的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xcanwin committed May 22, 2024
1 parent 51b3aa4 commit 0077910
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions KeepChatGPT.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name KeepChatGPT
// @description 这是一款提高ChatGPT的数据安全能力和效率的插件。并且免费共享大量创新功能,如:自动刷新、保持活跃、数据安全、取消审计、克隆对话、言无不尽、净化页面、展示大屏、拦截跟踪、日新月异、明察秋毫等。让我们的AI体验无比安全、顺畅、丝滑、高效、简洁。
// @version 28.7
// @version 28.8
// @author xcanwin
// @namespace https://github.com/xcanwin/KeepChatGPT/
// @supportURL https://github.com/xcanwin/KeepChatGPT/
Expand Down Expand Up @@ -1057,6 +1057,8 @@ nav.flex .transition-all {
unsafeWindow.fetch = new Proxy(fetch, {
apply: function (target, thisArg, argumentsList) {
const fetchReqUrl = argumentsList[0];
const fetchReqOptions = argumentsList[1];
const fetchReqMethod = fetchReqOptions?.method?.toUpperCase();
let fetchRsp;
try {
const block_url = 'gravatar\.com|browser-intake-datadoghq\.com|\.wp\.com|intercomcdn\.com|sentry\.io|sentry_key=|intercom\.io|featuregates\.org|/v1/initialize|/messenger/|statsigapi\.net|/rgstr|/v1/sdk_exception';
Expand Down Expand Up @@ -1120,27 +1122,39 @@ nav.flex .transition-all {
}, 1000);//有点bug
return Promise.resolve(new Response(fetchRspBodyNew, {status: response.status, statusText: response.statusText, headers: response.headers}));
});
} else if (gv("k_everchanging", false) === true && fetchReqUrl.match('/backend-api/conversation/')) {
//点击侧边栏的历史对话时,更新数据库:当前id、当前标题、当前更新时间,当前last,当前model。同时更新侧边栏
} else if (gv("k_everchanging", false) === true && fetchReqUrl.match('/backend-api/conversation/(.*?)(\\?|$)')) {
//点击/编辑/删除侧边栏的历史对话时,更新数据库:当前id、当前标题、当前更新时间,当前last,当前model。同时更新侧边栏
return response.text().then(async fetchRspBody => {
let fetchRspBodyNew = fetchRspBody;
const f = JSON.parse(fetchRspBody);
const crt_con_id = f && f.conversation_id;
const crt_con_title = f && f.title;
let crt_con_update_time = f && f.update_time;
crt_con_update_time = crt_con_update_time < 10**10 ? crt_con_update_time * 1000 : crt_con_update_time;
crt_con_update_time = new Date(crt_con_update_time);
const crt_con_speak_last_keys = f && f.mapping && Object.keys(f.mapping);
const crt_con_speak_last_id = crt_con_speak_last_keys[crt_con_speak_last_keys.length - 1]
const crt_con_speak_last = f.mapping[crt_con_speak_last_id].message
const crt_con_last = crt_con_speak_last.content.parts[0].trim().replace(/[\r\n]/g, ``).substr(0, 100);
const crt_con_model = crt_con_speak_last.metadata.model_slug;
await global.st_ec.put({id: crt_con_id, title: crt_con_title, update_time: crt_con_update_time, last: crt_con_last, model: crt_con_model});
let kec_object = {};
kec_object[crt_con_id] = {title: crt_con_title, update_time: crt_con_update_time, last: crt_con_last, model: crt_con_model};
setTimeout(function() {
attachDate(kec_object);
}, 300);
if (fetchReqMethod === 'GET') {
//点击/编辑历史对话
const f = JSON.parse(fetchRspBody);
const crt_con_id = f && f.conversation_id;
const crt_con_title = f && f.title;
let crt_con_update_time = f && f.update_time;
crt_con_update_time = crt_con_update_time < 10**10 ? crt_con_update_time * 1000 : crt_con_update_time;
crt_con_update_time = new Date(crt_con_update_time);
const crt_con_speak_last_keys = f && f.mapping && Object.keys(f.mapping);
const crt_con_speak_last_id = crt_con_speak_last_keys[crt_con_speak_last_keys.length - 1]
const crt_con_speak_last = f.mapping[crt_con_speak_last_id].message
const crt_con_last = crt_con_speak_last.content.parts[0].trim().replace(/[\r\n]/g, ``).substr(0, 100);
const crt_con_model = crt_con_speak_last.metadata.model_slug;
await global.st_ec.put({id: crt_con_id, title: crt_con_title, update_time: crt_con_update_time, last: crt_con_last, model: crt_con_model});
let kec_object = {};
kec_object[crt_con_id] = {title: crt_con_title, update_time: crt_con_update_time, last: crt_con_last, model: crt_con_model};
setTimeout(function() {
attachDate(kec_object);
}, 300);
} else if (fetchReqMethod === 'PATCH') {
//删除历史对话
const f = JSON.parse(fetchRspBody);
const crt_con_id = fetchReqUrl.match('/backend-api/conversation/(.*?)(\\?|$)')[1];
const crt_con_title = f && f.title;
const is_visible = f && f.is_visible;
if (is_visible) {
await global.st_ec.delete({id: crt_con_id});
}
}
return Promise.resolve(new Response(fetchRspBodyNew, {status: response.status, statusText: response.statusText, headers: response.headers}));
});
}
Expand Down

0 comments on commit 0077910

Please sign in to comment.