Skip to content

Commit

Permalink
add: diy tag color
Browse files Browse the repository at this point in the history
  • Loading branch information
Polygononon committed Nov 28, 2022
1 parent 7b3f0d6 commit 6d89028
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 155 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Mac用户同时鼠标中键可能也用不了,可以用`Shift+P`来唤醒设置
| Zotero.ZoteroStyle.tagPosition | 4 | 1,2,3,4 |
| Zotero.ZoteroStyle.tagAlign | left | left,right |
| Zotero.ZoteroStyle.constantFields | ['title', 'year'] | 要可以被js的eval函数执行(全英文字符) |

| /reference || 在阅读PDF界面使用 |
| /Zotero.Tags.setColor(1, "tagName", '#AAAAAA', 1) | 在命令中 | 注意斜杠 |
![](https://spr1ng.live/file/39bbe98fe67f8efd508b7.png)
![](https://spr1ng.live/file/e351445318a956ac10a7a.png)

Expand Down Expand Up @@ -90,13 +91,17 @@ Mac用户同时鼠标中键可能也用不了,可以用`Shift+P`来唤醒设置
2. 增加`只显示标题`按钮🌸
3. 显示阅读进度,是否划水,一看便知👋
4. 本插件可与`Chartero`共存,若安装`Chartero`本插件将不再渲染进度条,因为这一功能我已合并到`Chartero`,而且`Chartero`支持同步数据
5. /reference(还在做,下面是预览图)
5. 阅读界面快速检索参考文献,一键导入并关联至当前文献 (目前实验性功能)
6. 自定义指派标签颜色位置

> 5的图示
![](https://spr1ng.live/file/6c034034afb3f51309a76.png)
![](https://spr1ng.live/file/2c468b2d30abb704b8bf0.png)
![](https://spr1ng.live/file/f64a442981bcb66754feb.png)
![](http://tva1.sinaimg.cn/large/c5826cc9ly1h8k444nnclj20nk03m0w4.jpg)

> 6的图示
![](https://spr1ng.live/file/b7eaf4c526d5109558a9b.png)
🙌建议配合`Zotero Tag`&`Chartero`使用

## 安装方法
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"addonID": "[email protected]",
"addonRef": "zoterostyle",
"version": "1.2.3",
"description": "标签靠右显示,标题最大化按钮",
"description": "标签靠右显示,标题最大化按钮,参考文献检索快速导入关联",
"main": "src/index.js",
"scripts": {
"build": "node build.js",
Expand Down
13 changes: 9 additions & 4 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AddonEvents extends AddonModule {
}

// tip
this.setting.inputMessage("Zotero Style is running, have a nice day!", 3)
this.setting.inputMessage("Zotero Style is running, have a nice day!", 0, 5)
this.window.setTimeout(() => {
this.setting.settingNode.style.display = "none"
}, 3000)
Expand Down Expand Up @@ -264,7 +264,6 @@ class AddonEvents extends AddonModule {
// path: getMainWindow().ZoteroPane.itemsView._renderCell
let id = this.window.setInterval(
(() => {
console.log(this)
let zoteroFunc = eval(`this.Zotero.${path}`)
let zoteroFuncThis = eval(`this.Zotero.${path.match(/(.+)\.\w/)[1]}`)
this._hookFunction[path] = {
Expand Down Expand Up @@ -292,7 +291,6 @@ class AddonEvents extends AddonModule {
// 2693 _renderPrimaryCell(index, data, column)
let document = Zotero.getMainWindow().document
let createElement = (name) => document.createElementNS("http://www.w3.org/1999/xhtml", name)

// render the tag
if (primaryCell.querySelector(".tag-box")) return
let tagBoxNode = createElement("span")
Expand All @@ -305,6 +303,7 @@ class AddonEvents extends AddonModule {
if (tagNode.style.backgroundColor.includes("rgb")) {
tagNode.classList.add("zotero-tag")
delta = .25
// change its color
}
tagNode.style[tagAlign] = `${i*1.25+delta}em`
tagBoxNode.appendChild(tagNode)
Expand Down Expand Up @@ -411,6 +410,12 @@ class AddonEvents extends AddonModule {
return this.Zotero.Reader.getByTabID(((this.window as any).Zotero_Tabs as typeof Zotero_Tabs).selectedID);
}

private getReadingItem() {
let reader = this.getReader()
let item = this.Zotero.Items.get(reader.itemID).parentItem as any
return item
}

public recordReadTime(): void {
// is not reading
// it return undefined if no reader selected, so we ignore it
Expand Down Expand Up @@ -438,7 +443,7 @@ class AddonEvents extends AddonModule {

// real read, record this recordInterval
const totalPageNum = reader._iframeWindow.wrappedJSObject.PDFViewerApplication.pdfDocument.numPages;
const title = (this.Zotero.Items.get(reader.itemID).parentItem as any)._displayTitle;
const title = this.getReadingItem()._displayTitle

// get local record
// console.log("saving");
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AddonModule {
try {
_v = JSON.parse(_v)
} catch (e) {
console.log(`Error in JSON.parse function - JSON.parse(${_v})`)
// console.log(`Error in JSON.parse function - JSON.parse(${_v})`)
// i.e., JSON.parse("['1']") can not work, but eval can
}
// last try
Expand Down
Loading

0 comments on commit 6d89028

Please sign in to comment.