forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cambridge Journals Online.js
187 lines (181 loc) · 8.73 KB
/
Cambridge Journals Online.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
"translatorID": "850f4c5f-71fb-4669-b7da-7fb7a95500ef",
"label": "Cambridge Journals Online",
"creator": "Sean Takats, Michael Berkowitz and Avram Lyon",
"target": "^https?://[^/]*journals.cambridge.org[^/]*//?action/(quickSearch|search|displayAbstract|displayFulltext|displayIssue)",
"minVersion": "2.1",
"maxVersion": "",
"priority": 100,
"browserSupport": "gcsib",
"inRepository": true,
"translatorType": 4,
"lastUpdated": "2011-08-22 22:29:49"
}
function detectWeb(doc, url) {
var namespace=doc.documentElement.namespaceURI;
var nsResolver=namespace?function(prefix) {
return (prefix=="x")?namespace:null;
}:null;
var xpath = '//div[@class="tableofcontents-row"][div/input[@type="checkbox"][@name="toView"]]';
if ((url.indexOf("/action/displayAbstract") != -1) || (url.indexOf("action/displayFulltext") != -1)){
return "journalArticle";
} else if (doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
return "multiple";
}
}
function doWeb(doc, url){
var namespace=doc.documentElement.namespaceURI;
var nsResolver=namespace?function(prefix) {
return (prefix=="x")?namespace:null;
}:null;
var host = doc.location.host;
var urlstring="http://" + host + "/action/exportCitation";
var datastring="format=RIS&emailId=&Download=Download&componentIds=";
var links = new Array();
if(detectWeb(doc, url) == "multiple"){
var xpath = '//div[@class="tableofcontents-row"][div/input[@type="checkbox"][@name="toView"]]';
var tableRows = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
var tableRow;
var items=new Array();
while (tableRow = tableRows.iterateNext()){
var id = doc.evaluate('./div/input[@type="checkbox"][@name="toView"]/@value', tableRow, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
var title = doc.evaluate('.//h3', tableRow, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
items['http://' + host + '/action/displayAbstract?aid=' + id.nodeValue] = Zotero.Utilities.capitalizeTitle(title.textContent);
}
Zotero.selectItems(items, function(items) {
for (var i in items) {
links.push(i);
}
Zotero.Utilities.processDocuments(links, scrape,
function() {Zotero.done();});
});
} else {
scrape(doc);
}
Zotero.wait();
}
function scrape (doc) {
var namespace=doc.documentElement.namespaceURI;
var nsResolver=namespace?function(prefix) {
return (prefix=="x")?namespace:null;
}:null;
var host = doc.location.host;
var urlstring="http://" + host + "/action/exportCitation";
var datastring="format=RIS&emailId=&Download=Download&componentIds=";
var locURL = doc.location.href;
var abs;
if (abs = doc.evaluate('//p[@class="section-title" and contains(text(),"Abstract")]/following-sibling::p[not(@class) and text() != ""]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
abs = abs.textContent;
}
if (doc.evaluate('//p[@class="KeyWords"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
var kws = doc.evaluate('//p[@class="KeyWords"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent.substr(11).split('; ');
}
var pdfpath='//div/ul/li/a[contains(text(), "PDF")]';
if (doc.evaluate(pdfpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
var pdflink = doc.evaluate(pdfpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
}
idRe = /aid=([0-9]+)/
var m = idRe.exec(locURL);
var id = m[1];
Zotero.Utilities.doGet(urlstring + "?" + datastring+id, function(text) {
text = text.replace(/(^|\n)?([A-Z\d]{2})\s+\-\s+(\n)?/g, "\n$2 - $3");
var translator = Zotero.loadTranslator("import");
// Use RIS importer
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
translator.setHandler("itemDone", function(obj, item) {
item.attachments = [{url:locURL,
title:"Cambridge Journals Snapshot",
mimeType:"text/html"}];
item.title = Zotero.Utilities.capitalizeTitle(item.title);
var authors = item.creators;
item.creators = new Array();
for each (var aut in authors) {
// correct all-caps, if present
if (aut.firstName && aut.firstName.toUpperCase() == aut.firstName)
aut.firstName=Zotero.Utilities.capitalizeTitle(aut.firstName.toLowerCase(),true);
if (aut.lastName && aut.lastName.toUpperCase() == aut.lastName)
aut.lastName=Zotero.Utilities.capitalizeTitle(aut.lastName.toLowerCase(),true);
item.creators.push({firstName:aut.firstName,
lastName:aut.lastName,
creatorType:"author"});
}
if (item.tags.length === 1) item.tags = item.tags[0].split(",");
if (abs) item.abstractNote = Zotero.Utilities.trimInternal(abs);
if (pdflink) {
// Some PDFs aren't paywalled, so they don't need the 2nd request
item.attachments.push({
url: pdflink,
title: "Cambridge Journals PDF",
mimeType:"application/pdf"
});
Zotero.Utilities.doGet(pdflink, function(text) {
var domain = pdflink.match(/^https?:\/\/[^\/]+\//);
var realpdf = text.match(/<iframe src="\/(action\/displayFulltext[^"]+)"/);
if (realpdf && domain) {
// If we matched the IFRAME, the first attachment must be bad
for (var i in item.attachments) {
if (item.attachments[i].mimeType.indexOf("pdf") !== -1)
item.attachments[i].url = (domain[0]+realpdf[1]).replace(/&/g,"&");
};
}
}, function () {
item.complete();
});
} else {
item.complete();
}
});
translator.translate();
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://journals.cambridge.org/action/quickSearch?quickSearchType=search_combined&inputField1=tatar&fieldStartMonth=01&fieldStartYear=1800&fieldEndMonth=12&fieldEndYear=2011&searchType=ADVANCESEARCH&searchTypeFrom=quickSearch&fieldScjrnl=All&fieldSccats=All&selectField1=%23&jnlId=AMS&issId=02&volId=45&journalSearchType=all",
"items": "multiple"
},
{
"type": "web",
"url": "http://journals.cambridge.org/action/displayAbstract?fromPage=online&aid=8267699&fulltextType=RA&fileId=S0021875810001738",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"firstName": "Laurie A.",
"lastName": "Rodrigues",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"url": false,
"title": "Cambridge Journals Snapshot",
"mimeType": "text/html"
},
{
"url": false,
"title":"Cambridge Journals PDF",
"mimeType":"application/pdf"
}
],
"date": "2011",
"title": "“SAMO© as an Escape Clause”: Jean-Michel Basquiat's Engagement with a Commodified American Africanism",
"publicationTitle": "Journal of American Studies",
"pages": "227-243",
"volume": "45",
"issue": "02",
"DOI": "10.1017/S0021875810001738",
"abstractNote": "Heir to the racist configuration of the American art exchange and the delimiting appraisals of blackness in the American mainstream media, Jean-Michel Basquiat appeared on the late 1970s New York City street art scene – then he called himself “SAMO.” Not long thereafter, Basquiat grew into one of the most influential artists of an international movement that began around 1980, marked by a return to figurative painting. Given its rough, seemingly untrained and extreme, conceptual nature, Basquiat's high-art oeuvre might not look so sophisticated to the uninformed viewer. However, Basquiat's work reveals a powerful poetic and visual gift, “heady enough to confound academics and hip enough to capture the attention span of the hip hop nation,” as Greg Tate has remarked. As noted by Richard Marshall, Basquiat's aesthetic strength actually comes from his striving “to achieve a balance between the visual and intellectual attributes” of his artwork. Like Marshall, Tate, and others, I will connect with Basquiat's unique, self-reflexively experimental visual practices of signifying and examine anew Basquiat's active contribution to his self-alienation, as Hebdige has called it. Basquiat's aesthetic makes of his paintings economies of accumulation, building a productive play of contingency from the mainstream's constructions of race. This aesthetic move speaks to a need for escape from the perceived epistemic necessities of blackness. Through these economies of accumulation we see, as Tate has pointed out, Basquiat's “intellectual obsession” with issues such as ancestry/modernity, personhood/property and originality/origins of knowledge, driven by his tireless need to problematize mainstream media's discourses surrounding race – in other words, a commodified American Africanism.",
"libraryCatalog": "Cambridge Journals Online",
"shortTitle": "“SAMO© as an Escape Clause”"
}
]
}
]
/** END TEST CASES **/