Fixes #1452, generic translator for Highwire 2.0 sites.
This commit is contained in:
parent
dbf124ef90
commit
c4f59b07a6
2 changed files with 29 additions and 80 deletions
|
@ -1,40 +1,49 @@
|
||||||
{
|
{
|
||||||
"translatorID":"8c1f42d5-02fa-437b-b2b2-73afc768eb07",
|
"translatorID":"8c1f42d5-02fa-437b-b2b2-73afc768eb07",
|
||||||
"translatorType":4,
|
"translatorType":4,
|
||||||
"label":"PNAS",
|
"label":"Highwire 2.0",
|
||||||
"creator":"Matt Burton",
|
"creator":"Matt Burton",
|
||||||
"target":"http://www\\.pnas\\.org/(content|search|cgi/collection/.+)",
|
"target":"(content/([0-9]+/[0-9]+|current|firstcite)|search|cgi/collection/.+)",
|
||||||
"minVersion":"1.0.0b4.r5",
|
"minVersion":"1.0.0b4.r5",
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":100,
|
"priority":100,
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2008-12-27 20:50:00"
|
"lastUpdated":"2009-05-26 14:35:00"
|
||||||
}
|
}
|
||||||
|
|
||||||
// This translator is for HighWire 2.0
|
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
if (url.match("search") || url.match("content/by/section") || doc.title.match("Table of Contents") || doc.title.match("Early Edition") || url.match("cgi/collection/.+")) {
|
if (
|
||||||
|
url.match("search") ||
|
||||||
|
url.match("content/by/section") ||
|
||||||
|
doc.title.match("Table of Contents") ||
|
||||||
|
doc.title.match("Early Edition") ||
|
||||||
|
url.match("cgi/collection/.+") ||
|
||||||
|
url.match("content/firstcite")
|
||||||
|
) {
|
||||||
return "multiple";
|
return "multiple";
|
||||||
} else if (url.match("content/[0-9]")) {
|
} else if (url.match("content/[0-9]+")) {
|
||||||
return "journalArticle";
|
return "journalArticle";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doWeb(doc, url) {
|
function doWeb(doc, url) {
|
||||||
|
|
||||||
|
|
||||||
|
var host = 'http://' + doc.location.host + "/";
|
||||||
|
|
||||||
var arts = new Array();
|
var arts = new Array();
|
||||||
if (detectWeb(doc, url) == "multiple") {
|
if (detectWeb(doc, url) == "multiple") {
|
||||||
var items = new Object();
|
var items = new Object();
|
||||||
if (doc.title.match("Table of Contents") || doc.title.match("Early Edition")) {
|
if (doc.title.match("Table of Contents") || doc.title.match("Early Edition") || url.match("content/firstcite")) {
|
||||||
var searchx = '//li[@class = "cit toc-cit" and not(ancestor::div/h2/a/text() = "Correction" or ancestor::div/h2/a/text() = "Corrections")]';
|
var searchx = '//li[contains(@class, "cit toc-cit") and not(ancestor::div/h2/a/text() = "Correction" or ancestor::div/h2/a/text() = "Corrections")]';
|
||||||
var titlex = './/h4';
|
var titlex = './/h4';
|
||||||
} else if (url.match("content/by/section") || url.match("cgi/collection/.+")) {
|
} else if (url.match("content/by/section") || url.match("cgi/collection/.+")) {
|
||||||
var searchx = '//li[contains(@class, "results-cit cit")]';
|
var searchx = '//li[contains(@class, "results-cit cit")]';
|
||||||
var titlex = './/span[@class = "cit-title"]';
|
var titlex = './/span[contains(@class, "cit-title"])';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var searchx = '//div[@class = "results-cit cit"]';
|
var searchx = '//div[contains(@class,"results-cit cit")]';
|
||||||
var titlex = './/span[@class = "cit-title"]';
|
var titlex = './/span[contains(@class,"cit-title")]';
|
||||||
}
|
}
|
||||||
var linkx = './/a[1]';
|
var linkx = './/a[1]';
|
||||||
var searchres = doc.evaluate(searchx, doc, null, XPathResult.ANY_TYPE, null);
|
var searchres = doc.evaluate(searchx, doc, null, XPathResult.ANY_TYPE, null);
|
||||||
|
@ -55,6 +64,11 @@ function doWeb(doc, url) {
|
||||||
for each (var i in arts) {
|
for each (var i in arts) {
|
||||||
newurls.push(i);
|
newurls.push(i);
|
||||||
}
|
}
|
||||||
|
Zotero.debug(arts.length);
|
||||||
|
if(arts.length == 0) {
|
||||||
|
Zotero.debug('no items');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Zotero.Utilities.HTTP.doGet(arts, function(text) {
|
Zotero.Utilities.HTTP.doGet(arts, function(text) {
|
||||||
var id = text.match(/=([^=]+)\">\s*Download to citation manager/)[1];
|
var id = text.match(/=([^=]+)\">\s*Download to citation manager/)[1];
|
||||||
var newurl = newurls.shift();
|
var newurl = newurls.shift();
|
||||||
|
@ -64,7 +78,7 @@ function doWeb(doc, url) {
|
||||||
// This is not ideal...todo: brew a regex that grabs the correct URL
|
// This is not ideal...todo: brew a regex that grabs the correct URL
|
||||||
var pdfurl = newurl.slice(0, newurl.lastIndexOf(".")) + ".full.pdf";
|
var pdfurl = newurl.slice(0, newurl.lastIndexOf(".")) + ".full.pdf";
|
||||||
}
|
}
|
||||||
var get = 'http://www.pnas.org/citmgr?type=refman&gca=' + id;
|
var get = host + 'citmgr?type=refman&gca=' + id;
|
||||||
Zotero.Utilities.HTTP.doGet(get, function(text) {
|
Zotero.Utilities.HTTP.doGet(get, function(text) {
|
||||||
var translator = Zotero.loadTranslator("import");
|
var translator = Zotero.loadTranslator("import");
|
||||||
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
|
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
|
||||||
|
@ -74,8 +88,8 @@ function doWeb(doc, url) {
|
||||||
}
|
}
|
||||||
translator.setHandler("itemDone", function(obj, item) {
|
translator.setHandler("itemDone", function(obj, item) {
|
||||||
item.attachments = [
|
item.attachments = [
|
||||||
{url:newurl, title:"PNAS Snapshot", mimeType:"text/html"},
|
{url:newurl, title:"Snapshot", mimeType:"text/html"},
|
||||||
{url:pdfurl, title:"PNAS Full Text PDF", mimeType:"application/pdf"}
|
{url:pdfurl, title:"Full Text PDF", mimeType:"application/pdf"}
|
||||||
];
|
];
|
||||||
if (doi) item.DOI = doi;
|
if (doi) item.DOI = doi;
|
||||||
if (item.notes) item.notes = [];
|
if (item.notes) item.notes = [];
|
|
@ -1,65 +0,0 @@
|
||||||
{
|
|
||||||
"translatorID":"56ea09bc-57ee-4f50-976e-cf7cb1f6c6d8",
|
|
||||||
"translatorType":4,
|
|
||||||
"label":"Royal Society Publishing",
|
|
||||||
"creator":"Michael Berkowitz",
|
|
||||||
"target":"http://journals.royalsociety.org/",
|
|
||||||
"minVersion":"1.0.0b4.r5",
|
|
||||||
"maxVersion":"",
|
|
||||||
"priority":100,
|
|
||||||
"inRepository":true,
|
|
||||||
"lastUpdated":"2008-04-23 09:45:00"
|
|
||||||
}
|
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
|
||||||
if (doc.evaluate('//div[@class="listItemName"]/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
|
||||||
return "multiple";
|
|
||||||
} else if (doc.evaluate('//div[contains(@id, "ExportDiv")]/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
|
||||||
return "journalArticle";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeURL(str, type) {
|
|
||||||
var m = str.match(/content\/([^/]+)/)[1];
|
|
||||||
if (type == "ris") {
|
|
||||||
return "http://journals.royalsociety.org/export.mpx?code=" + m + "&mode=ris";
|
|
||||||
} else if (type == "pdf") {
|
|
||||||
return "http://journals.royalsociety.org/content/" + m + "/fulltext.pdf";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function doWeb(doc, url) {
|
|
||||||
var arts = new Array();
|
|
||||||
if (detectWeb(doc, url) == "multiple") {
|
|
||||||
var items = new Object();
|
|
||||||
var links = doc.evaluate('//div[@class="listItemName"]/a', doc, null, XPathResult.ANY_TYPE, null);
|
|
||||||
var link;
|
|
||||||
while (link = links.iterateNext()) {
|
|
||||||
items[link.href] = link.textContent;
|
|
||||||
}
|
|
||||||
items = Zotero.selectItems(items);
|
|
||||||
for (var i in items) {
|
|
||||||
arts.push(i);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
arts = [url];
|
|
||||||
}
|
|
||||||
for each (var link in arts) {
|
|
||||||
var newurl = makeURL(link, "ris");
|
|
||||||
var pdfurl = makeURL(link, "pdf");
|
|
||||||
Zotero.Utilities.HTTP.doGet(newurl, function(text) {
|
|
||||||
Zotero.debug(text);
|
|
||||||
var translator = Zotero.loadTranslator("import");
|
|
||||||
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
|
|
||||||
translator.setString(text);
|
|
||||||
translator.setHandler("itemDone", function(obj, item) {
|
|
||||||
item.attachments = [
|
|
||||||
{url:link, title:"Royal Society Snapshot", mimeType:"text/html"},
|
|
||||||
{url:pdfurl, title:"Royal Society PDF", mimeType:"application/pdf"}
|
|
||||||
];
|
|
||||||
item.complete();
|
|
||||||
});
|
|
||||||
translator.translate();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue