-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathLibrary Catalog (Encore).js
211 lines (196 loc) · 6.57 KB
/
Library Catalog (Encore).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
{
"translatorID": "446764bf-7da6-49ec-b7a7-fefcbafe317f",
"label": "Library Catalog (Encore)",
"creator": "Sebastian Karcher",
"target": "/iii/encore/(record|search)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 270,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2017-11-25 15:51:49"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2017 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 *****
*/
// attr()/text() v2
function attr(docOrElem,selector,attr,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.getAttribute(attr):null;}function text(docOrElem,selector,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.textContent:null;}
function detectWeb(doc, url) {
if (url.includes("encore/record")) {
return "book";
} else if (url.includes("encore/search")) {
return "multiple";
}
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('a[id^=recordDisplayLink2Component]');
for (let i = 0; i < rows.length; i++) {
let href = createMarcURL(rows[i].href);
let title = ZU.trimInternal(rows[i].textContent);
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), function(items) {
if (!items) {
return true;
}
var articles = [];
for (var i in items) {
articles.push(i);
}
scrape(articles);
});
} else {
var marcURL = createMarcURL(url);
scrape([marcURL]);
}
}
function createMarcURL(url) {
//construct the marc URL
return url.replace(/\?/, "?marcData=Y&");
}
function scrape(marcURL) {
for (let i = 0; i < marcURL.length; i++) {
//Z.debug(marcURL[i])
// the library catalogue name isn't perfect, but should be unambiguous.
var domain = marcURL[i].match(/https?:\/\/([^/]+)/);
ZU.doGet(marcURL[i], function(text) {
var translator = Zotero.loadTranslator("import");
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
translator.getTranslatorObject(function(marc) {
var record = new marc.record();
var newItem = new Zotero.Item();
text = text.replace(/^\n/mg, '') // skip empty lines
.replace(/\s?\n\s+/gm, ' '); // delete line breaks when only needed for displaying long lines
//Z.debug(text);
var line = text.split("\n");
for (var j = 0; j < line.length; j++) {
line[j] = line[j].replace(/[\xA0_\t]/g, " ");
var value = line[j].substr(7);
if (line[j].substr(0, 6) == "LEADER") {
// trap leader
record.leader = value;
} else {
var tag = line[j].substr(0, 3);
var ind = line[j].substr(4, 2);
if (value) {
value = value.replace(/\|(.)/g, marc.subfieldDelimiter + "$1");
if (value[0] != marc.subfieldDelimiter) {
value = marc.subfieldDelimiter + "a" + value;
}
record.addField(tag, ind, value);
}
}
}
record.translate(newItem);
newItem.repository = domain[1].replace(/encore\./, "");
// there is too much stuff in the note field - or file this as an abstract?
newItem.notes = [];
newItem.complete();
});
});
}
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://sallypro.sandiego.edu/iii/encore/record/C__Rb4044553__Stesting__P0%2C6__Orightresult__U__X6?lang=eng&suite=cobalt",
"items": [
{
"itemType": "book",
"title": "Evaluation and testing in nursing education",
"creators": [
{
"firstName": "Marilyn H.",
"lastName": "Oermann",
"creatorType": "author"
},
{
"firstName": "Kathleen B.",
"lastName": "Gaberson",
"creatorType": "author"
}
],
"date": "2017",
"ISBN": "9780826194886",
"abstractNote": "Considered the \"gold standard' for evaluation and testing in nursing education, this classic text helps educators to assess the level of learning achieved in the classroom, clinical settings, and online. The fifth edition helps teachers to keep pace with new learning dynamics through expanded coverage of essential concepts in assessment, evaluation, and testing in a wider variety of learning environments. It presents new content on evaluation in online programs and testing, and features a new chapter on using simulation for assessment and high stakes evaluations. Also included is updated information on clinical evaluation and program evaluation along with current research featuring new examples and tools. The fifth edition expands content on standardized tests, including how to write test items for licensure and certification exam prep, and provides new information on developing rubrics for assessing written assignments. -- Provided by publisher",
"callNumber": "RT73.7 .O47 2017",
"edition": "Fifth edition",
"extra": "OCLC: 957077777",
"libraryCatalog": "sallypro.sandiego.edu",
"numPages": "403",
"place": "New York, NY",
"publisher": "Springer Publishing Company, LLC",
"attachments": [],
"tags": [
{
"tag": "Ability testing"
},
{
"tag": "Ability testing"
},
{
"tag": "Examinations"
},
{
"tag": "Examinations"
},
{
"tag": "Nursing"
},
{
"tag": "Nursing"
},
{
"tag": "Nursing"
},
{
"tag": "Nursing"
},
{
"tag": "Nursing"
},
{
"tag": "Nursing"
},
{
"tag": "Study and teaching Evaluation"
},
{
"tag": "Study and teaching Evaluation"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://sallypro.sandiego.edu/iii/encore/search/C__Rb3558162__Stesting__Orightresult__U__X6?lang=eng&suite=cobalt#resultRecord-b3558162",
"items": "multiple"
}
]
/** END TEST CASES **/