diff --git a/README.md b/README.md
index b1d2431..a8943d8 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@
Everything about note management. All in Zotero.
[User Guide(EN)](./UserGuide.md) | [用户指引(中文)](./UserGuideCN.md)
+
## Easy to Use
New to note-taking? Install and start now!
@@ -31,9 +32,12 @@ Discuss & contribute your templates [here](https://github.com/windingwind/zotero
## Note Enhancements
-- `LaTex` view
+- `LaTex` view
+- Copy annotation image to clipboard
+
+
- Heading indent
- Image resizing(comming soon)
diff --git a/image/README/copyimage.png b/image/README/copyimage.png
new file mode 100644
index 0000000..09cc994
Binary files /dev/null and b/image/README/copyimage.png differ
diff --git a/src/events.ts b/src/events.ts
index 2d9e1fd..ccd641a 100644
--- a/src/events.ts
+++ b/src/events.ts
@@ -1390,6 +1390,63 @@ class AddonEvents extends AddonBase {
annotationItem.annotationComment ? annotationItem.annotationComment : ""
}\nnote link: "${this._Addon.knowledge.getNoteLink(note)}"`;
await annotationItem.saveTx();
+ } else if (message.type === "copyImageAnnotation") {
+ /*
+ message.content = {
+ params: { src: string }
+ }
+ */
+ var image = message.content.params.src;
+
+ var io = Components.classes[
+ "@mozilla.org/network/io-service;1"
+ ].getService(Components.interfaces.nsIIOService);
+ var channel = io.newChannel(image, null, null);
+ var input = channel.open();
+ var imgTools = Components.classes[
+ "@mozilla.org/image/tools;1"
+ ].getService(Components.interfaces.imgITools);
+
+ var buffer = NetUtil.readInputStreamToString(input, input.available());
+ var container = imgTools.decodeImageFromBuffer(
+ buffer,
+ buffer.length,
+ channel.contentType
+ );
+
+ var trans = Components.classes[
+ "@mozilla.org/widget/transferable;1"
+ ].createInstance(Components.interfaces.nsITransferable);
+ // Add Blob
+ trans.addDataFlavor(channel.contentType);
+ trans.setTransferData(channel.contentType, container, -1);
+
+ // // Add Text
+ // let str = Components.classes[
+ // "@mozilla.org/supports-string;1"
+ // ].createInstance(Components.interfaces.nsISupportsString);
+ // str.data = text;
+ // trans.addDataFlavor("text/unicode");
+ // trans.setTransferData("text/unicode", str, text.length * 2);
+
+ // // Add HTML
+ // str = Components.classes["@mozilla.org/supports-string;1"].createInstance(
+ // Components.interfaces.nsISupportsString
+ // );
+ // str.data = html;
+ // trans.addDataFlavor("text/html");
+ // trans.setTransferData("text/html", str, html.length * 2);
+
+ var clipid = Components.interfaces.nsIClipboard;
+ var clip =
+ Components.classes["@mozilla.org/widget/clipboard;1"].getService(
+ clipid
+ );
+ clip.setData(trans, null, clipid.kGlobalClipboard);
+ this._Addon.views.showProgressWindow(
+ "Better Notes",
+ "Image copied to clipboard."
+ );
} else {
Zotero.debug(`Knowledge4Zotero: message not handled.`);
}
diff --git a/src/views.ts b/src/views.ts
index 63729dc..f1b5444 100644
--- a/src/views.ts
+++ b/src/views.ts
@@ -21,6 +21,7 @@ class AddonViews extends AddonBase {
isMainKnowledge: ``,
openAttachment: ``,
addAnnotationNote: ``,
+ copyImageAnnotation: ``,
switchTex: ``,
switchEditor: ``,
export: ``,
@@ -601,6 +602,35 @@ class AddonViews extends AddonBase {
addAnnotationNoteButton.setAttribute("style", "margin: 5px;");
});
moreButton.before(addAnnotationNoteButton);
+ if (annotationItem.annotationType === "image") {
+ // Customize image copy
+ const copyImageButton = _document.createElement("div");
+ copyImageButton.setAttribute("style", "margin: 5px;");
+ copyImageButton.innerHTML = this.editorIcon["copyImageAnnotation"];
+ copyImageButton.addEventListener("click", (e) => {
+ this._Addon.events.onEditorEvent(
+ new EditorMessage("copyImageAnnotation", {
+ params: {
+ src: (
+ copyImageButton.parentElement.parentElement
+ .nextSibling as HTMLImageElement
+ ).src,
+ },
+ })
+ );
+ e.preventDefault();
+ });
+ copyImageButton.addEventListener("mouseover", (e: XULEvent) => {
+ copyImageButton.setAttribute(
+ "style",
+ "background: #F0F0F0; margin: 5px;"
+ );
+ });
+ copyImageButton.addEventListener("mouseout", (e: XULEvent) => {
+ copyImageButton.setAttribute("style", "margin: 5px;");
+ });
+ moreButton.before(copyImageButton);
+ }
updateCount += 1;
}
return reader.annotationItemIDs.length === updateCount;
diff --git a/typing/global.d.ts b/typing/global.d.ts
index 46b4fa7..73a7f2d 100644
--- a/typing/global.d.ts
+++ b/typing/global.d.ts
@@ -79,6 +79,8 @@ declare const OS: {
};
};
+declare const NetUtil: { [attr: string]: any };
+
declare interface ZoteroItem {
id: number;
isRegularItem: () => boolean;