-
Notifications
You must be signed in to change notification settings - Fork 1
/
ai-ui.js
104 lines (89 loc) · 2.73 KB
/
ai-ui.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
AiUi = {
editcandidate(id){
var c = document.getElementById(id);
c.contentEditable = "true";
c.style.backgroundColor = "#efedff";
c.focus();
},
savecandidate(id)
{
var c = document.getElementById(id);
c.contentEditable = "false";
c.style.backgroundColor = "";
},
acceptcandidate(id, currentcomment, annotation=false, mode="bard")
{
if(!annotation)
{
alert("No destination annotation!\nThis button adds the current element to annotation.\nIf you want to add the results to an annotation, right click on the annotation.");
return;
}
var c = document.getElementById(id);
var comment = c.innerText;
annotation.annotationComment = currentcomment+"\n\n<b>[Paraphrase]</b>\n"+comment+"\n";
if(["g-translate", "deepl-translate"].includes(mode))
{
annotation.annotationComment = currentcomment+"\n\n<b>[Translation]</b>\n"+comment+"\n";
}
annotation.saveTx({skipSelect:true}).then(e=>{
Zotero.ZeNotes.Ui.reload();
});
},
createdialog(annotation, currentcomment, candidates, mode="bard")
{
var confirm_message = "Do you want to add this content to the annotation?";
if(mode=="g-translate")
{
confirm_message = "Do you want to add this translation to the annotation?";
}
var table = document.createElement("table");
table.id = "zn-ai-table";
var th = document.createElement("tr");
table.appendChild(th);
for(h of ["Candidate", "Content", ""])
{
let td = document.createElement("td");
td.innerHTML = h;
th.appendChild(td);
}
var i = 0;
for(line of candidates)
{
let tr = document.createElement("tr");
table.appendChild(tr);
let id = document.createElement("td");
id.innerHTML = i+1;
tr.appendChild(id);
let candidate = document.createElement("td");
candidate.id = "ai-candidate-"+i;
candidate.addEventListener("blur", function(e){
AiUi.savecandidate(e.target.id);
})
tr.appendChild(candidate);
candidate.innerHTML = line;
let buttons = document.createElement("td");
tr.appendChild(buttons);
let edit = document.createElement("i");
edit.className = "fas fa-pen zn-button";
edit.dataset.candidateid = "ai-candidate-"+i;
edit.addEventListener("click", function(e){
AiUi.editcandidate(e.target.dataset.candidateid);
});
buttons.appendChild(edit);
let accept = document.createElement("i");
accept.className = "fas fa-check zn-button";
accept.dataset.candidateid = "ai-candidate-"+i;
accept.title = "Use this candidate."
accept.addEventListener("click", function(e){
if(!confirm(confirm_message))
{
return;
}
AiUi.acceptcandidate(e.target.dataset.candidateid, currentcomment, annotation, mode);
});
buttons.appendChild(accept);
i+=1;
}
return table;
}
}