Skip to content

Commit

Permalink
/reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Polygononon committed Nov 27, 2022
1 parent 72e33f1 commit e14a741
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 71 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ Mac用户同时鼠标中键可能也用不了,可以用`Shift+P`来唤醒设置
2. 增加`只显示标题`按钮🌸
3. 显示阅读进度,是否划水,一看便知👋
4. 本插件可与`Chartero`共存,若安装`Chartero`本插件将不再渲染进度条,因为这一功能我已合并到`Chartero`,而且`Chartero`支持同步数据
5. /reference

![](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)

🙌建议配合`Zotero Tag`&`Chartero`使用

Expand Down
42 changes: 2 additions & 40 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class AddonEvents extends AddonModule {
public toolbarbutton: any;
public style: any;
public intervalID: number;
public keyset: any;
public _hookFunction = {};
public tagSize = 5; // em
public tagPosition = 3;
Expand Down Expand Up @@ -82,7 +81,6 @@ class AddonEvents extends AddonModule {
this.setting = new Setting(AddonModule)
this.setting.init(this.Zotero)
this.setting.settingNode.style.display = "none"
this.initKeys()
// event
let notifierID = this.Zotero.Notifier.registerObserver(
this.notifierCallback,
Expand All @@ -100,13 +98,11 @@ class AddonEvents extends AddonModule {
// listen to Zotero's state
if (!this.Zotero.Chartero) {
this.window.addEventListener('activate', () => {
console.log('activate')
this.state.activate = true
// once Zotero is activated again, it will continue to record read time
this.intervalID = this.window.setInterval(this.recordReadTime.bind(this), this.recordInterval * 1e3)
}, true);
this.window.addEventListener('deactivate', () => {
console.log('deactivate')
this.state.activate = false
this.state.hangCount = 0;
// once Zotero is deactivate again, it will stop to record read time
Expand Down Expand Up @@ -245,7 +241,7 @@ class AddonEvents extends AddonModule {
}
.zotero-style-progress {
position: absolute;
left: ${tagPosition == 4 ? 3.25 : 3.25 + tagSize}em;
left: ${tagPosition == 4 ? 3.25 : 3.25 + tagSize}em !important;
top: 0;
width: calc(100% - 3.5em - ${tagSize}em) !important;
height: 100%;
Expand Down Expand Up @@ -465,40 +461,6 @@ class AddonEvents extends AddonModule {
return (typeof(arg) == "number" && String(arg) != "NaN")
}

private initKeys() {
this.removeKeys()
let keyset = this.document.createElement("keyset");
keyset.setAttribute("id", "zoterostyle-keyset");

let key = this.document.createElement("key");
key.setAttribute("id", "zoterostyle-key");
key.setAttribute("oncommand", "console.log(111)");
key.addEventListener("command", function () {
var _Zotero = Components.classes["@zotero.org/Zotero;1"].getService(
Components.interfaces.nsISupports
).wrappedJSObject;
let document = _Zotero.getMainWindow().document
let settingNode = document.querySelector("#Zotero-Style-Setting")
if (settingNode.style.display == "none") {
settingNode.style.display = ""
settingNode.querySelector("input").focus()
} else {
settingNode.style.display = "none"
}
})
key.setAttribute("key", "p")
key.setAttribute("modifiers", "shift")
keyset.appendChild(key)
this.keyset = keyset
this.document.getElementById("mainKeyset").parentNode.appendChild(keyset);
}

private removeKeys() {
if (this.keyset) {
this.keyset.remove()
}
}

private toRGB(color: string) {
var sColor = color.toLowerCase();
//十六进制颜色值的正则表达式
Expand Down Expand Up @@ -535,7 +497,7 @@ class AddonEvents extends AddonModule {
// remove ZoteroStyle UI
this.removeStyle()
this.removeSwitchButton()
this.removeKeys()
this.setting.removeKeys()
for (let path of Object.keys(this._hookFunction)) {
let obj = this._hookFunction[path]
let func = function(...args: any[]) {return obj.zoteroFunc.apply(obj.zoteroFuncThis, args)}
Expand Down
Loading

0 comments on commit e14a741

Please sign in to comment.