Created
May 21, 2009 19:21
-
-
Save rmzelle/115663 to your computer and use it in GitHub Desktop.
royalsocietypublishing
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
REPLACE INTO translators VALUES ('027f1b68-4f4b-4644-b6ee-f6f06bd56746', '1.0.0b4.r5', '', '2009-05-22 14:16:02', '0', '1', '4', 'Royal Society Publishing redux', 'Michael Berkowitz and Rintze Zelle', 'http://[a-z]+\.royalsocietypublishing.org/', | |
'function detectWeb(doc, url) { | |
var namespace = doc.documentElement.namespaceURI; | |
var nsResolver = namespace ? function(prefix) { | |
if (prefix == ''x'') return namespace; else return null; | |
} : null; | |
try { | |
var pageType = doc.evaluate(''/html/body/div'', doc, null, XPathResult.ANY_TYPE, null).iterateNext().id; | |
if (pageType == "pageid-content") { | |
return "journalArticle"; | |
} else if (pageType == "pageid-search-results" || pageType == "pageid-toc" || pageType == "pageid-gca" || pageType == "pageid-pap-index") { | |
return "multiple"; | |
} | |
} catch (e) { | |
} | |
}', | |
'function journalIdentifier(journalShortID) { | |
switch(journalShortID) | |
{ | |
case "rsbl": | |
return "roybiolett"; | |
case "rstb": | |
return "royptb"; | |
case "rspb": | |
return "royprsb"; | |
case "rsif": | |
return "royinterface"; | |
case "rsta": | |
return "roypta"; | |
case "rspa": | |
return "royprsa"; | |
case "rsnr": | |
return "roynotesrec"; | |
} | |
} | |
function makeURL(str, type) { | |
if (!str.match("early")) { | |
var m = str.match(/([\w]+)\.royalsocietypublishing.org\/content\/([^\.]+)/); | |
var journal = m[1]; | |
var articleID = m[2]; | |
if (type == "ris") { | |
return "http://" + journal + ".royalsocietypublishing.org/citmgr?type=refman&gca=" + journalIdentifier(journal) + ";" + articleID; | |
} else if (type == "pdf") { | |
return "http://" + journal + ".royalsocietypublishing.org/content/" + articleID +".full.pdf"; | |
} | |
} else { | |
var m = str.match(/([\w]+)\.royalsocietypublishing.org\/content\/early\/([\d\/]+)\/([^\/]+\d)/); | |
var journal = m[1]; | |
var articleID = m[3]; | |
var articleIDPartTwo = m[2]; | |
if (type == "ris") { | |
return "http://" + journal + ".royalsocietypublishing.org/citmgr?type=refman&gca=" + journalIdentifier(journal) + ";" + articleID; | |
} else if (type == "pdf") { | |
return "http://" + journal + ".royalsocietypublishing.org/content/early/" + articleIDPartTwo + "/" + articleID +".full.pdf"; | |
} | |
} | |
} | |
function doWeb(doc, url) { | |
var namespace = doc.documentElement.namespaceURI; | |
var nsResolver = namespace ? function(prefix) { | |
if (prefix == ''x'') return namespace; else return null; | |
} : null; | |
var rislinks = new Array(); | |
var pdflinks = new Array(); | |
if (detectWeb(doc, url) == "multiple") { | |
var items = new Object(); | |
var articleLinks = doc.evaluate(''//a[@rel="full-text.pdf"]'', doc, null, XPathResult.ANY_TYPE, null); | |
if (doc.evaluate(''//span[@class="cit-title"]'', doc, null, XPathResult.ANY_TYPE, null).iterateNext() != null) { | |
var articleTitles = doc.evaluate(''//span[@class="cit-title"]'', doc, null, XPathResult.ANY_TYPE, null); | |
} else { | |
var articleTitles = doc.evaluate(''//div[@class="cit-metadata"]/h4'', doc, null, XPathResult.ANY_TYPE, null); | |
} | |
var link; | |
while (link = articleLinks.iterateNext()) { | |
items[link.href] = articleTitles.iterateNext().textContent; | |
} | |
items = Zotero.selectItems(items); | |
for (var i in items) { | |
rislinks.push(makeURL(i, "ris")); | |
pdflinks.push(makeURL(i, "pdf")); | |
} | |
} else { | |
rislinks.push(makeURL(url, "ris")); | |
pdflinks.push(makeURL(url, "pdf")); | |
} | |
Zotero.Utilities.HTTP.doGet(rislinks, function(ris) { | |
var pdflink = pdflinks.shift(); | |
var translator = Zotero.loadTranslator("import"); | |
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7"); | |
translator.setString(ris); | |
translator.setHandler("itemDone", function(obj, item) { | |
item.attachments = [ | |
{url:pdflink, title:"Royal Society PDF", mimeType:"application/pdf"} | |
]; | |
item.notes = null; | |
item.complete(); | |
}); | |
translator.translate(); | |
}, function() { Zotero.done(); }, null); | |
Zotero.wait(); | |
}'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment