Skip to content

Commit

Permalink
update: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Sep 21, 2023
1 parent 9ac65e7 commit 4c6aaba
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ Share & find custom scripts here: https://github.com/windingwind/zotero-actions-

You can use the following variables in the script:

- `item`: The target item. Might be `undefined` if the action is triggered by an event that doesn't have a target item, e.g. shortcut in the Zotero client without selecting an item. (Not available in `programStartup`, `mainWindowLoad`, and `mainWindowUnload` event)
- `item`: The target item. Might be `null` if the action is triggered by an event that doesn't have a target item, e.g. shortcut in the Zotero client without selecting an item. (Not available in `programStartup`, `mainWindowLoad`, and `mainWindowUnload` event)

<details style="text-indent: 4em">
<summary>Examples with item</summary>
<summary>Examples with `item`</summary>

- Get the title of the item: `item.getField('title')`. More details of the available fields can be found in [Zotero:item fields](https://api.zotero.org/itemFields?pprint=1)
- Get the tags of the item: `item.getTags().map(tag => tag.tag)`
Expand All @@ -182,10 +182,30 @@ You can use the following variables in the script:

</details>

- `items`: The target items[] array. Only available in menu/shortcut-triggered actions, otherwise it's `null`.

<details style="text-indent: 4em">
<summary>Examples with `items`</summary>

When selecting multiple items in the library, the action will be triggered for each item. You can use the `items` variable to get the selected items array and avoid duplicate operations.

```js
if (!items && item) {
// Disable the action if it's triggered for a single item to avoid duplicate operations
return;
}

if (items?.length > 0) {
// Do something with the selected items
}
```
</details>
- `require`: The `require` function to import global variables. Use `const window = require('window')` to import the `window` variable.
<details style="text-indent: 4em">
<summary>Examples with require</summary>
<summary>Examples with `require`</summary>
- Get selected items: `const selectedItems = require('ZoteroPane').getSelectedItems()`
- Get the item of current tab:
Expand Down

0 comments on commit 4c6aaba

Please sign in to comment.