Created
July 11, 2020 12:12
-
-
Save zuphilip/c1dbbac39385098f729e09dd601d49d9 to your computer and use it in GitHub Desktop.
JS-Script for Zotero to check consistency for your book chapters in your library
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
/* | |
Check data consistency for book chapters of the same book | |
(isbn check for that). For each outputed object the bookTitle, | |
publisher and place should be the same also when there are more | |
than one chapter in your currently selected library. If not, then | |
you may want to look closer to this reported incosistency. [License: CC0] | |
*/ | |
var isbnData = {}; | |
var s = new Zotero.Search(); | |
s.libraryID = ZoteroPane.getSelectedLibraryID(); | |
s.addCondition('itemType', 'is', 'bookSection'); | |
s.addCondition('noChildren', 'true'); | |
var itemIDs = await s.search(); | |
for (let id of itemIDs) { | |
let item = Zotero.Items.get(id); | |
let isbn = item.getField("ISBN"); | |
let bookTitle = item.getField("bookTitle"); | |
let publisher= item.getField("publisher"); | |
let place= item.getField("place"); | |
if (isbn) { | |
if (isbn in isbnData) { | |
isbnData[isbn]["count"] = isbnData[isbn]["count"] + 1; | |
isbnData[isbn]["ids"].push(id); | |
if (isbnData[isbn]["bookTitle"].indexOf(bookTitle) === -1) { | |
isbnData[isbn]["bookTitle"].push(bookTitle); | |
} | |
if (isbnData[isbn]["publisher"].indexOf(publisher) === -1) { | |
isbnData[isbn]["publisher"].push(publisher); | |
} | |
if (isbnData[isbn]["place"].indexOf(place) === -1) { | |
isbnData[isbn]["place"].push(place); | |
} | |
} | |
else { | |
isbnData[isbn] = { | |
"count": 1, | |
"ids": [id], | |
"bookTitle": [bookTitle], | |
"publisher": [publisher], | |
"place": [place] | |
} | |
} | |
} | |
} | |
return isbnData; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment