Skip to content

Commit

Permalink
Added font size setting and image support for annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Jan 11, 2024
1 parent adff458 commit b53dd03
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 11 deletions.
6 changes: 6 additions & 0 deletions content/notes/notes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Notes = {
init() {
var fontsize = Zotero.ZeNotes.Prefs.get("font-size");
this.tableutils = Zotero_Preferences.ZNTable;
this.body = document.getElementById("zn-body");
this.infotags = ["id", "key", "title", "date", "journal", "author", "creators", "itemid", "filekey"];
this.body.focus();
if(fontsize)
{
this.body.style.fontSize = fontsize+"px";
}

},

isvertical()
Expand Down
1 change: 1 addition & 0 deletions content/settings/display.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<tr><td>Highlight opacity</td><td><input type="range" min="0" max="255" value="255" id="zn-bg-opacity" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'bg-opacity');"/></td><td class='highlight' style='background-color: #FFFF00; height: 1.1em;' id="zn-bg-sample">Lorem ipsum</td></tr>
<tr><td>Header size</td><td><input id="zn-header-size" type="range" value="100" min="20" max="1500" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'header-size');" oninput="document.getElementById('zn-header-size-val').value=this.value;"/></td><td><input id="zn-header-size-val" /></td></tr>
<tr><td>Column width (for vertical)</td><td><input id="zn-column-width" type="range" value="100" min="20" max="1500" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'column-width');" oninput="document.getElementById('zn-column-width-val').value=this.value;"/></td><td><input id="zn-column-width-val" /></td></tr>
<tr><td>Font size</td><td><input id="zn-font-size" type="range" value="100" min="6" max="75" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'font-size');" oninput="document.getElementById('zn-font-size-val').value=this.value;"/></td><td><input id="zn-font-size-val" /></td></tr>
<tr><td>Filter html (replace)</td><td><textarea id="zn-html-filter" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'html-filter');" style="width:100%; height: 2em;" placeholder="Comma separeted CSS selectors. Also accepts JSON: {selectors: replacement, ...}"></textarea></td><td><input id="zn-html-filter-replacement" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'html-filter-replacement');" style="width:100%;" placeholder="Replace with"/></td></tr>
</table>
</div>
14 changes: 13 additions & 1 deletion content/settings/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ Zotero_Preferences.ZeNotes = {
});
}
}
if(elid.includes("-val"))
{
el.addEventListener("keyup", function(e){
let value = e.target.value;
let id = e.target.id.replace("-val", "");
let cevent = new Event('change');
document.getElementById(id).value = value;
document.getElementById(id).dispatchEvent(cevent);
})
}
}
},

Expand Down Expand Up @@ -261,7 +271,9 @@ Zotero_Preferences.ZeNotes = {
["column-width", "zn-column-width-val"],
["header-size", "zn-header-size"],
["header-size", "zn-header-size-val"],
["vertical-table", "zn-vertical-table"]
["vertical-table", "zn-vertical-table"],
["font-size", "zn-font-size"],
["font-size", "zn-font-size-val"]
];
break;

Expand Down
22 changes: 20 additions & 2 deletions core/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Format = {
annotationtext = this.escapehtml(annotationtext);
}

var contents = "&#x201F;<span class='direct-quote'>"+annotationtext+"</span>&#8221; ("+Format.creatorshort(item)+" "+Format.year(item)+", p. "+note["annotationPageLabel"]+")";


var comment = note["annotationComment"];

Expand All @@ -226,18 +226,36 @@ Format = {
comment = "";
}




if(!this.isvalidxhtml(comment))
{
comment = this.escapehtml(comment);
}

comment = comment.split("\n").join("<br/>\n");

var contents = "&#x201F;<span class='direct-quote'>"+annotationtext+"</span>&#8221; ("+Format.creatorshort(item)+" "+Format.year(item)+", p. "+note["annotationPageLabel"]+")";

var img = "";
if(note.annotationType=="image")
{
var json = await Zotero.Annotations.toJSON(note);
if(annotationtext)
{
annotationtext = "&#x201F;<span class='direct-quote'>"+annotationtext+"</span>&#8221;";
}
var img = "<img width='100%' src='"+json["image"]+"' />";

var contents = annotationtext+"<br/> Source: "+Format.creatorshort(item)+" "+Format.year(item)+", p. "+note["annotationPageLabel"]+"";
}

var annotationpage = JSON.parse(note["annotationPosition"])["pageIndex"];

var color = Zotero.ZeNotes.Utils.addopacity(note["annotationColor"], Zotero.ZeNotes.Prefs.get("bg-opacity"));

let note_ = "<div class='annotation-body'><div class='annotation-comment'>"+comment+"</div><hr style='width: 25%;'/><div id='annotation-"+note["parentItem"].key+"-"+note["key"]+"' class='annotation' data-attachmentkey='"+note["parentItem"].key+"' data-tag='"+tag+"' data-attachmentid='"+note["parentItem"].id+"' data-pagelabel='"+note["annotationPageLabel"]+"' data-annotationpage='"+annotationpage+"' data-annotationid='"+note.id+"' data-annotationkey='"+note["key"]+"' style='background-color:"+color+";' data-source='"+Format.creatorshortlocale(item)+"' data-author='"+Format.creatorshort(item)+"' data-date='"+Format.year(item)+"'>"+contents+"</div></div><hr/>";
let note_ = "<div class='annotation-body'><div class='annotation-comment'>"+comment+"</div><hr style='width: 25%;'/><div id='annotation-"+note["parentItem"].key+"-"+note["key"]+"' class='annotation' data-attachmentkey='"+note["parentItem"].key+"' data-tag='"+tag+"' data-attachmentid='"+note["parentItem"].id+"' data-pagelabel='"+note["annotationPageLabel"]+"' data-annotationpage='"+annotationpage+"' data-annotationid='"+note.id+"' data-annotationkey='"+note["key"]+"' style='background-color:"+color+";' data-source='"+Format.creatorshortlocale(item)+"' data-author='"+Format.creatorshort(item)+"' data-date='"+Format.year(item)+"'>"+img+ contents+"</div></div><hr/>";
notetext+=note_;
}
else
Expand Down
10 changes: 10 additions & 0 deletions core/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var window = Zotero.getMainWindow();
Utils = {
tohex(d)
{
Expand Down Expand Up @@ -93,6 +94,7 @@ Utils = {
}
return arr;
},

displayjson(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
Expand All @@ -116,5 +118,13 @@ Utils = {

json = json.split("\n").join("<br/>").split(" ").join("&#160;&#160;");
return json;
},

bin2b64(bin, mime="png"){
var uint8Array = new TextEncoder().encode(bin);
var base64String = btoa(String.fromCharCode.apply(null, uint8Array));
return base64String;
// return "data:image/"+mime+";base64,"+window.btoa(encodeURIComponent(bin));
}

}
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.7.7</em:version>
<em:version>0.7.8</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.7.7",
"version": "0.7.8",
"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.7.7",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.7/zenotes-v0.7.7.xpi",
"update_hash": "sha256:5c7573098676a08d4b1839548caa33fb33aadcc910ef50ae82ef6ecc9d2b256d",
"version": "0.7.8",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.8/zenotes-v0.7.8.xpi",
"update_hash": "sha256:2d45d794a0b648399351af95f6990342d3c5ebb78188462a5880c8bc431215e2",
"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.7.7</ns1:version>
<ns1:version>0.7.8</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.7.7/zenotes-v0.7.7.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.8/zenotes-v0.7.8.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.7.7/zenotes-v0.7.7.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.8/zenotes-v0.7.8.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit b53dd03

Please sign in to comment.