zotero/translators/JSTOR.js

123 lines
3.8 KiB
JavaScript
Raw Normal View History

{
2009-01-14 17:33:14 +00:00
"translatorID":"d921155f-0186-1684-615c-ca57682ced9b",
"translatorType":4,
"label":"JSTOR",
2009-01-12 03:55:55 +00:00
"creator":"Simon Kornblith, Sean Takats, Michael Berkowitz and Eli Osherovich",
2009-05-04 17:46:52 +00:00
"target":"https?://[^/]*jstor\\.org[^/]*/(action/(showArticle|doBasicSearch|doAdvancedSearch|doLocatorSearch|doAdvancedResults|doBasicResults)|stable/|pss/)",
"minVersion":"1.0.0b4.r1",
"maxVersion":"",
"priority":100,
"inRepository":true,
2009-05-04 17:46:52 +00:00
"lastUpdated":"2009-05-04 17:15:00"
}
2009-01-12 03:55:55 +00:00
function detectWeb(doc, url) {
2009-01-14 17:33:14 +00:00
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
2009-01-12 03:55:55 +00:00
if (prefix == 'x') return namespace; else return null;
2009-01-14 17:33:14 +00:00
} : null;
2009-01-14 17:33:14 +00:00
// See if this is a seach results page or Issue content
if (doc.title == "JSTOR: Search Results" || url.match(/\/i\d+/)) {
2009-01-12 03:55:55 +00:00
return "multiple";
2009-01-14 17:33:14 +00:00
} else if(url.indexOf("/search/") != -1) {
2009-01-12 03:55:55 +00:00
return false;
2009-01-14 17:33:14 +00:00
}
2009-01-14 17:33:14 +00:00
// If this is a view page, find the link to the citation
var xpath = '//a[@id="favorites"]';
var elmt = doc.evaluate(xpath, doc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(elmt || url.match(/pss/)) {
2009-01-12 03:55:55 +00:00
return "journalArticle";
2009-01-14 17:33:14 +00:00
}
}
function doWeb(doc, url) {
2009-01-14 17:33:14 +00:00
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
2009-01-12 03:55:55 +00:00
if (prefix == 'x') return namespace; else return null;
2009-01-14 17:33:14 +00:00
} : null;
2009-01-14 17:33:14 +00:00
var host = doc.location.host;
// If this is a view page, find the link to the citation
var xpath = '//a[@id="favorites"]';
var elmt = doc.evaluate(xpath, doc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var allJids = new Array();
if (elmt && /jid=(\d+)/.test(elmt.href)) {
2009-01-12 03:55:55 +00:00
allJids.push(RegExp.$1);
Zotero.debug("JID found 1 " + jid);
2009-01-14 17:33:14 +00:00
}
else if (/(?:pss|stable)\/(\d+)/.test(url)) {
2009-01-12 03:55:55 +00:00
Zotero.debug("URL " + url);
allJids.push(RegExp.$1);
Zotero.debug("JID found 2 " + jid);
2009-01-14 17:33:14 +00:00
}
else {
2009-01-12 03:55:55 +00:00
// We have multiple results
var resultsBlock = doc.evaluate('//fieldset[@id="results"]', doc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (! resultsBlock) {
2009-01-14 17:33:14 +00:00
return true;
2009-01-12 03:55:55 +00:00
}
2009-01-12 03:55:55 +00:00
var allTitlesElmts = doc.evaluate('//li/ul/li/a[@class="title"]', resultsBlock, nsResolver, XPathResult.ANY_TYPE, null);
var currTitleElmt;
var availableItems = new Object();
while (currTitleElmt = allTitlesElmts.iterateNext()) {
2009-01-14 17:33:14 +00:00
var title = currTitleElmt.textContent;
var jid = currTitleElmt.href.match(/stable\/([a-z]*?\d+)/)[1];
2009-01-14 17:33:14 +00:00
if (jid) {
2009-01-12 03:55:55 +00:00
availableItems[jid] = title;
2009-01-14 17:33:14 +00:00
}
Zotero.debug("Found title " + title+jid);
2009-01-12 03:55:55 +00:00
}
Zotero.debug("End of titles");
2009-01-12 03:55:55 +00:00
var selectedItems = Zotero.selectItems(availableItems);
if (!selectedItems) {
2009-01-14 17:33:14 +00:00
return true;
}
2009-01-12 03:55:55 +00:00
for (var j in selectedItems) {
2009-01-14 17:33:14 +00:00
Zotero.debug("Pushing " + j);
allJids.push(j);
2009-01-12 03:55:55 +00:00
}
2009-01-14 17:33:14 +00:00
}
for (var i in allJids) {
2009-01-12 03:55:55 +00:00
var downloadString = "&suffix="+allJids[i];
Zotero.Utilities.HTTP.doPost("http://"+host+"/action/downloadSingleCitation?format=refman&direct=true&singleCitation=true",downloadString, function(text) {
// load translator for RIS
var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
translator.setHandler("itemDone", function(obj, item) {
if(item.notes && item.notes[0]) {
2009-01-14 17:33:14 +00:00
// For some reason JSTOR exports abstract with 'AB' tag istead of 'N1'
item.abstractNote = item.notes[0].note;
delete item.notes;
item.notes = undefined;
}
item.attachments[0].title = item.title;
item.attachments[0].mimeType = "text/html";
2009-01-12 03:55:55 +00:00
if (/stable\/(\d+)/.test(item.url)) {
2009-01-14 17:33:14 +00:00
var localJid = RegExp.$1;
// Add DOI
if (! item.DOI) {
2009-01-12 03:55:55 +00:00
item.DOI = "10.2307/"+localJid;
2009-01-14 17:33:14 +00:00
}
var pdfurl = "http://"+ host + "/stable/pdfplus/" + localJid + ".pdf";
item.attachments.push({url:pdfurl, title:"JSTOR Full Text PDF", mimeType:"application/pdf"});
2009-01-12 03:55:55 +00:00
}
item.complete();
2009-01-14 17:33:14 +00:00
});
translator.translate();
2009-01-12 03:55:55 +00:00
Zotero.done();
2009-01-14 17:33:14 +00:00
});
}
2009-01-12 03:55:55 +00:00
}