forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
A Contra Corriente.js
148 lines (134 loc) · 5.06 KB
/
A Contra Corriente.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
{
"translatorID": "bbf1617b-d836-4665-9aae-45f223264460",
"label": "A Contra Corriente",
"creator": "Sebastian Karcher",
"target": "^https?://tools\\.chass\\.ncsu\\.edu/open_journal/index\\.php/acontracorriente/",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsb",
"lastUpdated": "2012-03-23 04:26:44"
}
/*
A Contra Corriente Translator
Copyright (C) 2012 Sebastian Karcher and Avram Lyon
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affer General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affer General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function detectWeb(doc, url) {
var xpath = '//meta[@name="citation_journal_title"]';
if (ZU.xpath(doc, xpath).length > 0) {
return "journalArticle";
}
if (url.match(/issue\/view|search\/results/)) {
return "multiple";
}
return false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
var hits = {};
var urls = [];
//distinguish between search results and ToCs, which require different logic
if (url.match(/search\/results/)) {
var rows = ZU.xpath(doc, "//table[@class='listing']//tr[@valign='top']");
if (!rows || rows.length == 0) results = ZU.xpath(doc, "//form[@name='search']/table[3]/tbody/tr/td[2]/a[@class='hiddenlink']");
for (var i in rows) {
var titles = ZU.xpathText(rows[i], './td[2]');
var URL = ZU.xpathText(rows[i], './td[3]/a/@href');
hits[URL] = titles;
}
} else {
var results = ZU.xpath(doc, "//td[@class='tocTitle']/a");
for (var i in results) {
hits[results[i].href] = results[i].textContent;
}
}
//Z.debug(hits);
Z.selectItems(hits, function (items) {
if (items == null) return true;
for (var j in items) {
urls.push(j);
}
ZU.processDocuments(urls, function (myDoc) {
doWeb(myDoc, myDoc.location.href)
}, function () {
Z.done()
});
Z.wait();
});
} else {
// We call the Embedded Metadata translator to do the actual work
var translator = Zotero.loadTranslator("import");
translator.setTranslator("951c027d-74ac-47d4-a107-9c3069ab7b48");
translator.setHandler("itemDone", function (obj, item) {
item.abstractNote = item.extra;
item.extra = '';
item.rights = '';
item.complete();
});
translator.getTranslatorObject(function (obj) {
obj.doWeb(doc, url);
});
}
}
/** BEGIN TEST CASES **/
var testCases = [{
"type": "web",
"url": "http://tools.chass.ncsu.edu/open_journal/index.php/acontracorriente/article/view/102",
"items": [{
"itemType": "journalArticle",
"creators": [{
"firstName": "José Luis",
"lastName": "Rénique",
"creatorType": "author"
}],
"notes": [],
"tags": ["Carlos Iván degregori", "historia", "Perú"],
"seeAlso": [],
"attachments": [{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}, {
"title": "Snapshot"
}],
"itemID": "http://tools.chass.ncsu.edu/open_journal/index.php/acontracorriente/article/view/102",
"title": "Carlos Iván Degregori: antropólogo del alma",
"publicationTitle": "A Contracorriente",
"date": "02/06/2011",
"reportType": "Text.Serial.Journal",
"letterType": "Text.Serial.Journal",
"manuscriptType": "Text.Serial.Journal",
"mapType": "Text.Serial.Journal",
"thesisType": "Text.Serial.Journal",
"websiteType": "Text.Serial.Journal",
"presentationType": "Text.Serial.Journal",
"postType": "Text.Serial.Journal",
"audioFileType": "Text.Serial.Journal",
"language": "en",
"volume": "8",
"issue": "3",
"pages": "i-vii",
"ISSN": "1548-7083",
"url": "http://tools.chass.ncsu.edu/open_journal/index.php/acontracorriente/article/view/102",
"accessDate": "CURRENT_TIMESTAMP",
"libraryCatalog": "tools.chass.ncsu.edu",
"abstractNote": "Remembranza de la reciente muerte (18 de Mayo de 2011) en Lima de Carlos Iván Degregori, uno de los intelectuales peruanos más importantes de las últimas décadas y uno de los estudiosos internacionales más destacados de la violencia política. A Contracorriente se suma a los innumerables homenajes que se tributan a su memoria. Su colega y amigo a lo largo de muchos años, el historiador José Luis Rénique, traza en esta nota el perfil humano, intelectual y político de Degregori. Al final incluimos también una lista de sus principales publicaciones.",
"shortTitle": "Carlos Iván Degregori"
}]
}, {
"type": "web",
"url": "http://tools.chass.ncsu.edu/open_journal/index.php/acontracorriente/issue/view/16/showToc",
"items": "multiple"
}]
/** END TEST CASES **/