Last active
November 18, 2017 21:07
-
-
Save kmpenner/6f5e4122b36e5757becc7ab18602a08e to your computer and use it in GitHub Desktop.
Zotero translator for The Orion Center for the Study of the Dead Sea Scrolls and Associated Literature bibliography
This file contains 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
{ | |
"translatorID": "eb63d07b-ceeb-465c-985c-799c1b2900b7", | |
"label": "Orion-Dev", | |
"creator": "Ken M. Penner", | |
"target": "http://orion-bibliography.huji.ac.il/orion_editor/", | |
"minVersion": "3.0", | |
"maxVersion": "", | |
"priority": 100, | |
"inRepository": true, | |
"translatorType": 4, | |
"browserSupport": "g", | |
"lastUpdated": "2017-11-18 21:05:11" | |
} | |
/* | |
***** BEGIN LICENSE BLOCK ***** | |
Copyright © 2017 Ken M. Penner | |
This Orion translator is free software: you can redistribute it and/or modify | |
it under the terms of the GNU Affero General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This translator is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU Affero General Public License for more details. | |
You should have received a copy of the GNU Affero General Public License | |
along with Zotero. If not, see <http://www.gnu.org/licenses/>. | |
***** END LICENSE BLOCK ***** | |
*/ | |
// Map Orion item types onto Zotero item types | |
var itemTypeMap=new Array(); | |
itemTypeMap["Journal Article"]="journalArticle"; | |
itemTypeMap["Edited Book"]="book"; | |
itemTypeMap["Book"]="book"; | |
itemTypeMap["Book section"]="bookSection"; | |
itemTypeMap["Audiovisual Material"]="videoRecording"; | |
itemTypeMap["Newspaper Article"]="newspaperArticle"; | |
itemTypeMap["Thesis"]="thesis"; | |
itemTypeMap["Hebrew Edited Book"]="book"; | |
itemTypeMap["Hebrew Authored Book"]="book"; | |
itemTypeMap["Hebrew Book Section"]="bookSection"; | |
// Zotero calls this to determine which icon to put on the toolbar | |
function detectWeb(doc, url) { | |
if (url.match("record-search")) {return "multiple";} | |
else { | |
// standard XPath header | |
var namespace = doc.documentElement.namespaceURI; | |
var nsResolver = namespace ? function(prefix) { | |
if (prefix == 'x') return namespace; else return null; | |
} : null; | |
var myXPath = '//div[@class="field-label"]'; | |
var myXPathObject = doc.evaluate(myXPath, doc, nsResolver, XPathResult.ANY_TYPE, null); | |
var headers; | |
var itemType=""; | |
while (headers = myXPathObject.iterateNext()) { | |
if (headers.textContent.match("Reference type:")) { | |
if(itemType=headers.nextElementSibling.textContent) { | |
return itemTypeMap[itemType.replace(/;/g,"")]; // the semi-colon at the end of Orion type "Hebrew Book Section" must be removed | |
} | |
} | |
} | |
} | |
} | |
// Zotero calls this when the user tells it to add the item(s) to the library | |
function doWeb(doc, url) { | |
var selectedItems = new Array(); | |
itemType=detectWeb(doc,url); | |
if (itemType=="multiple") { | |
// standard XPath header | |
var namespace = doc.documentElement.namespaceURI; | |
var nsResolver = namespace ? function(prefix) { | |
if (prefix == 'x') return namespace; else return null; | |
} : null; | |
var itemType=""; | |
var multipleItems=new Object(); | |
var nextTitle; | |
var titles = doc.evaluate('//td[@class="views-field views-field-title"]/a', doc, nsResolver, XPathResult.ANY_TYPE, null); | |
while (nextTitle = titles.iterateNext()) { | |
multipleItems[nextTitle.href] = nextTitle.textContent; | |
} | |
multipleItems=Zotero.selectItems(multipleItems); | |
for (var i in multipleItems) { | |
selectedItems.push(i); | |
} | |
} else { | |
selectedItems = [url]; | |
} | |
Zotero.Utilities.processDocuments(selectedItems, scrape, function(){Zotero.done();}); | |
Zotero.wait(); | |
} | |
function scrape(doc,url) { | |
//standard XPath header | |
var namespace = doc.documentElement.namespaceURI; | |
var nsResolver = namespace ? function(prefix) { | |
if (prefix == 'x') return namespace; else return null; | |
} : null; | |
var myXPath = '//div[@class="field-label"]'; | |
var myXPathObject = doc.evaluate(myXPath, doc, nsResolver, XPathResult.ANY_TYPE, null); | |
// Two loops are needed because the item type has to be determined before the Zotero object can be | |
// first get all the information into arrays, identifying the item type and cleaning up the authorscreated | |
var labels = new Array(); | |
var items = new Array(); | |
var creatorArray = new Array(); | |
var item; | |
var headers; | |
var i=0; | |
var count=0; | |
while (headers = myXPathObject.iterateNext()) { | |
labels[i]=headers.textContent.trim(); | |
item=headers.nextElementSibling.textContent; | |
if (labels[i].match("Reference type:")) { | |
itemType=itemTypeMap[item.replace(/;/g,"")]; | |
var newItem = new Zotero.Item(itemType); | |
} | |
if (labels[i]=="Author(s):") { | |
for (j=0;j<headers.nextElementSibling.childElementCount;j++){ | |
creatorArray.push(Zotero.Utilities.cleanAuthor(headers.nextElementSibling.childNodes[j].textContent, "author",true)); | |
} | |
item=creatorArray; | |
} | |
if (labels[i]=="Editor(s):") { | |
var itemArray = new Array(); | |
for (j=0;j<headers.nextElementSibling.childElementCount;j++){ | |
creatorArray.push(Zotero.Utilities.cleanAuthor(headers.nextElementSibling.childNodes[j].textContent, "editor",true)); | |
} | |
item=creatorArray; | |
} | |
items[labels[i]]=item; | |
i++; | |
} | |
// second map the information in the arrays onto the Zotero item object | |
count=i-1; | |
for (i=0;i<count;i++){ | |
if (labels[i].match("Full title:")) {newItem.title=items[labels[i]]} | |
else if (labels[i]=="Author(s):") {newItem.creators=items[labels[i]]} | |
else if (labels[i]=="Editor(s):") {newItem.creators=items[labels[i]]} | |
else if (labels[i].match("notes")) {newItem.notes.push({title:labels[i],note:items[labels[i]]})} | |
else if (labels[i].match("Label")) {newItem.tags.push(items[labels[i]])} | |
else if (labels[i].match("Primary")) {newItem.tags.push(items[labels[i]])} | |
else if (labels[i].match("Scroll")) {newItem.tags.push(items[labels[i]])} | |
else if (labels[i].match("year")) {newItem.date=items[labels[i]]} | |
else if (labels[i].match("Journal / Book Title")) { | |
if (itemType=="book") {newItem.series=items[labels[i]]} | |
else if (itemType=="bookSection") {newItem.bookTitle=items[labels[i]]} | |
else {newItem.publicationTitle=items[labels[i]]} | |
} | |
else if (labels[i]=="Series Title:") { | |
if(items[labels[i]].match(/ [0-9]/)) { | |
newItem.series=items[labels[i]].split(" ")[0]; | |
newItem.seriesNumber=items[labels[i]].split(" ")[1]; | |
} else { | |
newItem.series=items[labels[i]]; | |
} | |
} | |
else if (labels[i]=="Volume:") {newItem.volume=items[labels[i]]} | |
else if (labels[i].match("Issue")) { | |
if (itemType.match("book")) {newItem.seriesNumber=items[labels[i]]} | |
else if (itemType=="newspaperArticle") {newItem.date=items[labels[i]]} | |
else {newItem.issue=items[labels[i]]} | |
} | |
else if (labels[i].match("Abbreviated")) {newItem.journalAbbreviation=items[labels[i]]} | |
else if (labels[i].match("[Pp]ages")) {newItem.pages=items[labels[i]]} | |
else if (labels[i].match("Work type")) { | |
if (itemType=="thesis") {newItem.thesisType=items[labels[i]]} | |
else {newItem.tags.push(items[labels[i]])} | |
} | |
else if (labels[i].match("[Aa]bstract")) {newItem.abstractNote=items[labels[i]]} | |
else if (labels[i].match("URL")) {newItem.url=items[labels[i]]} | |
else if (labels[i].match("[Pp]lace")) {newItem.place=items[labels[i]]} | |
else if (labels[i].match("Publisher")) { | |
if (itemType=="thesis") {newItem.university=items[labels[i]]} | |
else {newItem.publisher=items[labels[i]]} | |
} | |
else if (labels[i].match("Record reference")) {newItem.extra=items[labels[i]]} | |
else if (labels[i].match("Language")) {newItem.language=items[labels[i]]} | |
else {newItem.notes.push({title:labels[i],note:items[labels[i]]})} | |
} | |
// save the new item to the Zotero database | |
newItem.complete(); | |
}/** BEGIN TEST CASES **/ | |
var testCases = [] | |
/** END TEST CASES **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment