forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISTC.js
181 lines (157 loc) · 5.63 KB
/
ISTC.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
{
"translatorID": "29051e64-8eba-4b26-bbf1-0c224bc59497",
"label": "ISTC",
"creator": "Maike Kittelmann",
"target": "^https?://data\\.cerl\\.org/istc/(_search|i[a-z]\\d{8})",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2016-12-28 14:39:45"
}
/*
***** BEGIN LICENSE BLOCK *****
RKE Web translator Copyright © 2016 Maike Kittelmann
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) {
if (url.indexOf('_search?') != -1 && getSearchResults(doc, true, url)) {
return "multiple";
} else if (url.search(/i[a-z]\d{8}/) != -1) {
var title = ZU.trimInternal(ZU.xpath(doc, '//div[contains(@class, "ample-record")]/h3')[0].textContent);
if (title) {
return 'book';
}
}
}
function getSearchResults(doc, checkOnly, url) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//p[contains(@class, "ample-shortlist-item-entry")]/a[contains(@href, "/istc/i")]');
for (i = 0; i < rows.length; i++) {
var title = ZU.trimInternal(rows[i].textContent);
var href = rows[i].href + '?format=json';
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false, url), function(items) {
if (!items) {
return true;
}
var books = [];
for (var i in items) {
books.push(i);
}
ZU.doGet(Object.keys(items), scrape);
});
} else if (detectWeb(doc, url) == "book") {
ZU.doGet(url + '?format=json', scrape);
}
}
function scrape(response, obj, url) {
var jsonObject = JSON.parse(response);
var data = jsonObject.data;
var item = new Zotero.Item('book');
var name = data.author;
item.creators.push(Zotero.Utilities.cleanAuthor(name, "author", true))
item.title = data.title;
item.url = url.replace('?format=json', '');
var imprint = data.imprint[0];
item.place = (imprint.imprint_place || '');
item.publisher = (imprint.imprint_name || '');
item.date = (imprint.imprint_date || '');
if (data.notes) {
item.notes.push(data.notes[0]);
}
if (imprint.geo_info && imprint.geo_info[0].geonames_id) {
item.notes.push('Geonames identifier of printing place: ' + imprint.geo_info[0].geonames_id);
}
if (data.references) {
var concatRef = '';
for (var i in data.references) {
var ref = data.references[i];
var refName = (ref.reference_name || '');
var refLoc = (ref.reference_location_in_source || '');
concatRef += (refName + ' ' + refLoc + '; ');
}
concatRef = concatRef.replace(/; $/, '');
item.notes.push('References: ' + concatRef);
}
item.callNumber = 'ISTC ' + jsonObject._id;
item.language = (data.language_of_item || '');
item.libraryCatalog = 'Incunabula Short Title Catalogue (ISTC)';
item.tags = ['incunabula', 'istc'];
item.accessed = new Date().toString();
// // Uncomment the following if you always want to save the page as attachment:
// item.attachments = [{
// url: url.replace('?format=json', ''),
// title: "ISTC",
// mimeType: "text/html",
// snapshot: true
// }];
item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://data.cerl.org/istc/if00117000",
"items": [
{
"itemType": "book",
"title": "Propositiones ex omnibus Aristotelis libris excerptae. Add: Benedictus Soncinas",
"creators": [
{
"firstName": "Theophilus de",
"lastName": "Ferrariis",
"creatorType": "author"
}
],
"date": "3 Aug. 1493",
"callNumber": "ISTC if00117000",
"language": "lat",
"libraryCatalog": "Incunabula Short Title Catalogue (ISTC)",
"place": "Venice",
"publisher": "Johannes and Gregorius de Gregoriis, de Forlivio, for Alexander Calcedonius",
"shortTitle": "Propositiones ex omnibus Aristotelis libris excerptae. Add",
"url": "http://data.cerl.org/istc/if00117000",
"attachments": [],
"tags": [
"incunabula",
"istc"
],
"notes": [
"Contains extracts from Latin translations of Aristotle by Leonardus Brunus Aretinus, etc. The translation of De mirabilibus auscultationibus by Antonius Beccaria is given entire (ff.113-128v)",
"Geonames identifier of printing place: 3164603",
"References: Goff F117; HC(+Add) 6997* ; Klebs 395.1; Pell 4777; Buffévent 199; Fernillot 239; Parguez 426; Zehnacker 878; Polain(B) 1475; IGI 3840; IBP 2172; IBPort 705; IBE 2419; SI 1519; CCIR F-6; IJL2 170; Badalić(Croatia) 444; Madsen 1571; Mendes 524; Martín Abad F-17; Sallander 1716; Coll(S) 1233; Sack(Freiburg) 1426; Hubay(Augsburg) 802; Voull(Trier) 1915; Schlechter-Ries 1707; Voull(B) 3875; Günt(L) 3226; Walsh 1986, 1987; Bod-inc F-022; Sheppard 3898; Rhodes(Oxford Colleges) 768; Pr 4531; BMC V 344; BSB-Ink F-82; GW 9826"
],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://data.cerl.org/istc/_search?query=aristotle&from=0&size=10&mode=default&sort=default",
"items": "multiple"
}
]
/** END TEST CASES **/