cleaning up whitespace

This commit is contained in:
Matt Burton 2009-01-14 17:33:14 +00:00
parent 2bcf3f2c98
commit 9568bf6b6f

View File

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