Skip to content

Commit

Permalink
优化克隆对话
Browse files Browse the repository at this point in the history
  • Loading branch information
xcanwin committed May 19, 2024
1 parent 4698115 commit 7846170
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 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.4
// @version 28.5
// @author xcanwin
// @namespace https://github.com/xcanwin/KeepChatGPT/
// @supportURL https://github.com/xcanwin/KeepChatGPT/
Expand Down Expand Up @@ -908,12 +908,6 @@
}
}
/*克隆对话*/
main .text-sm.flex-col>.text-token-text-primary .mx-auto>div:first-child {
user-select: none;
cursor: pointer;
}
/*明察秋毫*/
.kkeenobservation {
/*用户气泡优化*/
Expand Down Expand Up @@ -1256,6 +1250,7 @@ nav.flex .transition-all {
克隆对话
*/
const cloneChat = function(action) {
cloneChat.firstTarget = null;
if (action === true) {
window.addEventListener('click', cloneChat.listen_Click);
} else {
Expand All @@ -1265,13 +1260,23 @@ nav.flex .transition-all {

cloneChat.listen_Click = function(event) {
const avatarSelector = "main .text-sm.flex-col>.text-token-text-primary .mx-auto>div:first-child";
const avatarDiv = findParent(event.target, avatarSelector);
const avatarDiv = findParent(event.target, avatarSelector, 10);
if (avatarDiv) {
const contentSelector = ".max-w-full .text-message";
const content = $(contentSelector, findParent(avatarDiv, "main .text-sm.flex-col>.text-token-text-primary .mx-auto", 2)).innerText.trim();
$("form.w-full textarea").value = "";
$("form.w-full textarea").focus();
document.execCommand('insertText', false, content);
const selectionText = window.getSelection().toString();
if (selectionText.length === 0) { //未选中文本时
if (!cloneChat.firstTarget || (cloneChat.firstTarget && cloneChat.firstTarget !== avatarDiv)){ //普通单击时执行克隆,以及选中文本时记录的选中元素与当前单击元素不同时执行克隆
const contentSelector = ".max-w-full .text-message";
const content = $(contentSelector, findParent(avatarDiv, "main .text-sm.flex-col>.text-token-text-primary .mx-auto", 2)).innerText.trim();
$("form.w-full textarea").value = "";
$("form.w-full textarea").focus();
document.execCommand('insertText', false, content);
}
cloneChat.firstTarget = null;
} else { //选中文本时记录选中元素
cloneChat.firstTarget = avatarDiv;
}
} else {
cloneChat.firstTarget = null;
}
};

Expand Down

0 comments on commit 7846170

Please sign in to comment.