-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.js
65 lines (58 loc) · 2.03 KB
/
editor.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
function contextCopy() {
const selectedText = document.querySelector('.ql-editor').textContent;
navigator.clipboard.writeText(selectedText).then(() => {
closeQuillContextMenu();
}).catch(err => {
console.error('Failed to copy text: ', err);
});
}
function contextCut() {
contextCopy();
const range = quill.getSelection();
quill.deleteText(range.index, range.length);
}
function contextPaste() {
clipboardText = navigator.clipboard.readText()
.then(text => {
quill.pasteHTML(text);
closeQuillContextMenu();
})
.catch(err => {
console.error('Failed to paste text: ', err);
});
}
function contextPasteWithoutFormatting() {
}
function closeGeneratePopup() {
const generatePopup = document.querySelector('#generatePopup');
generatePopup.style.opacity = 0;
generatePopup.style.pointerEvents = 'none';
document.querySelector(".main-content").removeEventListener('click', closeGeneratePopup);
}
function openGeneratePopup(e) {
closeQuillContextMenu();
const generatePopup = document.querySelector('#generatePopup');
generatePopup.style.top = `${e.clientY}px`;
generatePopup.style.left = `${e.clientX}px`;
generatePopup.style.opacity = 1;
generatePopup.style.pointerEvents = 'auto';
document.querySelector(".main-content").addEventListener('click', closeGeneratePopup);
}
document.querySelector("#openGeneratePopupButton").addEventListener('click', openGeneratePopup);
function generateText() {
const generateInput = document.querySelector('#generateInput');
const prompt = encodeURIComponent(generateInput.value);
fetch(`http://localhost:5000/api/promptGemini`, {
method: 'POST',
body: JSON.stringify({ prompt: prompt }),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
quill.pasteHTML(data.text);
closeGeneratePopup();
})
.catch(error => console.error('Error:', error));
}