forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chadwyck Literature Online.js
245 lines (232 loc) · 7.77 KB
/
Chadwyck Literature 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{
"translatorID": "e13b0f9d-44ba-4ece-aa22-77993bb26ef2",
"label": "Chadwyck Literature Online",
"creator": "Sebastian Karcher",
"target": "^https?://(lion|collections)\\.chadwyck\\.com/search",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsib",
"lastUpdated": "2014-03-31 15:22:07"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2013 Sebastian Karcher
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
//this may not always get the right item type, but doing that may neither be possible nor terribly important.
if (url.indexOf("searchFullrec.do?")!=-1||url.indexOf("searchFulltext.do?")!=-1){
if(ZU.xpathText(doc, '//a[@class="bold" and contains(text(), "Download citation")]/@href')) return "journalArticle";
}
//I think these are all possible search results - not sure, though, may need to add
if (url.indexOf("searchQuick")!=-1||url.indexOf("searchTexts") != -1) return "multiple";
}
function doWeb(doc, url){
if(detectWeb(doc, url) == "multiple") {
var results = ZU.xpath(doc, '//tr/td/a[contains(@href, "/searchFull") and not(contains(@href, "area=authors"))]|//dl/a[contains(@href, "/searchFull")]')
var hits = {};
var urls = [];
for (var i in results) {
hits[results[i].href] = results[i].textContent.trim();
}
Zotero.selectItems(hits, function (items) {
if (!items) {
return true;
}
for (var i in items) {
urls.push(i);
}
ZU.processDocuments(urls, scrape)
});
} else {
scrape(doc, url);
}
}
function scrape(doc, url){
var id = url.match(/id=[^&]+/);
var downloadurl = ZU.xpathText(doc, '//a[@class="bold" and contains(text(), "Download citation")]/@href')
if (id) id = id[0]; else id = downloadurl.match(/id=[^&]+/)[0];
var area = url.match(/area=([^&]+)/)[1];
var carea = area.toLowerCase();
var host = doc.location.host ? "http://" + doc.location.host : url.match(/https?:\/\/[^\/]+/)[0]
var risurl = "http://" + doc.location.host + "/downloadCitation.do?" + id + "&area=" + area + "&citationArea=" + carea + "&citationFormat=procite&citationExport=direct";
fetchRIS(risurl, downloadurl, 1)
}
function fetchRIS(risurl, downloadurl, retry){
Zotero.Utilities.HTTP.doGet(risurl, function (text) {
//Z.debug("RIS: " + text)
var foundRIS = (text.indexOf('TY - ') != -1);
//Cookie weirdness - on some, but not all pages, this requires a cookie set by loading the citation page.
//That's what we do when the first try fails (modeled after APA Psycnet)
if(!foundRIS && retry) {
//retry after accessing citation download page
Z.debug('No RIS data. Retrying (' + retry + ').');
ZU.doGet(downloadurl, function(){fetchRIS(risurl, --retry);});
return;
}
else if (!foundRIS){
throw("Can't find RIS data");
return;
}
var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
translator.setHandler("itemDone", function(obj, item) {
//We're using the permalink for the snapshot so users can quickly go to the item online, which may contain links to images of the work
//which are impossible to scrape
item.attachments = [
{url:item.url, title: "Chadwyck Literature Online Snapshot", mimeType: "text/html"}
];
item.url ="";
//remove role description put into author first names
for (i in item.creators){
if (item.creators[i].firstName){
item.creators[i].firstName = item.creators[i].firstName.replace(/\(.+/, "");
}
}
//put copyright notes into rights field and delete. Delete generic Chadwyck Healey note
var rights = "";
for (var i = item.notes.length-1; i >= 0; i--){
if (item.notes[i].note.match(/Copyright/)){
rights += item.notes[i].note;
item.notes.splice(i, 1);
}
else if (item.notes[i].note.match(/Chadwyck\-Healey/)){
item.notes.splice(i, 1);
}
}
if (rights) item.rights = rights.replace(/<\/?p>/g, " ");
//fix all caps titles
if (item.title == item.title.toUpperCase()){
item.title = ZU.capitalizeTitle(item.title.toLowerCase(), true);
}
item.series = ""; //T3 contains meaningless info like "Literature online
item.complete();
});
translator.translate();
});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://lion.chadwyck.com/searchQuickPhase1.do?QuickSearchField=borges",
"items": "multiple"
},
{
"type": "web",
"url": "http://lion.chadwyck.com/searchFulltext.do?id=R04701895&divLevel=0&area=abell&DurUrl=Yes&forward=critref_ft",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Yamashita",
"firstName": "Karen Tei",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "Chadwyck Literature Online Snapshot",
"mimeType": "text/html"
}
],
"title": "Borges & I",
"publicationTitle": "Massachusetts Review: a quarterly of literature, the arts, and public affairs",
"journalAbbreviation": "Massachusetts Review: a quarterly of literature, the arts, and public affairs",
"date": "Summer 2012",
"volume": "53",
"issue": "2",
"pages": "209",
"rights": "Copyright © 1996-2009 ProQuest LLC. All Rights Reserved.",
"libraryCatalog": "Chadwyck Literature Online"
}
]
},
{
"type": "web",
"url": "http://lion.chadwyck.com/searchFullrec.do?id=R04673959&area=abell&forward=critref_fr&DurUrl=Yes",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Borges",
"firstName": "Jorge Luis",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "Chadwyck Literature Online Snapshot",
"mimeType": "text/html"
}
],
"title": "Music Box",
"publicationTitle": "Poetry (New York; Chicago)",
"journalAbbreviation": "Poetry (New York; Chicago)",
"date": "2012",
"volume": "199",
"issue": "6",
"pages": "536",
"ISSN": "00322032",
"rights": "Copyright © 1996-2009 ProQuest LLC. All Rights Reserved.",
"libraryCatalog": "Chadwyck Literature Online"
}
]
},
{
"type": "web",
"url": "http://collections.chadwyck.com/searchFullrec.do?id=R04919506&area=abell&forward=critref_fr&DurUrl=Yes",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Connolly",
"firstName": "Andy",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "Chadwyck Literature Online Snapshot",
"mimeType": "text/html"
}
],
"title": "'the agitation of the autobiographical': national politics and aesthetic autonomy in Philip Roth's Exit Ghost.",
"publicationTitle": "Journal of American Studies",
"journalAbbreviation": "Journal of American Studies",
"date": "2013",
"pages": "637",
"rights": "Copyright © 1996-2010 ProQuest LLC. All Rights Reserved.",
"libraryCatalog": "Chadwyck Literature Online",
"shortTitle": "'the agitation of the autobiographical'"
}
]
}
]
/** END TEST CASES **/