Skip to content

Commit

Permalink
Fixed adding untagged notes and annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Dec 15, 2023
1 parent 718ba9f commit 6f219f9
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 36 deletions.
32 changes: 10 additions & 22 deletions content/notes/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,11 @@ Notes = {
td.className = "context-menu-one tag";
}

var span = td.querySelector(".notekey");

if(span)
{
td.dataset.notekey = span.innerText;
span.parentNode.removeChild(span);
}
else
{
td.dataset.notekey = "";
}
td.querySelectorAll(".user-note").forEach(div=>{
div.addEventListener("mouseover", function(e){
e.target.closest("td").dataset.notekey=div.dataset.notekey;
})
})

td.dataset.column = c;
td.dataset.itemid = v.itemid;
Expand Down Expand Up @@ -284,17 +278,11 @@ Notes = {
td.className = "context-menu-one tag";
}

var span = td.querySelector(".notekey");

if(span)
{
td.dataset.notekey = span.innerText;
span.parentNode.removeChild(span);
}
else
{
td.dataset.notekey = "";
}
td.querySelectorAll(".user-note").forEach(div=>{
div.addEventListener("mouseover", function(e){
e.target.closest("td").dataset.notekey=div.dataset.notekey;
})
})

td.dataset.column = c;
td.dataset.itemid = v.itemid;
Expand Down
10 changes: 8 additions & 2 deletions core/ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ Ai={
}
else if(mode=="gemini-pro")
{
// alert(JSON.stringify(data));
try {
return Promise.resolve(data.candidates.map(function(v){return v.content.parts.map(function(w){return w.text})}));
}
catch(e) {
return Promise.resolve([data.error.message]);
if(data.candidates[0].finishReason=="OTHER")
{
return Promise.resolve(["Error: No results found!"]);
}
else
{
return Promise.resolve(e);
}
}
}
else if(mode=="g-translate")
Expand Down
2 changes: 1 addition & 1 deletion core/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Data = {
var tag = "";
if(tags.length==0)
{
taglist.push("Other")
taglist.push("Untagged")
}
else if(tags.length==1)
{
Expand Down
66 changes: 63 additions & 3 deletions core/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Format = {
for(const tag of tags)
{
if(this.hastag(item, tag))
{
{
if(!Object.keys(tagged_items).includes(item.id))
{
tagged_items[item.id] = itemlist[item.id];
Expand All @@ -32,6 +32,25 @@ Format = {
}
}
}

for(const note of this.noteswithouttags(item))
{
var tag = "Untagged";
var n = await this.formatnote(note);

if(!Object.keys(tagged_items).includes(item.id))
{
tagged_items[item.id] = itemlist[item.id];
}
if(!Object.keys(tagged_items[item.id]).includes(tag))
{
tagged_items[item.id][tag] = n;
}
else
{
tagged_items[item.id][tag]+=n;
}
}
}
return {
data: Object.values(itemlist),
Expand Down Expand Up @@ -131,6 +150,48 @@ Format = {
return this.itemtags(item).includes(tag)
},

noteswithouttags(item)
{
var notes = [];
var noteids = [];
if(![NOTE_LABEL].includes(item.itemType))
{
noteids = item.getNotes();
}
else
{
noteids.push(item.id);
}

var pdfids = [];
try {
pdfids = item.getAttachments();
}
catch(e)
{
}

for(let id of pdfids)
{
let attachment = Zotero.Items.get(id);
if(attachment.isPDFAttachment())
{
noteids = noteids.concat(attachment.getAnnotations().map(function(e){return e.id}));
}
}

for(id of noteids)
{
var note = Zotero.Items.get(id);

if(note.getTags(false).length==0)
{
notes.push(note);
}
}
return notes;
},

xmlescape(txt){
txt = txt.replace(/&/g, '&');
txt = txt.replace(/<br>/g, '<br/>');
Expand Down Expand Up @@ -184,8 +245,7 @@ Format = {
note_ = note.getNote();
note_ = Zotero.ZeNotes.Filter.apply(note_, selectors, replacement);
note_ = await Zotero.ZeNotes.Image.render(note_, item);

notetext+=note_+ "<span class='notekey'>"+note.id+"</span><hr/>";
notetext+="<div class='user-note' data-notekey='"+note.id+"'>"+note_+"</div><hr/>";
}
return notetext;
},
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>ZeNotes</em:name>
<em:version>0.6.1</em:version>
<em:version>0.6.2</em:version>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:updateURL>https://raw.githubusercontent.com/frianasoa/zenotes/main/zenote-update.json</em:updateURL>
<em:homepageURL>https://github.com/frianasoa/zenotes</em:homepageURL>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ze Notes",
"version": "0.6.1",
"version": "0.6.2",
"description": "Advanced notes manager",
"homepage_url": "https://github.com/frianasoa/zenotes",
"author": "Fanantenana Rianasoa Andriariniaina",
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"[email protected]": {
"updates": [
{
"version": "0.6.1",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.6.1/zenotes-v0.6.1.xpi",
"update_hash": "sha256:c173988f9f280d6a634ebc98d2da40822cd135bbfe443f1c161c22225986daa5",
"version": "0.6.2",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.6.2/zenotes-v0.6.2.xpi",
"update_hash": "sha256:ea13700f4116e30b04aaf138c6d6e9c8646d69c7cb5ff4b19965ad77a9bd7851",
"applications": {
"gecko": {
"strict_min_version": "60.0"
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<ns1:version>0.6.1</ns1:version>
<ns1:version>0.6.2</ns1:version>
<ns1:targetApplication>
<rdf:Description>
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>5.0.0</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.6.1/zenotes-v0.6.1.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.6.2/zenotes-v0.6.2.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand All @@ -20,7 +20,7 @@
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>4.999</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.6.1/zenotes-v0.6.1.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.6.2/zenotes-v0.6.2.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit 6f219f9

Please sign in to comment.