Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:client_coding:javascript_api [2019/06/11 03:44]
dstillman [Running Ad Hoc JavaScript in Zotero]
dev:client_coding:javascript_api [2019/08/18 05:41] (current)
zuphilip [Running Ad Hoc JavaScript in Zotero] Add examples
Line 10: Line 10:
 Zotero includes an option to run arbitrary privileged JavaScript: Zotero includes an option to run arbitrary privileged JavaScript:
  
-  ​- In the Advanced pane of the Zotero preferences,​ select Config Editor, and then set ''​devtools.chrome.enabled''​ to ''​true''​ and restart Zotero. +  - In the Tools → Developer ​menu, select Run JavaScript. ​Opening ​the Error Console, which appears in the same menu, will also be helpful.
-  ​- In the Tools menu, select Run JavaScript. ​Open the Error Console, which also appears in Tools, will also be helpful.+
   - In the window that opens, enter JavaScript in the Code textbox and click Run or press Cmd-R/​Ctrl-R.   - In the window that opens, enter JavaScript in the Code textbox and click Run or press Cmd-R/​Ctrl-R.
  
-To run asynchronous code, check the "Run as async function"​ checkbox. This runs the entered code wrapped in an [[https://​developer.mozilla.org/​en-US/​docs/​Web/​JavaScript/​Reference/​Statements/​async_function|async function]], allowing you to use ''​await'' ​to wait for the resolution of promises returned by functions. Most Zotero functions that access the database, disk, or network are asynchronous. In this mode, the value of a ''​return''​ statement will be displayed in the right-hand pane upon successful completion.+When running **asynchronous** code containing ''​await''​, the entered code is wrapped in an [[https://​developer.mozilla.org/​en-US/​docs/​Web/​JavaScript/​Reference/​Statements/​async_function|async function]], allowing you to wait for the resolution of promises returned by functions. Most Zotero functions that access the database, disk, or network are asynchronous. In this mode, the value of a ''​return''​ statement will be displayed in the right-hand pane upon successful completion. ​E.g. returning the currently selected item(s)
  
-In synchronous mode, the value of the final line will appear in the right-hand pane.+<code javascript>​ 
 +var items = Zotero.getActiveZoteroPane().getSelectedItems();​ 
 +return items; 
 +</​code>​ 
 + 
 +In **synchronous** mode, the value of the final line will appear in the right-hand pane. The same result as above could be achieved in synchonous mode with 
 + 
 +<code javascript>​ 
 +var items = Zotero.getActiveZoteroPane().getSelectedItems();​ 
 +items; 
 +</​code>​
 ===== Zotero Code Architecture ===== ===== Zotero Code Architecture =====
  
dev/client_coding/javascript_api.1560239079.txt.gz · Last modified: 2019/06/11 03:44 by dstillman