{ "translatorID": "add7c71c-21f3-ee14-d188-caf9da12728b", "label": "Library Catalog (SIRSI)", "creator": "Sean Takats, Hicham El Kasmi", "target": "/uhtbin/(?:cgisirsi|quick_keyword)", "minVersion": "2.1", "maxVersion": "", "priority": 250, "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", "lastUpdated": "2014-08-26 04:09:11" } /*Spanish Libraries: No Permalinks, so no tests Biblioteca Nacional (Spanish National Library): http://catalogo.bne.es/uhtbin/webcat Universidad Carlos III de madrid: http://www.uc3m.es/portal/page/portal/library Universidad Autonoma de Madrid: http://biblos.uam.es/uhtbin/webcat UNED: http://biblio15.uned.es/ */ function detectWeb(doc, url) { var xpath = '//tr[th[@class="viewmarctags"]][td[@class="viewmarctags"]]'; if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { Zotero.debug("SIRSI detectWeb: viewmarctags"); return "book"; } var xpath = '//dl[dt[@class="viewmarctags"]][dd[@class="viewmarctags"]]'; if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { Zotero.debug("SIRSI detectWeb: viewmarctags"); return "book"; } var xpath = '//input[@name="VOPTIONS"]'; if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { Zotero.debug("SIRSI detectWeb: VOPTIONS"); return "book"; } var elmts = doc.evaluate('/html/body/form//text()', doc, null, XPathResult.ANY_TYPE, null); while(elmt = elmts.iterateNext()) { if(Zotero.Utilities.superCleanString(elmt.nodeValue) == "Viewing record") { Zotero.debug("SIRSI detectWeb: Viewing record"); return "book"; } } var xpath = '//td[@class="searchsum"]/table'; if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { Zotero.debug("SIRSI detectWeb: searchsum"); return "multiple"; } var xpath = '//form[@name="hitlist"]/table/tbody/tr'; if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { Zotero.debug("SIRSI detectWeb: hitlist"); return "multiple"; } } function scrape(doc) { //second xpath version for http://catalogue-bibliotheques.upmc.fr var xpath = '//tr[th[@class="viewmarctags"]][td[@class="viewmarctags"]]|//dl/dt[@class="viewmarctags"]'; var elmts = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); var elmt = elmts.iterateNext(); if(!elmt) { return false; } var newItem = new Zotero.Item("book"); newItem.extra = ""; var note; authors = []; while(elmt) { try { var node = ZU.xpathText(elmt, './TD[1]/A[1]/span/text()[1]|./following-sibling::dd[1]/a[1]/span/text()'); if(!node) { var node = ZU.xpathText(elmt, './TD[1]/A[1]/text()[1]|./following-sibling::dd[1]/a[1]/text()'); } if(!node) { var node = ZU.xpathText(elmt, './TD[1]/text()[1]|./following-sibling::dd[1]/text()') } if(node) { var casedField = Zotero.Utilities.superCleanString(ZU.xpathText(elmt, './th[1]/text()|./text()')); field = casedField.toLowerCase(); //Z.debug(field) field = field.replace(/:./,"").trim(); var value = Zotero.Utilities.superCleanString(node); //Z.debug(value) if(field == "publisher" || field == "éditeur" ) { newItem.publisher = value; } else if(field == "physical description" || field == "desc. matérielle" ||field == "description physique" ||field== "descripción física" ||field== "descripcion fisica" || field == "descr. física") { value = value.match(/([\d\sxvi]+)p/)[1]; if (value) newItem.numPages = value; } else if(field == "pub date" || field == "année" || field =="fecha de pub") { var re = /[0-9]+/; var m = re.exec(value); newItem.date = m[0]; } else if(field == "isbn") { var re = /^[0-9\-](?:[0-9X\-]+)/; var m = re.exec(value); newItem.ISBN = m[0]; } else if(field == "issn") { newItem.ISSN = value; } else if(field == "title" || field == "titre" ||field == "titulo" || field =="título") { var titleParts = value.split(" / "); newItem.title = Zotero.Utilities.capitalizeTitle(titleParts[0]); } else if (field == "serie"){ newItem.series = value; } else if (field == "langue" || field == "language"){ newItem.language = value; } else if(field == "series title" || field == "titre de série" || field == "collection") { newItem.series = value.replace(/^\(|\)$/g, ""); } else if(field == "publication info" || field == "publication" || field =="publicación" ||field =="publicacion") { //this is a bit tricky - can be in the form Place : Publisher; Place : Publisher, Year //or Place; Place : Publisher - the code` should get all cases and produce uniform output var places = []; var publishers = []; var pubParts = value.split(/\s*;\s*/); for (var i in pubParts){ var pubPart = pubParts[i].split(/\s*:\s*/); places.push(pubPart[0]); if (pubPart[1]){ if (pubPart[1].match(/\d+/)) newItem.date = pubPart[1].match(/\d+/)[0]; publishers.push(pubPart[1].match(/[^,]+/)[0]) } } newItem.publisher = publishers.join("; "); newItem.place = places.join("; "); } else if(field == "personal author" || field == "autor personal" || field == "auteur") { if(authors.indexOf(value) == -1) { value = value.replace(/(\(|\)|\d+|\-)/g, ""); newItem.creators.push(Zotero.Utilities.cleanAuthor(value, "author", true)); authors.push(value); } } else if(field == "author" || field == "auteur" || field == "autor"){ if(authors.indexOf(value) == -1) { value = value.replace(/(\(|\)|\d+|\-)/g, ""); newItem.creators.push(Zotero.Utilities.cleanAuthor(value, "author", true)); authors.push(value); } } else if(field == "added author" || field == "organisme" || field == "autor secundario") { if(authors.indexOf(value) == -1) { newItem.creators.push(Zotero.Utilities.cleanAuthor(value, "contributor", true)); authors.push(value); } } else if(field == "corporate author") { if(authors.indexOf(value) == -1) { newItem.creators.push({lastName:value, fieldMode:true}); authors.push(value); } } else if(field == "general note" || field == "note" || field =="nota general") { newItem.notes.push(value); } else if(field == "edition" || field == "édition" ||field =="edición" ||field =="edicion") { newItem.edition = value; } else if(field == "additional formats" || field == "autres supports") { newItem.additionalformats = value; } else if(field == "continued by" || field == "devient") { newItem.continuedby = value; } else if(field == "subject term" || field == "corporate subject" || field == "geographic term" || field == "subject" || field == "sujet" || field == "sujet géographique" || field == "materia-autor personal" || field == "materia") { var subjects = value.split("--"); for(var i=0; i\s*(.*[^\s])\s*
/i; var items = new Array(); do { var checkbox = doc.evaluate('.//input[@type="checkbox"]', elmt, null, XPathResult.ANY_TYPE, null).iterateNext(); // Collect title var title = doc.evaluate("./td[2]", elmt, null, XPathResult.ANY_TYPE, null).iterateNext().textContent; if(checkbox && title) { items[checkbox.name] = Zotero.Utilities.trimInternal(title); } } while(elmt = elmts.iterateNext()); items = Zotero.selectItems(items); if(!items) { return true; } for(var i in items) { recNumbers.push(i); } } else { // Normal page // this regex will fail about 1/100,000,000 tries var uriRegexp = /^((.*?)\/([0-9]+?))\//; var m = uriRegexp.exec(uri); var newUri = m[1]+"/40"; var elmts = doc.evaluate('/html/body/form', doc, null, XPathResult.ANY_TYPE, null); while(elmt = elmts.iterateNext()) { var initialText = doc.evaluate('.//text()[1]', elmt, null, XPathResult.ANY_TYPE, null).iterateNext(); if(initialText && initialText.nodeValue && Zotero.Utilities.superCleanString(initialText.nodeValue) == "Viewing record") { recNumbers.push(doc.evaluate('./b[1]/text()[1]', elmt, null, XPathResult.ANY_TYPE, null).iterateNext().nodeValue); break; } } // begin Emory compatibility var elmts = doc.evaluate('//input[@name="first_hit"]', doc, null, XPathResult.ANY_TYPE, null); while (elmt = elmts.iterateNext()) { recNumbers.length = 0; var recNumber = elmt.value; recNumbers.push(recNumber); break; } // end Emory compatibility } var translator = Zotero.loadTranslator("import"); translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973"); translator.getTranslatorObject(function(marc) { Zotero.Utilities.loadDocument(newUri+'?marks='+recNumbers.join(",")+'&shadow=NO&format=FLAT+ASCII&sort=TITLE&vopt_elst=ALL&library=ALL&display_rule=ASCENDING&duedate_code=l&holdcount_code=t&DOWNLOAD_x=22&DOWNLOAD_y=12&address=&form_type=', function(doc) { var pre = doc.getElementsByTagName("pre"); var text = pre[0].textContent; var documents = text.split("*** DOCUMENT BOUNDARY ***"); for(var j=1; j