From 532e9f1b8d7216fbbf0449221f14b4b92ea4635a Mon Sep 17 00:00:00 2001 From: frianasoa Date: Tue, 13 Dec 2022 18:21:35 +0900 Subject: [PATCH] Can open pdf files with zotero or external reader now. --- chrome/content/zenotes/data.js | 30 +++++++++++++-- chrome/content/zenotes/notes.js | 62 ++++++++++++++++++++++++++----- chrome/content/zenotes/zenotes.js | 4 +- install.rdf | 2 +- zenote-update.rdf | 6 +-- 5 files changed, 84 insertions(+), 20 deletions(-) diff --git a/chrome/content/zenotes/data.js b/chrome/content/zenotes/data.js index 69c4578..f2f65be 100644 --- a/chrome/content/zenotes/data.js +++ b/chrome/content/zenotes/data.js @@ -7,7 +7,11 @@ var Zotero = Components.classes["@zotero.org/Zotero;1"] var zp = Zotero.getActiveZoteroPane(); var document = zp.document; var window = document.defaultView; -var alert = window.alert; + +var znstr = function(name, params) +{ + return Zotero.ZeNotes.ZNStr(name, params); +} Zotero.ZeNotes.data = new function() { @@ -122,7 +126,19 @@ Zotero.ZeNotes.data = new function() var path = attachment.attachmentPath; filename = Zotero.Attachments.resolveRelativePath(path); } - return filename + return filename; + } + + this.filekey = function(item) + { + var attachmentIDs = item.getAttachments(); + var key = ""; + if(attachmentIDs.length>0) + { + var attachment = Zotero.Items.get(attachmentIDs[0]); + key = attachment.key; + } + return key; } this.pdfnotes = function(item) @@ -178,7 +194,14 @@ Zotero.ZeNotes.data = new function() var n = pdfnotes[j]; var authors = Zotero.ZeNotes.data.creatorshort(item); var year = Zotero.ZeNotes.data.year(item); - var note = n["annotationComment"]+"

Direct quote

“"+n["annotationText"]+"”
("+authors+" "+year+", p. "+n["annotationPageLabel"]+")"; + var contents = "“"+n["annotationText"]+"” ("+authors+" "+year+", p. "+n["annotationPageLabel"]+")"; + + if(n["annotationText"]==null) + { + contents = "(p. "+n["annotationPageLabel"]+")" + } + + var note = n["annotationComment"]+"
"+contents+"
"; var tags = n.getTags(); for(let i in tags) @@ -220,6 +243,7 @@ Zotero.ZeNotes.data = new function() author: Zotero.ZeNotes.data.creatorshort(item)+" ("+Zotero.ZeNotes.data.year(item)+")", creators: Zotero.ZeNotes.data.creators(item), filename: Zotero.ZeNotes.data.filename(item), + filekey: Zotero.ZeNotes.data.filekey(item), } line = Object.assign({},line, tags); if(Object.keys(tags).length>0) diff --git a/chrome/content/zenotes/notes.js b/chrome/content/zenotes/notes.js index 63b0058..e221398 100644 --- a/chrome/content/zenotes/notes.js +++ b/chrome/content/zenotes/notes.js @@ -36,14 +36,19 @@ var notes = new function() vm.actions(key, options) }, items: { - "edit": {name: "Edit", icon: "fa-edit"}, - "showentry": {name: "Show entry", icon: "fa-file-lines"}, - "showfile": {name: "Show attached file", icon: "fa-file-pdf"}, + "edit": {name: "Edit note", icon: "fa-pencil-alt"}, + "editpdfnote": {name: "Edit annotation", icon: "fa-edit"}, "sep0": "---------", + "showentry": {name: "Show entry", icon: "fa-file-lines"}, + "showfile": {name: "Show attached file (External reader)", icon: "fa-file-pdf"}, + "showfilezotero": {name: "Show attached file (Zotero reader)", icon: "fa-file-pdf"}, + "sep2": "---------", "hidecolumn": {name: "Hide column", icon: "fa-eye-slash"}, "deletenote": {name: "Delete note", icon: "fa-trash"}, - "sep1": "---------", - "copycell": {name: "Copy cell", icon: "fa-eye-slash"}, + "sep3": "---------", + "copycell": {name: "Copy entire cell", icon: "fa-clone"}, + "copyquote": {name: "Copy direct quote", icon: "fa-copy"}, + "copysel": {name: "Copy selection", icon: "fa-copy"}, // "quit": {name: "Exit", icon: "fa-xmark"}, } }); @@ -65,7 +70,8 @@ var notes = new function() "showfile": {name: "Show attached file", icon: "fa-file-pdf"}, "hidecolumn": {name: "Hide column", icon: "fa-eye-slash"}, "sep1": "---------", - "copycell": {name: "Copy cell", icon: "fa-eye-slash"}, + "copycell": {name: "Copy entire cell", icon: "fa-clone"}, + "copysel": {name: "Copy selection", icon: "fa-copy"}, // "quit": {name: "Exit", icon: "fa-xmark"}, } }); @@ -161,6 +167,15 @@ var notes = new function() td.dataset.itemid = v.itemid; td.dataset.itemkey = v.key; td.dataset.filename = v.filename; + td.dataset.filekey = v.filekey; + td.querySelectorAll(".annotation").forEach(a=>{ + a.addEventListener("mouseover", function(e){ + e.target.parentNode.dataset.attachmentkey = e.target.dataset.attachmentkey; + e.target.parentNode.dataset.attachmentpage = e.target.dataset.page; + e.target.parentNode.dataset.annotationkey = e.target.dataset.key; + e.target.parentNode.dataset.annotationdomid = e.target.id; + }); + }); tr.appendChild(td); }); }); @@ -173,10 +188,14 @@ var notes = new function() var column = td.dataset.column; var itemid = td.dataset.itemid; var itemkey = td.dataset.itemkey; + var attachmentkey = td.dataset.attachmentkey + var annotationkey = td.dataset.annotationkey; + var annotationpage = td.dataset.annotationpage; + var annotationdomid = td.dataset.annotationdomid; var filename = td.dataset.filename; + var filekey = td.dataset.filekey; var notekey = td.dataset.notekey; - if(key=="showentry") { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); @@ -201,9 +220,15 @@ var notes = new function() this.opennote(notekey); } } + else if(key=="editpdfnote") + { + var uri = "zotero://open-pdf/library/items/"+attachmentkey+"?page="+annotationpage+"&annotation="+annotationkey; + Zotero.launchURL(uri); + } else if(key=="showfile") { filename = filename.replace("\\", "/"); + filename = filename.replace("\\\\", "/"); if(filename=="false") { alert("File not found!"); @@ -212,7 +237,11 @@ var notes = new function() { window.openDialog("file:///"+filename); } - + } + else if(key=="showfilezotero") + { + var uri = "zotero://open-pdf/library/items/"+filekey; + Zotero.launchURL(uri); } else if(key=="hidecolumn") { @@ -257,7 +286,20 @@ var notes = new function() { this.copy(td); } - + else if(key=="copyquote") + { + var quote = document.getElementById(annotationdomid); + var range = document.createRange(); + range.selectNode(quote); + window.getSelection().removeAllRanges(); + window.getSelection().addRange(range); + document.execCommand("copy"); + window.getSelection().removeAllRanges(); + } + else if(key=="copysel") + { + document.execCommand('copy'); + } else if(key=="addrow") { this.addrow(); @@ -303,7 +345,7 @@ var notes = new function() if(["note", "attachment"].includes(type)) { - alert("Cannot attach a not to '"+type+"'"); + alert("Cannot attach a note to '"+type+"'"); return; } var show = Zotero.ZeNotes.settings.lists.show; diff --git a/chrome/content/zenotes/zenotes.js b/chrome/content/zenotes/zenotes.js index 2832d91..13fa746 100644 --- a/chrome/content/zenotes/zenotes.js +++ b/chrome/content/zenotes/zenotes.js @@ -142,9 +142,7 @@ Zotero.ZeNotes = new function() var name = "zenotes-notes"; Zotero.ZeNotes.openwindow(url, name, io); } - - - + this.download = function(type) { diff --git a/install.rdf b/install.rdf index b60be23..ae4c377 100644 --- a/install.rdf +++ b/install.rdf @@ -5,7 +5,7 @@ zenotes@alefa.net ZeNotes - 0.2.4 + 0.2.5 2 true Fanantenana Rianasoa Andriariniaina diff --git a/zenote-update.rdf b/zenote-update.rdf index 60c0a10..4e66a02 100644 --- a/zenote-update.rdf +++ b/zenote-update.rdf @@ -5,13 +5,13 @@ - 0.2.4 + 0.2.5 zotero@chnm.gmu.edu 5.0.0 6.* - https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.4/zenotes-v0.2.4.xpi + https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.5/zenotes-v0.2.5.xpi @@ -20,7 +20,7 @@ juris-m@juris-m.github.io 4.999 6.* - https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.4/zenotes-v0.2.4.xpi + https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.5/zenotes-v0.2.5.xpi