Skip to content

Commit 3089c8e

Browse files
committed
commit translators as separate files, combine CiteBase translators, and modify SPIE translator
0 parents  commit 3089c8e

File tree

264 files changed

+36688
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+36688
-0
lines changed

A Contra Corriente.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"translatorID":"bbf1617b-d836-4665-9aae-45f223264460",
3+
"translatorType":4,
4+
"label":"A Contra Corriente",
5+
"creator":"Michael Berkowitz",
6+
"target":"http://www.ncsu.edu/project/acontracorriente",
7+
"minVersion":"1.0.0b4.r5",
8+
"maxVersion":"",
9+
"priority":100,
10+
"inRepository":true,
11+
"lastUpdated":"2008-06-03 19:40:00"
12+
}
13+
14+
function detectWeb(doc, url) {
15+
if (doc.evaluate('//tr[td[1]//img][td[3]]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
16+
return "multiple";
17+
}
18+
}
19+
20+
function doWeb(doc, url) {
21+
var arts = doc.evaluate('//tr[td[1]//img][td[3]]', doc, null, XPathResult.ANY_TYPE, null);
22+
var art;
23+
var selectList = new Object();
24+
var items = new Object();
25+
while (art = arts.iterateNext()) {
26+
var item = new Object();
27+
var title = doc.evaluate('.//a', art, null, XPathResult.ANY_TYPE, null).iterateNext();
28+
item['title'] = Zotero.Utilities.trimInternal(title.textContent);
29+
item['pdfurl'] = title.href;
30+
item['author'] = doc.evaluate('.//strong', art, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
31+
selectList[item.title] = item.title;
32+
items[item.title] = item;
33+
}
34+
var selected = Zotero.selectItems(selectList);
35+
var voliss = Zotero.Utilities.trimInternal(doc.evaluate('//td[@class="red01"]/font[2]/strong', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
36+
voliss = voliss.match(/Vol\.\s+(\d+),\s+No\.\s+(\d+)\.\s+([^|]+)|/);
37+
Zotero.debug(voliss);
38+
for each (var title in selected) {
39+
var item = new Zotero.Item("journalArticle");
40+
var olditem = items[title];
41+
item.title = olditem.title;
42+
item.creators = [Zotero.Utilities.cleanAuthor(olditem.author, "author")];
43+
item.volume = voliss[1];
44+
item.issue = voliss[2]
45+
item.date = Zotero.Utilities.trimInternal(voliss[3]);
46+
item.complete();
47+
}
48+
}

ABC-CLIO Serials Web.js

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"translatorID":"a07bb62a-4d2d-4d43-ba08-d9679a0122f8",
3+
"translatorType":4,
4+
"label":"ABC-CLIO Serials Web",
5+
"creator":"Simon Kornblith",
6+
"target":"https?://[^/]*serials\\.abc-clio\\.com[^/]*/active/go/ABC-Clio-Serials_v4",
7+
"minVersion":"1.0.0b3.r1",
8+
"maxVersion":"",
9+
"priority":100,
10+
"inRepository":true,
11+
"lastUpdated":"2008-01-09 20:00:00"
12+
}
13+
14+
function detectWeb(doc, url) {
15+
var namespace = doc.documentElement.namespaceURI;
16+
var nsResolver = namespace ? function(prefix) {
17+
if (prefix == 'x') return namespace; else return null;
18+
} : null;
19+
20+
var result = doc.evaluate('//table[@class="rc_main"]', doc, nsResolver,
21+
XPathResult.ANY_TYPE, null).iterateNext();
22+
if(result) {
23+
return "multiple";
24+
}
25+
}
26+
27+
function doWeb(doc, url) {
28+
var namespace = doc.documentElement.namespaceURI;
29+
var nsResolver = namespace ? function(prefix) {
30+
if (prefix == 'x') return namespace; else return null;
31+
} : null;
32+
33+
var availableItems = new Array();
34+
var availableAttachments = new Array();
35+
36+
var elmts = doc.evaluate('//table[@class="rc_main"]', doc, nsResolver,
37+
XPathResult.ANY_TYPE, null);
38+
var elmt;
39+
while(elmt = elmts.iterateNext()) {
40+
var title = doc.evaluate('./tbody/tr/td[b/text() = "Title:"]',
41+
elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
42+
var checkbox = doc.evaluate('.//input[@type = "checkbox"]',
43+
elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
44+
if(title, checkbox) {
45+
checkbox = checkbox.name;
46+
availableItems[checkbox] = Zotero.Utilities.cleanString(title.textContent).substr(6);
47+
48+
var links = doc.evaluate('./tbody/tr/td[b/text() = "Fulltext: ["]/a',
49+
elmt, nsResolver, XPathResult.ANY_TYPE, null);
50+
var link;
51+
52+
var attach = new Array();
53+
while(link = links.iterateNext()) {
54+
attach.push({url:link.href, title:Zotero.Utilities.cleanString(link.textContent)+" Full Text",
55+
mimeType:"text/html"});
56+
}
57+
availableAttachments[checkbox] = attach;
58+
}
59+
}
60+
61+
var items = Zotero.selectItems(availableItems);
62+
63+
if(!items) {
64+
return true;
65+
}
66+
67+
var postString = "_defaultoperation=Download+Options&research_field=&research_value=&jumpto=";
68+
var attachments = new Array();
69+
for(var i in availableItems) {
70+
postString += "&_checkboxname="+i+(items[i] ? "&"+i+"=1" : "");
71+
if(items[i]) {
72+
attachments.push(availableAttachments[i]);
73+
}
74+
}
75+
76+
Zotero.Utilities.HTTP.doPost(url, postString, function(text) {
77+
Zotero.Utilities.HTTP.doPost(url, "_appname=serials&_defaultoperation=Download+Documents&_formname=download&download_format=citation&download_which=tagged&download_where=ris&mailto=&mailreplyto=&mailsubject=&mailmessage=",
78+
function(text) {
79+
// get link
80+
var linkRe = /<a\s+class="button"\s+href="([^"]+)"\s+id="resource_link"/i;
81+
var m = linkRe.exec(text);
82+
if(!m) {
83+
throw("regular expression failed!");
84+
}
85+
Zotero.Utilities.HTTP.doGet(m[1], function(text) {
86+
// load translator for RIS
87+
var translator = Zotero.loadTranslator("import");
88+
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
89+
translator.setString(text);
90+
translator.setHandler("itemDone", function(obj, item) {
91+
if(item.notes && item.notes[0]) {
92+
item.extra = item.notes[0].note;
93+
94+
delete item.notes;
95+
item.notes = undefined;
96+
}
97+
98+
// grab uni data from thesis
99+
if(item.itemType == "thesis") {
100+
var re = /^(.+?) ([0-9]{4})\. ([0-9]+) pp\.(.*)$/;
101+
var m = re.exec(item.extra);
102+
if(m) {
103+
item.publisher = m[1];
104+
item.date = m[2];
105+
item.pages = m[3];
106+
item.extra = m[4];
107+
}
108+
}
109+
110+
// fix periods
111+
for(var i in item.creators) {
112+
var nameLength = item.creators[i].firstName.length;
113+
114+
if(item.creators[i].firstName[nameLength-1] == ".") {
115+
item.creators[i].firstName = item.creators[i].firstName.substr(0, nameLength-1);
116+
}
117+
}
118+
for(var i in item.tags) {
119+
var tagLength = item.tags[i].length;
120+
121+
if(item.tags[i][tagLength-1] == ".") {
122+
item.tags[i] = item.tags[i].substr(0, tagLength-1);
123+
}
124+
}
125+
126+
// fix title
127+
item.title = Zotero.Utilities.superCleanString(item.title);
128+
129+
// add attachments
130+
item.attachments = attachments.shift();
131+
132+
item.complete();
133+
});
134+
translator.translate();
135+
Zotero.done();
136+
});
137+
});
138+
});
139+
140+
Zotero.wait();
141+
}

ACM.js

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"translatorID":"e78d20f7-488-4023-831-dfe39679f3f",
3+
"translatorType":4,
4+
"label":"ACM",
5+
"creator":"Simon Kornblith and Michael Berkowitz",
6+
"target":"https?://[^/]*portal\\.acm\\.org[^/]*/(?:results\\.cfm|citation\\.cfm)",
7+
"minVersion":"1.0.0b3.r1",
8+
"maxVersion":"",
9+
"priority":100,
10+
"inRepository":true,
11+
"lastUpdated":"2008-06-06 08:45:00"
12+
}
13+
14+
function detectWeb(doc, url) {
15+
if(url.indexOf("/results.cfm") != -1) {
16+
var items = Zotero.Utilities.getItemArray(doc, doc, '^https?://[^/]+/citation.cfm\\?[^#]+$');
17+
// hack to return multiple if there are items
18+
for(var i in items) {
19+
return "multiple";
20+
}
21+
} else {
22+
var onClick = doc.evaluate('//a[substring(text(), 5, 7) = "EndNote"]', doc, null, XPathResult.ANY_TYPE,
23+
null).iterateNext().getAttribute("onClick");
24+
if(onClick.match("proceeding.article")) {
25+
return "conferencePaper";
26+
} else {
27+
return "journalArticle";
28+
}
29+
}
30+
}
31+
32+
var urls = new Array();
33+
34+
// this handles sequential loading, since first we need to process a document (to get the abstract), then
35+
// get the Refer metadata, then process the next document, etc.
36+
function getNext() {
37+
if(urls.length) {
38+
var url = urls.shift();
39+
Zotero.Utilities.processDocuments([url], function(doc) { scrape(doc); });
40+
} else {
41+
Zotero.done();
42+
}
43+
}
44+
45+
function scrape(doc) {
46+
var onClick = doc.evaluate('//a[substring(text(), 5, 7) = "EndNote"]', doc, null, XPathResult.ANY_TYPE,
47+
null).iterateNext().getAttribute("onClick");
48+
var m = onClick.match(/'([^']+)'/);
49+
50+
if (doc.evaluate('//div[@class="abstract"]/p[@class="abstract"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
51+
var abstract = doc.evaluate('//div[@class="abstract"]/p[@class="abstract"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext();
52+
if (!abstract.textContent.match(/\w+/)) {
53+
var abstract = doc.evaluate('//div[@class="abstract"]/p[2]', doc, null, XPathResult.ANY_TYPE, null).iterateNext();
54+
}
55+
if(abstract) abstract = Zotero.Utilities.cleanString(abstract.textContent);
56+
}
57+
var snapshot = doc.location.href;
58+
59+
var attachments = new Array();
60+
var url;
61+
var typeLinks = doc.evaluate('//td[@class="smaller-text"]/a[img]', doc, null,
62+
XPathResult.ANY_TYPE, null);
63+
var typeLink;
64+
while(typeLink = typeLinks.iterateNext()) {
65+
var linkText = typeLink.textContent.toLowerCase();
66+
if(linkText == "pdf") {
67+
attachments.push({title:"ACM Full Text PDF", mimeType:"application/pdf", url:typeLink.href});
68+
url = typeLink.href;
69+
} else if(linkText == "html") {
70+
url = snapshot = typeLink.href;
71+
}
72+
}
73+
74+
attachments.push({title:"ACM Snapshot", mimeType:"text/html", url:snapshot});
75+
76+
var keywords = new Array();
77+
var keywordLinks = doc.evaluate('//p[@class="keywords"]/a', doc, null,
78+
XPathResult.ANY_TYPE, null);
79+
var keywordLink;
80+
while(keywordLink = keywordLinks.iterateNext()) {
81+
keywords.push(Zotero.Utilities.trimInternal(keywordLink.textContent.toLowerCase()));
82+
}
83+
var doi = "";
84+
var doiElmt = doc.evaluate('/html/body/div/table/tbody/tr[4]/td/table/tbody/tr/td/table/tbody/tr[3]/td[2][@class="small-text"]/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()
85+
if (doiElmt){
86+
var match = doiElmt.textContent.match(/org\/(.*)/);
87+
if (match){
88+
doi = match[1];
89+
}
90+
}
91+
92+
Zotero.Utilities.HTTP.doGet("http://portal.acm.org/"+m[1], function(text) {
93+
// split() may no longer be necessary
94+
var m = text.split(/<\/?pre[^>]*>/ig);
95+
if (m[1]) {
96+
var text = m[1];
97+
}
98+
// unescape HTML for extended characters
99+
function unescapeHTML(str, p1){
100+
return Zotero.Utilities.unescapeHTML("&#"+p1);
101+
}
102+
text = text.replace(/\\&\\#([^;]+;)/g, unescapeHTML);
103+
// load Refer translator
104+
var translator = Zotero.loadTranslator("import");
105+
translator.setTranslator("881f60f2-0802-411a-9228-ce5f47b64c7d");
106+
translator.setString(text);
107+
translator.setHandler("itemDone", function(obj, item) {
108+
if(abstract) item.abstractNote = abstract;
109+
item.attachments = attachments;
110+
item.tags = keywords;
111+
item.DOI = doi;
112+
item.url = doc.location.href;
113+
item.complete();
114+
});
115+
translator.translate();
116+
117+
getNext();
118+
});
119+
}
120+
121+
function doWeb(doc, url) {
122+
if(url.indexOf("/results.cfm") != -1) {
123+
var items = Zotero.Utilities.getItemArray(doc, doc, '^https?://[^/]+/citation.cfm\\?[^#]+$');
124+
125+
items = Zotero.selectItems(items);
126+
if(!items) return true;
127+
128+
for(var url in items) {
129+
urls.push(url);
130+
}
131+
132+
getNext();
133+
} else {
134+
scrape(doc);
135+
}
136+
137+
Zotero.wait();
138+
}

0 commit comments

Comments
 (0)