Skip to content

Commit

Permalink
Added json support for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Dec 6, 2023
1 parent 363388e commit 27ae876
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion content/settings/display.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<tr><td>Highlight opacity</td><td><input type="range" min="0" max="255" value="255" id="zn-bg-slider" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'bg-opacity');" oninput="Zotero_Preferences.ZeNotes.updateopacity(event);"/></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="Zotero_Preferences.ZeNotes.updatecolumnwidth(event);"/></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="Zotero_Preferences.ZeNotes.updatedisplay(event, 'zn-column-width-val');"/></td><td><input id="zn-column-width-val" /></td></tr>
<tr><td>Filter html</td><td><input id="zn-html-filter" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'html-filter');" style="width:100%;" placeholder="Comma separeted CSS selectors"/></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>
<tr><td>Filter html</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>
36 changes: 31 additions & 5 deletions core/filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
Filter = {
apply(txt, selectors = "", replacement=""){
this.replacement = replacement
txt = Filter.legacy(txt);
txt = Filter.userdefined(txt, selectors);

selectors = this.processselectors(selectors);
if(typeof selectors=="string")
{
txt = Filter.userdefined(txt, selectors, replacement);
}
else {
txt = Filter.userdefinedmultiple(txt, selectors);
}

return txt;
},
legacy(txt){
Expand All @@ -16,7 +24,25 @@ Filter = {
return txt;
},

userdefined(txt, selectors)
processselectors(s)
{
try {
return JSON.parse(s);
}
catch {}
return s
},

userdefinedmultiple(txt, selectors) {
for(selector in selectors)
{
var replacement = selectors[selector];
txt = this.userdefined(txt, selector, replacement);
}
return txt;
},

userdefined(txt, selectors, replacement)
{
if(selectors)
{
Expand Down Expand Up @@ -48,9 +74,9 @@ Filter = {
{
if(this.validselector(selector))
{
if(this.replacement!="")
if(replacement!="")
{
html.querySelectorAll("body "+selector).forEach(e => e.outerHTML="<div>"+this.escapehtml(this.replacement))+"</div>";
html.querySelectorAll("body "+selector).forEach(e => e.outerHTML="<div>"+this.escapehtml(replacement))+"</div>";
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion zenote-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"version": "0.4.6",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.4.6/zenotes-v0.4.6.xpi",
"update_hash": "sha256:c573a75c41ca299b7f35db4a8429bfa6fad8d5a9c1be165b5e8dfd36d567e15b",
"update_hash": "sha256:f0c58339b9e4cb58fbf3aaf32f4d437e8941778000427e2894d217be6c3f1104",
"applications": {
"gecko": {
"strict_min_version": "60.0"
Expand Down

0 comments on commit 27ae876

Please sign in to comment.