-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
137 lines (110 loc) · 3.5 KB
/
index.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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
let isRequesting = false;
const API_URL = "http://127.0.0.1:5000/";
function init() {
const shareButton = createBtn();
function appendShareButton() {
const buttonsWrapper = document.querySelector(
"#root > div.apppage > div:nth-child(1) > div.container-fluid.chattop > div:nth-child(3) > div.row.pb-1.pt-2.justify-content-between.chatheaderbg-normal.align-items-center > div.col-3.col-md-3 > div > div"
);
if (buttonsWrapper) {
buttonsWrapper.appendChild(shareButton);
}
}
appendShareButton();
const id = setInterval(() => {
if (
!document.querySelector("#export-button") ||
document.querySelector("#export-button").style.display === "none"
) {
appendShareButton();
}
}, 300);
shareButton.addEventListener("click", async () => {
if (isRequesting) return;
isRequesting = true;
shareButton.innerHTML = "📋 Copied!";
setTimeout(function () {
shareButton.innerHTML = "✂️ Copy";
}, 500);
shareButton.style.cursor = "pointer";
isRequesting = false;
console.log(document.title);
const find = document.querySelectorAll('[class*="inner-scroll-view"]');
console.log(find);
const threadContainer = find[0];
console.log(threadContainer);
const conversationData = {
title: document.title,
items: [],
};
for (const node of threadContainer.children) {
const AI_NAME = document.title.split("-")[1].trim();
const img = node.querySelector("img");
const markdown = node.querySelector("p");
if (img) {
conversationData.items.push({
from: `${AI_NAME}`,
value: markdown.textContent,
});
} else {
conversationData.items.push({
from: "human",
value: markdown.textContent,
});
}
}
console.log(JSON.stringify(conversationData));
console.log(JSON.stringify(conversationData.items));
navigator.clipboard
.writeText(JSON.stringify(conversationData))
.then(() => {
console.log("JSON copied to clipboard");
})
.catch((err) => {
console.log("Error copying JSON to clipboard:", err);
});
// setTimeout(() => {
// shareButton.innerHTML = "✂️ Copy";
// shareButton.style.cursor = "pointer";
// isRequesting = false;
// }, 1000);
});
}
function showIfNotLoading(loadingElement, newElement) {
const timerId = setInterval(() => {
if (loadingElement.disabled) {
isLoading = true;
newElement.style.display = "none";
} else {
isLoading = false;
newElement.style.display = "flex";
clearInterval(timerId);
}
}, 100);
}
// function getAvatarImage() {
// // Create a canvas element
// try {
// const canvas = document.createElement("canvas");
// const image = document.querySelectorAll("img")[3];
// // Set the canvas size to 30x30 pixels
// canvas.width = 48;
// canvas.height = 48;
// // Draw the img onto the canvas
// canvas.getContext("2d").drawImage(image, 0, 0);
// // Convert the canvas to a base64 string as a JPEG image
// const base64 = canvas.toDataURL("image/jpeg");
// return base64;
// } catch (error) {
// console.log("Error generating avatar image.");
// return null;
// }
// }
function createBtn() {
const button = document.createElement("button");
button.id = "export-button";
button.classList.add("btn", "flex", "justify-center", "btn-neutral");
button.textContent = "✂️ Copy";
return button;
}
init();