[Item] A slightly modified version of annotation collection by color #406
Replies: 11 comments 37 replies
-
The following version works in the latest Zotero. If you encounter problems (e.g., annotations won't show) when using the above version, please try this one. ${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>`;
const colors = {
"#aaaaaa": "💡Purpose", // Grey
"#ffd400": "🖌️General & Images", // Yellow
"#ff6666": "❗Attention", // Red
"#5fb236": "❓Hypotheses", // Green
"#2ea8e5": "📚Theory", // Blue
"#a28ae5": "⛏️Method", // Purple
"#e56eee": "📝Results", // Magenta
"#f19837": "👍Contribution" // Orange
}
for (const attachment of attachments) {
res += `<h2>📄For Document:${attachment.attachmentFilename}</h2>`;
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 style="background-color:${color};">${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);
})} The problem is caused by variable function getEditorInstance(noteId) {
return Zotero.Notes._editorInstances.find(
(e) =>
e._item.id === noteId && !Components.utils.isDeadWrapper(e._iframeWindow)
);
} Then just call it to get the + let editor = getEditorInstance(targetNoteItem.id)
if (!editor) {
alert("No active note editor detected. Please open workspace.");
return r("");
}
await editor.importImages(annotations); |
Beta Was this translation helpful? Give feedback.
-
Yes,my template is still work well. My zotero’s vesion is 6.0.26.
And my Zotero Better Notes‘ version is 1.0.4.
But I encountered a few times that an empty note was generated.
It might be related to the steps you take to create notes.
After you make annotations on the paper,
you should first create a new Item note from Zotero Better Notes.
Then, you will get an empty note, please don’t give up.
You should click the gear icon, then choose the ‘Insert template at cursor’
Finally, you will get the right note with annotations grouped by color
I hope my experience can help you.
从 Windows 版邮件发送
发件人: Gino
发送时间: 2023年6月13日 1:40
收件人: windingwind/zotero-better-notes
抄送: butterflyli; Comment
主题: Re: [windingwind/zotero-better-notes] [Item] A slightly modifiedversion of annotation collection by color (Discussion #406)
Your template is still work? Mine is broken in the latest version zotero. There is only a empty note be generated.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Use this, based on @HPDell : One-click to import.
Click to show the templatename: "[Item] A slightly modified version of annotation collection by color"
content: |-
// @author LynnXie00, HPDell, and windingwind
// @link https://github.com/windingwind/zotero-better-notes/discussions/406
${{
async function getAnnotationsByColor(_item, color) {
const annots = _item
.getAnnotations()
.filter((item) => item.annotationColor === color);
if (annots.length === 0) {
return "";
}
return Zotero.BetterNotes.api.convert.annotations2html(annots, {
noteItem: targetNoteItem,
});
}
const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
i.isPDFAttachment()
);
let res = `<h1>${topItem.getField("title")}</h1>`;
const colors = {
"#aaaaaa": "💡Purpose", // Grey
"#ffd400": "🖌️General & Images", // Yellow
"#ff6666": "❗Attention", // Red
"#5fb236": "❓Hypotheses", // Green
"#2ea8e5": "📚Theory", // Blue
"#a28ae5": "⛏️Method", // Purple
"#e56eee": "📝Results", // Magenta
"#f19837": "👍Contribution", // Orange
};
for (const attachment of attachments) {
res += `<h2>📄For Document:${attachment.attachmentFilename}</h2>`;
for (const color in colors) {
if (Object.hasOwnProperty.call(colors, color)) {
const colorName = colors[color];
const renderedAnnotations = await getAnnotationsByColor(
attachment,
color
);
if (renderedAnnotations) {
res += `<h3><p style="background-color:${color};">${colorName}</p></h3>\n${renderedAnnotations}`;
}
}
}
const renderedAnnotations = await getAnnotationsByColor(
attachment,
(_annot) => !colors.includes(_annot.annotationColor)
);
if (renderedAnnotations) {
res += `<h2><p>Other Annotations</p></h2>\n${renderedAnnotations}`;
}
}
return res;
}}$
|
Beta Was this translation helpful? Give feedback.
-
怎么下线这个插件啊友友们 |
Beta Was this translation helpful? Give feedback.
-
This note template is very useful, and I've modified the colors of the annotations to match my reading preferences. However, I'm wondering if it's possible to also make the text color in the notes consistent with the annotation colors. // @author LynnXie00, HPDell, and windingwind const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) => let res = const colors = { "#ffd400": "🖌️Overview", // Yellow |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for this template! I modified it for my own color coding (which also includes colors used by the Boox Neoreader)
|
Beta Was this translation helpful? Give feedback.
-
每次如果annotation 更新了,note 也更着更新或者有快捷键点一下就更新就好了。 |
Beta Was this translation helpful? Give feedback.
-
Seems not to be working with the recent zotero versions. |
Beta Was this translation helpful? Give feedback.
-
I get the error Zotero 7.0.7 and Better Notes 2.0.17 Any idea what could cause that ? |
Beta Was this translation helpful? Give feedback.
-
**2024-10-10
Guys, I updated the scripts. With the Zotero 7 and Better Notes, for some reason, the script can't import annotations that contain images anymore. (I'm not a programmer and that's all I can do lol.... So you probably need to import images into Zotero notes manually. But the other part works fine for me. **
This code is modified based on later versions in this thread
#406 (comment)
Type: Item
Description: This template maps certain colors with certain meanings in annotations.
I use gray for purpose, yellow for general, red for attention, green for hypotheses, blue for theory, purple for method, magenta for results, and orange for contribution.
You may change this code to change your own color style.
How to use it:
Showcase result:
Template Contents:
I'd greatly appreciate it if anyone knows how to improve the codes...
In the old script there's one line:
Beta Was this translation helpful? Give feedback.
All reactions