Created
May 30, 2009 17:17
-
-
Save rmzelle/120563 to your computer and use it in GitHub Desktop.
PLoS Journals Redux
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
function detectWeb(doc, url) { | |
if (url.indexOf("Search.action") != -1 || url.indexOf("browse.action") != -1 || url.indexOf("browseIssue.action") != -1) { | |
return "multiple"; | |
} else if (url.indexOf("article/info") != -1) { | |
return "journalArticle"; | |
} | |
} | |
function getSelectedItems(doc, articleRegEx) { | |
var items = new Object(); | |
var texts = new Array(); | |
var articles = doc.evaluate(articleRegEx, doc, null, XPathResult.ANY_TYPE, null); | |
var next_art = articles.iterateNext(); | |
while (next_art) { | |
items[next_art.href] = next_art.textContent; | |
next_art = articles.iterateNext(); | |
} | |
items = Zotero.selectItems(items); | |
for (var i in items) { | |
texts.push(i); | |
} | |
return(texts); | |
} | |
function doWeb(doc, url) { | |
if (url.indexOf("Search.action") != -1 || url.indexOf("browse.action") != -1) { | |
var articlex = '//span[@class="article"]/a'; | |
var texts = getSelectedItems(doc, articlex); | |
} else if (url.indexOf("browseIssue.action") != -1) { | |
var articlex = '//div[@class="article"]/h3/a'; | |
var texts = getSelectedItems(doc, articlex); | |
} else { | |
var texts = new Array(url); | |
} | |
var risLinks = new Array(); | |
for (var i in texts) { | |
texts[i]=texts[i].replace(/;jsessionid[^;]+/, "");//Strip sessionID string | |
var risLink = texts[i].replace("info", "getRisCitation.action?articleURI=info"); | |
risLinks.push(risLink); | |
} | |
Zotero.Utilities.HTTP.doGet(risLinks, function(text) { | |
var risLink = texts.shift(); | |
var pdfURL = risLink.replace("info", "fetchObjectAttachment.action?uri=info") + '&representation=PDF'; | |
var doi = risLink.match(/doi(\/|%2F)(.*)$/)[2]; | |
text = text.replace(text.match(/(ER[^\n]*)([^\0]*)/)[2],"");//Remove stray M3-tag at the end of the RIS record | |
text = text.replace("%2F","/");//Replace %2F characters by forward slashes in url | |
doi = doi.replace("%2F","/");//Replace %2F characters by forward slashes in doi | |
var translator = Zotero.loadTranslator("import"); | |
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7"); | |
translator.setString(text); | |
translator.setHandler("itemDone", function(obj, item) { | |
item.attachments[0]=({url:pdfURL, title:"PLoS One Full Text PDF", mimeType:"application/pdf"}); | |
item.DOI = doi; | |
item.repository = item.publicationTitle; | |
item.complete(); | |
}); | |
translator.translate(); | |
}, function() {Zotero.done();}); | |
Zotero.wait(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment