Skip to content

Commit

Permalink
new feature: tagAlign
Browse files Browse the repository at this point in the history
  • Loading branch information
Polygononon committed Nov 27, 2022
1 parent c4532b1 commit 72e33f1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ Mac用户同时鼠标中键可能也用不了,可以用`Shift+P`来唤醒设置
| Zotero.ZoteroStyle.progressOpacity | 0.5 | 设置进度条透明度,0~1 |
| Zotero.ZoteroStyle.tagSize | 8 | 设置标签宽度,单位em |
| Zotero.ZoteroStyle.tagPosition | 4 | 1,2,3,4 |
| Zotero.ZoteroStyle.tagAlign | left | left,right |
| Zotero.ZoteroStyle.constantFields | ['title', 'year'] | 要可以被js的eval函数执行(全英文字符) |

![](https://spr1ng.live/file/39bbe98fe67f8efd508b7.png)
![](https://spr1ng.live/file/419785dd210386431df11.png)
![](https://spr1ng.live/file/e351445318a956ac10a7a.png)

> Tips:
<https://github.com/zotero/zotero/blob/26847c672f62de30bd63d9434a00d6c9f8a5e76c/chrome/locale/zh-CN/zotero/zotero.properties>
Expand Down
8 changes: 5 additions & 3 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class AddonEvents extends AddonModule {
public keyset: any;
public _hookFunction = {};
public tagSize = 5; // em
public tagPosition = 3; // em
public tagPosition = 3;
public tagAlign = "left"; // em
public progressOpacity = .7;
public progressColor = "#5AC1BD";
public constantFields = ["hasAttachment", "title"];
Expand Down Expand Up @@ -301,16 +302,17 @@ class AddonEvents extends AddonModule {
let tagBoxNode = createElement("span")
tagBoxNode.setAttribute("class", "tag-box")
// special algin between font and span
let obj = Zotero.ZoteroStyle.events
let tagAlign = obj.getValue("Zotero.ZoteroStyle.tagAlign", obj.tagAlign)
primaryCell.querySelectorAll(".tag-swatch").forEach((tagNode: any, i: number) => {
let delta = 0
if (tagNode.style.backgroundColor.includes("rgb")) {
tagNode.classList.add("zotero-tag")
delta = .25
}
tagNode.style.left = `${i*1.25+delta}em`
tagNode.style[tagAlign] = `${i*1.25+delta}em`
tagBoxNode.appendChild(tagNode)
})
let obj = Zotero.ZoteroStyle.events
let tagPosition = obj.getValue("Zotero.ZoteroStyle.tagPosition", obj.tagPosition)
switch (tagPosition) {
case 4:
Expand Down
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class AddonModule {
Components.interfaces.nsISupports
).wrappedJSObject;
let _v = Zotero.Prefs.get(k)
// not stored, return
if (_v == undefined) { return v }
// not stored or stored empty string, return
if (_v == undefined || _v == "") { return v }
// stored, maybe we needn't later processing or need string, return
if (v == undefined || typeof(_v) == typeof(v)) { return _v }
// json or number, but Number("") = 0, eval("") = undefined, so we use latter
Expand Down
1 change: 1 addition & 0 deletions src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Setting extends AddonModule {
"Zotero.ZoteroStyle.progressOpacity=.7",
"Zotero.ZoteroStyle.tagSize=5",
"Zotero.ZoteroStyle.tagPosition=3",
"Zotero.ZoteroStyle.tagAlign=left",
"Zotero.ZoteroStyle.progressColor=#5AC1BD",
"Zotero.ZoteroStyle.constantFields=['hasAttachment', 'title']"
],
Expand Down

0 comments on commit 72e33f1

Please sign in to comment.