-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoterobn
89 lines (85 loc) · 2.72 KB
/
zoterobn
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
${await new Promise (async (r) => {
async function getAnnotation(item) {
try {
if (!item || !item.isAnnotation()) {
return null;
}
let json = await Zotero.Annotations.toJSON(item);
json.id = item.key;
delete json.key;
for (let key in json) {
json[key] = json[key] || "";
}
json.tags = json.tags || [];
return json;
} catch (e) {
Zotero.logError(e);
return null;
}
}
function getEditorInstance(noteId) {
return Zotero.Notes._editorInstances.find(
(e) =>
e._item.id === noteId && !Components.utils.isDeadWrapper(e._iframeWindow)
);
}
async function getAnnotationsByColor(_item, color) {
const annots = _item.getAnnotations().filter(item => item.annotationColor === color);
if (annots.length === 0) {
return {
html: "",
};
}
let annotations = [];
for (let annot of annots) {
const annotJson = await getAnnotation(annot);
annotJson.attachmentItemID = _item.id;
annotations.push(annotJson);
}
let editor = getEditorInstance(targetNoteItem.id)
if (!editor) {
alert("No active note editor detected. Please open workspace.");
return r("");
}
await editor.importImages(annotations);
return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
}
const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
i.isPDFAttachment()
);
let res = `<h1>${topItem.getField("title")}</h1>
<i>${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}</i>
<p>[${topItem.getField("DOI")}]</p>
<p>[${topItem.getField("Date")}]</p>`;
const colors = {
"#aaaaaa": "💡Purpose", // Grey
"#ffd400": "📝 Altı Çizilenler", // White
"#ff6666": "❗Önemli", // Red
"#5fb236": "❓Kaynak", // Green
"#2ea8e5": "📚Theory", // Blue
"#a28ae5": "⛏️Method", // Purple
"#e56eee": "📝Results", // Magenta
"#f19837": "👍Contribution" // Orange
}
for (const attachment of attachments) {
for (const color in colors) {
if (Object.hasOwnProperty.call(colors, color)) {
const colorName = colors[color];
const renderedAnnotations = (await getAnnotationsByColor(attachment, color)).html;
if (renderedAnnotations) {
res += `<h3><p>${colorName}</p></h3>\n${renderedAnnotations}`;
}
}
}
const renderedAnnotations = (
await getAnnotationsByColor(
attachment,
(_annot) => !colors.includes(_annot.annotationColor)
)
).html;
if (renderedAnnotations) {
res += `<h2><p>Other Annotations</p></h2>\n${renderedAnnotations}`;
}
}
r(res);
})}