forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighwire 2.0.js
316 lines (303 loc) · 12.1 KB
/
Highwire 2.0.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
{
"translatorID": "8c1f42d5-02fa-437b-b2b2-73afc768eb07",
"label": "Highwire 2.0",
"creator": "Matt Burton",
"target": "(content/([0-9]+/[0-9]+|current|firstcite|early)|search\\?submit=|search\\?fulltext=|cgi/collection/.+)",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsib",
"lastUpdated": "2011-09-20 20:17:54"
}
/*
Translator for several Highwire journals. Example URLs:
1. Ajay Agrawal, Iain Cockburn, and John McHale, “Gone but not forgotten: knowledge flows, labor mobility, and enduring social relationships,” Journal of Economic Geography 6, no. 5 (November 2006): 571-591.
http://joeg.oxfordjournals.org/content/6/5/571 :
2. Gordon L. Clark, Roberto Durán-Fernández, and Kendra Strauss, “‘Being in the market’: the UK house-price bubble and the intended structure of individual pension investment portfolios,” Journal of Economic Geography 10, no. 3 (May 2010): 331-359.
http://joeg.oxfordjournals.org/content/10/3/331.abstract
3. Hans Maes, “Intention, Interpretation, and Contemporary Visual Art,” Brit J Aesthetics 50, no. 2 (April 1, 2010): 121-138.
http://bjaesthetics.oxfordjournals.org/cgi/content/abstract/50/2/121
4. M L Giger et al., “Pulmonary nodules: computer-aided detection in digital chest images.,” Radiographics 10, no. 1 (January 1990): 41-51.
http://radiographics.rsna.org/content/10/1/41.abstract
5. Mitch Leslie, "CLIP catches enzymes in the act," The Journal of Cell Biology 191, no. 1 (October 4, 2010): 2.
http://jcb.rupress.org/content/191/1/2.2.short
*/
function detectWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var highwiretest = false;
highwiretest = url.match(/\.pdf+html\?frame=header/);
if (!highwiretest) {
// lets hope this installations don't tweak this...
highwiretest = doc.evaluate("//link[@href = '/shared/css/hw-global.css']", doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
}
if(highwiretest) {
if (
url.match("search\\?submit=") ||
url.match("search\\?fulltext=") ||
url.match("content/by/section") ||
doc.title.match("Table of Contents") ||
doc.title.match("Early Edition") ||
url.match("cgi/collection/.+") ||
url.match("content/firstcite")
) {
return "multiple";
} else if (url.match("content/(early/)?[0-9]+")) {
return "journalArticle";
}
}
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
if (!url) url = doc.documentElement.location;
else if (url.match(/\?frame=header/)) {
// recall all this using new url
url = url.replace(/\?.*/,"?frame=sidebar");
Zotero.Utilities.processDocuments(url,
function(newdoc) {
doWeb(newdoc, url);
}, function() {Zotero.done()});
Zotero.wait();
return true;
}
var host = doc.location.protocol+'//' + doc.location.host + "/";
var arts = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
if (doc.title.match("Table of Contents")
|| doc.title.match("Early Edition")
|| url.match("content/firstcite")) {
var searchx = '//li[contains(@class, "toc-cit") and not(ancestor::div/h2/a/text() = "Correction" or ancestor::div/h2/a/text() = "Corrections")]';
var titlex = './/h4';
} else if (url.match("content/by/section") || url.match("cgi/collection/.+")) {
var searchx = '//li[contains(@class, "results-cit cit")]';
var titlex = './/span[contains(@class, "cit-title")]';
}
else {
var searchx = '//div[contains(@class,"results-cit cit")]';
var titlex = './/span[contains(@class,"cit-title")]';
}
var linkx = './/a[1]';
var searchres = doc.evaluate(searchx, doc, nsResolver, XPathResult.ANY_TYPE, null);
var next_res, title, link;
while (next_res = searchres.iterateNext()) {
title = doc.evaluate(titlex, next_res, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
link = doc.evaluate(linkx, next_res, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
items[link] = title;
}
items = Zotero.selectItems(items);
for (var i in items) {
arts.push(i);
}
} else {
arts = [url];
}
var newurls = new Array();
for each (var i in arts) {
newurls.push(i);
}
if(arts.length == 0) {
Zotero.debug('no items');
return false;
}
Zotero.Utilities.HTTP.doGet(arts, function(text) {
var id, match, newurl, pdfurl, get;
/* Here, we have to use three phrasings because they all occur, depending on
the journal.
TODO We should rewrite this to not use regex! */
match = text.match(/=([^=]+)\">\s*Download (C|c)itation/);
if (!match || match.length < 1) {
match = text.match(/=([^=]+)\">\s*Download to citation manager/);
if (!match || match.length < 1) {
// Journal of Cell Biology
match = text.match(/=([^=]+)\">\s*Add to Citation Manager/);
if (!match || match.length < 1) {
/* apparently we can get frames */
/* but they have the ID too! */
Z.debug("Attempting to fetch ID from frameset");
match = text.match(/<meta content="([^"]+)"\s*name="citation_mjid"\s*\/>/);
}
}
}
id = match[1];
newurl = newurls.shift();
if (newurl.match("cgi/content")) {
pdfurl = newurl.replace(/cgi\/content\/abstract/, "content") + ".full.pdf";
// This is here to catch those pdf+html pages
} else if (newurl.match("\.full\.pdf")) {
pdfurl = newurl.slice(0, newurl.lastIndexOf(".full.pdf")) + ".full.pdf";
} else {
// This is not ideal...todo: brew a regex that grabs the correct URL
pdfurl = newurl.slice(0, newurl.lastIndexOf(".")) + ".full.pdf";
}
get = host + 'citmgr?type=refman&gca=' + id;
Zotero.Utilities.HTTP.doGet(get, function(text) {
var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
// Sometimes Highwire 2.0 has blank entries for N1
if (text.match(/N1\s+\-\s+(10\..*)\n/)) {
var doi = text.match(/N1\s+\-\s+(.*)\n/)[1];
}
translator.setHandler("itemDone", function(obj, item) {
item.attachments = [
{url:newurl, title:"Snapshot", mimeType:"text/html"},
{url:pdfurl, title:"Full Text PDF", mimeType:"application/pdf"}
];
if (doi) item.DOI = doi;
if (item.notes) item.notes = [];
item.complete();
});
translator.translate();
});
});
Zotero.wait();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://rer.sagepub.com/content/52/2/201.abstract",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Hofstein",
"firstName": "Avi",
"creatorType": "author"
},
{
"lastName": "Lunetta",
"firstName": "Vincent N.",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"url": false,
"title": "Snapshot",
"mimeType": "text/html"
},
{
"url": false,
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"title": "The Role of the Laboratory in Science Teaching: Neglected Aspects of Research",
"date": "Summer 1982",
"publicationTitle": "Review of Educational Research",
"pages": "201 -217",
"volume": "52",
"issue": "2",
"url": "http://rer.sagepub.com/content/52/2/201.abstract",
"abstractNote": "The laboratory has been given a central and distinctive role in science education, and science educators have suggested that there are rich benefits in learning from using laboratory activities. At this time, however, some educators have begun to question seriously the effectiveness and the role of laboratory work, and the case for laboratory teaching is not as self-evident as it once seemed. This paper provides perspectives on these issues through a review of the history, goals, and research findings regarding the laboratory as a medium of instruction in introductory science teaching. The analysis of research culminates with suggestions for researchers who are working to clarify the role of the laboratory in science education.",
"DOI": "10.3102/00346543052002201",
"libraryCatalog": "Highwire 2.0",
"shortTitle": "The Role of the Laboratory in Science Teaching"
}
]
},
{
"type": "web",
"url": "http://sag.sagepub.com/content/early/2010/04/23/1046878110366277.abstract",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Owens",
"firstName": "Trevor",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"url": false,
"title": "Snapshot",
"mimeType": "text/html"
},
{
"url": false,
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"title": "Modding the History of Science: Values at Play in Modder Discussions of Sid Meier’s CIVILIZATION",
"date": "May 27 , 2010",
"publicationTitle": "Simulation & Gaming",
"url": "http://sag.sagepub.com/content/early/2010/04/23/1046878110366277.abstract",
"abstractNote": "Sid Meier’s CIVILIZATION has been promoted as an educational tool, used as a platform for building educational simulations, and maligned as promoting Eurocentrism, bioimperialism, and racial superiority. This article explores the complex issues involved in interpreting a game through analysis of the ways modders (gamers who modify the game) have approached the history of science, technology, and knowledge embodied in the game. Through text analysis of modder discussion, this article explores the assumed values and tone of the community’s discourse. The study offers initial findings that CIVILIZATION modders value a variety of positive discursive practices for developing historical models. Community members value a form of historical authenticity, they prize subtlety and nuance in models for science in the game, and they communicate through civil consensus building. Game theorists, players, and scholars, as well as those interested in modeling the history, sociology, and philosophy of science, will be interested to see the ways in which CIVILIZATION III cultivates an audience of modders who spend their time reimagining how science and technology could work in the game.",
"DOI": "10.1177/1046878110366277",
"libraryCatalog": "Highwire 2.0",
"shortTitle": "Modding the History of Science"
}
]
},
{
"type": "web",
"url": "http://scx.sagepub.com/content/30/2/277.abstract",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Mulder",
"firstName": "Henk A. J.",
"creatorType": "author"
},
{
"lastName": "Longnecker",
"firstName": "Nancy",
"creatorType": "author"
},
{
"lastName": "Davis",
"firstName": "Lloyd S.",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"url": false,
"title": "Snapshot",
"mimeType": "text/html"
},
{
"url": false,
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"title": "The State of Science Communication Programs at Universities Around the World",
"date": "December 01 , 2008",
"publicationTitle": "Science Communication",
"pages": "277 -287",
"volume": "30",
"issue": "2",
"url": "http://scx.sagepub.com/content/30/2/277.abstract",
"abstractNote": "Building on discussions at two workshops held at the recent 10th International Conference on the Public Communication of Science and Technology during June 2008 in Malmö, Sweden, this article proposes specific steps toward achieving a common understanding of the essential elements for academic programs in science communication. About 40 academics, science communication professionals, and students from at least 16 countries participated in this process.",
"DOI": "10.1177/1075547008324878",
"libraryCatalog": "Highwire 2.0"
}
]
}
]
/** END TEST CASES **/