Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically execute code when a tab is closed #2

Open
RibomBalt opened this issue Oct 28, 2022 · 1 comment
Open

Automatically execute code when a tab is closed #2

RibomBalt opened this issue Oct 28, 2022 · 1 comment

Comments

@RibomBalt
Copy link

Hello, I'm also upset about the fact that Zotero still doesn't offer a function of "Recent Read Papers" lol.

In your workflow, you have to manually switch to the Javascript interface and execute the code when you switch from one paper to another. However, Zotero offers a (probably unused) API to define a callback function when a tab is closed. (though it is currently not on the wiki page. I found that through reading the Zotero source code)

let win = Zotero.getMainWindow();
let zts = win.Zotero_Tabs._tabs;
// zts is a list of tab objects with many useful fields including id, title, time of last selected/unselected. 
// Usually, zts[0] is the main panel where you select papers, while the others are the papers you have opened.
let old_onClose = zts[1].onClose; // undefined
zts[1].onClose = ()={
    alert('this tab is closed');
}
// after you execute, when you close the first tab, the callback runs, and you will see the alert.

So in your case, you can define your second piece of code as a function and register it as the onClose callback of each opened tab. You can even use setInterval to iterate over all opened tabs (with zts) every given time (e.g., 10 seconds), so you only have to execute the code once and don't have to bother with it anymore!

And this can go even further, like writing the closing time into the paper's metadata (it seems #1 mentioned writing to the attachment (pdf) of the paper, but actually there is a (probably) unused access_time field in the metadata), and/or tag them "Recently Read" / add them to a collection named "Recent Read". After that, you can simply visit the "Recently Read" tag/collection and sort the paper by access time, like the way Mendeley does. I plan to work on this if I got time :)

@sonictl
Copy link
Owner

sonictl commented Oct 28, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants