diff --git a/README.md b/README.md index 337d2be..c713556 100644 --- a/README.md +++ b/README.md @@ -197,54 +197,54 @@ You can use the following variables in the script: - `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) -
-Examples with `item` +
+ Examples with `item` -- 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)` -- Add a tag to the item: `item.addTag('tag')` -- Remove a tag from the item: `item.removeTag('tag')` + - 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)` + - Add a tag to the item: `item.addTag('tag')` + - Remove a tag from the item: `item.removeTag('tag')` -
+
- `items`: The target items[] array. Only available in menu/shortcut-triggered actions, otherwise it's `null`. -
-Examples with `items` - -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. + When selecting multiple items in the library, the action will be triggered once for all item (`items=[...], item=undefined`) and then one-by-one for each item (`items=[], item=...`). You can use the `items` variable to get the selected items array and avoid duplicate executions. -```js -if (!items && item) { - // Disable the action if it's triggered for a single item to avoid duplicate operations - return; -} +
+ Examples with `items` -if (items?.length > 0) { - // Do something with the selected items -} -``` + ```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 + } + ``` -
+
- `collection`: The target collection object, only available when triggered by collection menu. - `require`: The `require` function to import global variables. Use `const window = require('window')` to import the `window` variable. -
-Examples with `require` +
+ Examples with `require` -- Get selected items: `const selectedItems = require('ZoteroPane').getSelectedItems()` -- Get the item of current tab: + - Get selected items: `const selectedItems = require('ZoteroPane').getSelectedItems()` + - Get the item of current tab: - ```js - const Zotero = require("Zotero"); - const Zotero_Tab = require("Zotero_Tab"); - const itemID = Zotero_Tabs._tabs[Zotero_Tabs.selectedIndex].data.itemID; - const item = Zotero.Items.get(itemID); - ``` + ```js + const Zotero = require("Zotero"); + const Zotero_Tab = require("Zotero_Tab"); + const itemID = Zotero_Tabs._tabs[Zotero_Tabs.selectedIndex].data.itemID; + const item = Zotero.Items.get(itemID); + ``` -
+
- `window`: Only available in `mainWindowLoad` and `mainWindowUnload` event. In other events, you should use `require('Zotero').getMainWindow()` to import the `window` variable.