Last active
November 20, 2019 22:47
-
-
Save zuphilip/65afb670a44f743f695bb647c755cd63 to your computer and use it in GitHub Desktop.
Update Zotero author information from Crossref (proof of concept script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // can be run within Zotero "Run Javascript" tool | |
| var items = Zotero.getActiveZoteroPane().getSelectedItems(); | |
| var output | |
| for (let item of items) { | |
| let doi = item.getField("DOI"); | |
| if (doi) { | |
| await Zotero.HTTP.doGet("http://api.crossref.org/works/" + doi, function (obj) { | |
| let data = JSON.parse(obj.responseText); | |
| for (let i = 0; i < data.message.author.length; i++) { | |
| let crossrefAuthor = data.message.author[i]; | |
| let zoteroAuthor = item.getCreator(i); | |
| if (zoteroAuthor && crossrefAuthor.family && crossrefAuthor.given && zoteroAuthor.lastName == crossrefAuthor.family) { | |
| zoteroAuthor.firstName = crossrefAuthor.given; | |
| item.setCreator(i, zoteroAuthor) | |
| } | |
| } | |
| }); | |
| } | |
| } | |
| return items; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment