{ "translatorID":"2d174277-7651-458f-86dd-20e168d2f1f3", "translatorType":4, "label":"Canadiana.org", "creator":"Adam Crymble", "target":"http://(www.)?canadiana.org", "minVersion":"1.0.0b4.r5", "maxVersion":"", "priority":100, "inRepository":true, "lastUpdated":"2008-06-12 19:30:00" } function detectWeb(doc, url) { //checks the title of the webpage. If it matches, then the little blue book symbol appears in the address bar. //works for English and French versions of the page. if(doc.title == "Early Canadiana Online - Item Record"|doc.title == "Notre mémoire en ligne - Notice") { return "book"; } else if (doc.evaluate('//div[@id="Content"]/div[@class="NormalRecord"]/h3/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { return "multiple"; } } //Canadiana Translator Coding by Adam Crymble //because the site uses so many random formats for the "Imprint" field, it's not always perfect. But it works for MOST entries function associateData (newItem, dataTags, field, zoteroField) { if (dataTags[field]) { newItem[zoteroField] = dataTags[field]; } } function scrape(doc, url) { var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { if (prefix == "x" ) return namespace; else return null; } : null; //declaring variables to be used later. var newItem = new Zotero.Item("book"); newItem.url = doc.location.href; var dataTags = new Object(); var fieldTitle; var tagsContent= new Array(); //these variables tell the program where to find the data we want in the HTML file we're looking at. //in this case, the data is found in a table. var xPath1 = '//tr/td[1][@class="Label"]'; var xPath2 = '//tr/td[2]'; //at this point, all the data we want has been saved into the following 2 Objects: one for the headings, one for the content. // The 3rd object tells us how many items we've found. if (doc.evaluate('//tr/td[1][@class="Label"]', doc, nsResolver, XPathResult.ANY_TYPE, null)) { var xPath1Results = doc.evaluate(xPath1, doc, nsResolver, XPathResult.ANY_TYPE, null); var xPath2Results = doc.evaluate(xPath2, doc, nsResolver, XPathResult.ANY_TYPE, null); var xPathCount = doc.evaluate( 'count (//tr/td[1][@class="Label"])', doc, nsResolver, XPathResult.ANY_TYPE, null); } //At this point we have two lists (xPath1Results and xPath2Results). this loop matches the first item in the first list //with the first item in the second list, and on until the end. //If we then ask for the "Principal Author" the program returns "J.K. Rowling" instead of "Principal Author" if (doc.evaluate('//tr/td[1][@class="Label"]', doc, nsResolver, XPathResult.ANY_TYPE, null)) { for (i=0; i