{ "translatorID": "fe728bc9-595a-4f03-98fc-766f1d8d0936", "label": "Wiley Online Library", "creator": "Sean Takats, Michael Berkowitz and Avram Lyon", "target": "^https?://onlinelibrary\\.wiley\\.com[^\\/]*/(?:doi|advanced/search)", "minVersion": "1.0.0b4.r5", "maxVersion": "", "priority": 100, "browserSupport": "gcs", "inRepository": true, "translatorType": 4, "lastUpdated": "2011-08-22 22:33:07" } /* Wiley Online Translator Copyright (C) 2011 CHNM and Avram Lyon This program 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 program 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 this program. If not, see . */ function detectWeb(doc, url){ var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { if (prefix == 'x') return namespace; else return null; } : null; if (url.match(/\/issuetoc|\/results/)) { return "multiple"; } else return "journalArticle"; } function doWeb(doc, url){ // Define ZU, Z if (!ZU) var ZU = Zotero.Utilities; if (!Z) var Z = Zotero; var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { if (prefix == 'x') return namespace; else return null; } : null; var host = 'http://' + doc.location.host + "/"; var urls = new Array(); if(detectWeb(doc, url) == "multiple") { //search var title; var availableItems = new Array(); var articles = doc.evaluate('//li//div[@class="citation article" or @class="citation tocArticle"]/a', doc, nsResolver, XPathResult.ANY_TYPE, null); var article = false; while (article = articles.iterateNext()) { availableItems[article.href] = article.textContent; } var items = Zotero.selectItems(availableItems); if(!items) { return true; } for (var i in items) { urls.push(i); } Zotero.Utilities.processDocuments(urls, scrape, function () { Zotero.done(); }); } else { //single article if (url.indexOf("/pdf/") != -1) { url = url.replace(/\/pdf\/.+$/,'/abstract'); Z.debug("Redirecting to abstract page: "+url); Zotero.Utilities.processDocuments([ url ], scrape, function () { Zotero.done(); }); } else { scrape(doc, url); } } Zotero.wait(); } function parseIdentifier(identifier) { var idPieces = identifier.split(':'); if (idPieces.length > 1) { var prefix = idPieces.shift(); switch (prefix.toLowerCase()) { case "doi": return ["doi", idPieces.join(':')]; case "isbn": return ["isbn", idPieces.join(':')]; case "issn": return ["issn", idPieces.join(':')]; case "pmid": return ["pmid", idPieces.join(':')]; default: // do nothing } Zotero.debug("Unknown identifier prefix '"+prefix+"'"); return [prefix, idPieces.join(':')]; } if (identifer.substr(0,3) == '10.') return ["doi", identifier]; // If we're here, we have a funny number, and we don't know what to do with it. var ids = idCheck(identifier); if (ids.isbn13) return ["isbn13", isbn13]; if (ids.isbn10) return ["isbn10", isbn10]; if (ids.issn) return ["issn", isbn10]; return ["unknown", identifier]; } function addIdentifier(identifier, item) { var parsed = parseIdentifier(identifier); switch (parsed[0]) { case "doi": item.DOI = parsed[1]; break; case "isbn": item.ISBN = parsed[1]; break; case "isbn13": item.ISBN = parsed[1]; break; case "isbn10": item.ISBN = parsed[1]; break; case "issn": item.ISSN = parsed[1]; break; default: } } function scrape(doc,url) { var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { if (prefix == 'x') return namespace; else return null; } : null; var newItem=new Zotero.Item("journalArticle"); var temp; var xpath; var row; var rows; newItem.url = doc.location.href; var metaTags = doc.getElementsByTagName("meta"); var pages = [false, false]; var doi = false; var pdf = false; var html = false; for (var i = 0; i< metaTags.length; i++) { var tag = metaTags[i].getAttribute("name"); var value = metaTags[i].getAttribute("content"); //Zotero.debug(pages + pdf + html); //Zotero.debug("Have meta tag: " + tag + " => " + value); switch (tag) { // PRISM case "prism.publicationName": newItem.publicationTitle = value; break; case "prism.issn": if (!newItem.ISSN && value != "NaN" && value != "") newItem.ISSN = value; break; case "prism.eIssn": if (!newItem.ISSN && value != "NaN" && value != "") newItem.ISSN = value; break; // This is often NaN for some reason case "prism.publicationDate": if (!newItem.date && value != "NaN" && value !== "") newItem.date = value; break; case "prism.volume": if (!newItem.volume && value != "NaN" && value != "") newItem.volume = value; break; case "prism.number": if (!newItem.issue && value != "NaN" && value != "") newItem.issue = value; break; // These also seem bad case "prism.startingPage": if(!pages[0] && value != "null" && value != "") pages[0] = value; break; case "prism.endingPage": if(!pages[1] && value != "null" && value != "") pages[1] = value; break; case "prism.number": newItem.issue = value; break; // Google. case "citation_journal_title": if (!newItem.publicationTitle) newItem.publicationTitle = value; break; case "citation_authors": if (newItem.creators.length == 0) { for each(var author in value.split(';')) { if (author.toUpperCase() == author) author = ZU.capitalizeTitle(author.toLowerCase(), true); newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author", true)); } } break; case "citation_title": if (!newItem.title) newItem.title = value; break; case "citation_publisher": if (!newItem.publisher) newItem.publisher = value; break; case "citation_date": if (!newItem.date && value != "NaN" && value != "") newItem.date = value; break; case "citation_year": if (!newItem.date && value != "NaN" && value != "") newItem.date = value; break; case "citation_volume": if (!newItem.volume && value != "NaN" && value != "") newItem.volume = value; break; case "citation_issue": if (!newItem.issue && value != "NaN" && value != "") newItem.issue = value; break; case "citation_firstpage": if (!pages[0] && value != "NaN" && value != "") pages[0] = value; break; case "citation_lastpage": if (!pages[1] && value != "NaN" && value != "") pages[1] = value; break; case "citation_issn": if (!newItem.ISSN && value != "NaN" && value != "") newItem.ISSN = value; break; case "citation_isbn": if (!newItem.ISBN && value != "NaN" && value != "") newItem.ISBN = value; break; // Prefer long language names case "citation_language": if ((!newItem.language || newItem.language.length < 4) && value != "null" && value != "") newItem.language = value; break; case "citation_doi": if (!newItem.DOI) newItem.DOI = value; break; case "citation_abstract": newItem.abstractNote = value; break; case "citation_abstract_html_url": newItem.url = value; break; case "citation_pdf_url": if(!pdf) pdf = value; break; case "citation_keywords": newItem.tags.push(value); break; case "citation_fulltext_html_url": if(!pdf) pdf = value; break; case "fulltext_pdf": if(!pdf) pdf = value; break; // Dublin Core case "dc.publisher": if(!newItem.publisher) newItem.publisher = value; break; case "dc.language": if(!newItem.language) newItem.language = value; break; case "dc.rights": if(!newItem.rights) newItem.rights = value; break; case "dc.title": if(!newItem.title) newItem.title = value; break; case "dc.creator": if(!newItem.creators.length == 0) newItem.creators.push(Zotero.Utilities.cleanAuthor(value)); break; // This is often NaN for some reason case "dc.date": if (!newItem.date && value != "NaN" && value !== "") newItem.date = value; break; case "dc.identifier": addIdentifier(value, newItem); break; default: Zotero.debug("Ignoring meta tag: " + tag + " => " + value); } } if (pages[0] && pages[1]) newItem.pages = pages.join('-') else newItem.pages = pages[0] ? pages[1] : (pages[1] ? pages[1] : ""); // Abstracts don't seem to come with if (!newItem.abstractNote) { var abstractNode = doc.evaluate('//div[@id="abstract"]/div[@class="para"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext(); if (abstractNode) newItem.abstractNote = abstractNode.textContent; } // Fix things in uppercase var toFix = [ "title", "shortTitle" ]; for each (var i in toFix) { if (newItem[i] && newItem[i].toUpperCase() == newItem[i]) newItem[i] = Zotero.Utilities.capitalizeTitle(newItem[i].toLowerCase(), true); } // Remove final asterisk in title if present newItem.title = newItem.title.replace(/\*$/,''); if (html) newItem.attachments = [{url:html, title:"Wiley Full Text HTML"}]; if (pdf) { Zotero.Utilities.doGet(pdf, function(text) { pdf = text.match(/