Created
November 15, 2023 00:56
-
-
Save sjgknight/9a1ba937220621abcda38f401dbe7c80 to your computer and use it in GitHub Desktop.
A javascript snippet to be used in zotero js developer interface, batch select in the UI and it will convert '1 field' names into '2 field' names. Likely to be quite imperfect...
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
| var newFieldMode = 0; // 0: two-field, 1: one-field (with empty first name) | |
| const zoteroPane = Zotero.getActiveZoteroPane(); | |
| const selected = zoteroPane.getSelectedItems(); | |
| for (const item of selected) { | |
| let creators = item.getCreators(); | |
| let newCreators = []; // Initialize newCreators array | |
| for (let creator of creators) { | |
| if(creator.fieldMode == 1){ | |
| let oldname = creator.lastName; | |
| creator.fieldMode = newFieldMode; | |
| creator.firstName = oldname.split(' ').slice(0, -1).join(' '); | |
| creator.lastName = oldname.split(' ').slice(-1).join(' '); | |
| } | |
| newCreators.push(creator); | |
| } | |
| item.setCreators(newCreators); | |
| await item.save(); | |
| } | |
| return selected.length + " item(s) updated"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment