-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathLibrary Catalog (Capita Prism).js
162 lines (150 loc) · 4.13 KB
/
Library Catalog (Capita Prism).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
{
"translatorID": "dc024bfc-2252-4257-b10e-cb95a0f213aa",
"label": "Library Catalog (Capita Prism)",
"creator": "Sebastian Karcher",
"target": "/items(/\\d+|\\?query=)",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 260,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2016-07-02 21:37:30"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2012 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) {
if (url.match(/\/items\?query=/) && ZU.xpathText(doc, '//div[@id="searchResults"]//h2[@class="title"]/a')!=null ) return "multiple";
if (url.match(/\/items\/\d+/)) {
var test = ZU.xpathText(doc, '//link/@type');
if (test && test.indexOf("application/x-endnote-refer")!=-1)
return "book";
}
}
function doWeb(doc, url){
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = {};
var titles = doc.evaluate('//div[@id="searchResults"]//h2[@class="title"]/a', doc, null, XPathResult.ANY_TYPE, null);
var title;
while (title = titles.iterateNext()) {
items[title.href] = title.textContent;
}
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var i in items) {
articles.push(referURL(i));
}
scrape(articles);
});
} else {
scrape(referURL(url));
}
}
// help function
function scrape(url){
Zotero.Utilities.HTTP.doGet(url, function (text) {
//Z.debug(text)
//the language text doesn't seem regular Refer, but it's used here
var language = text.match(/%G.+/)[0];
//load Refer/BibIX translator - until we can import their JSON or RDF format this looks best.
var translator = Zotero.loadTranslator("import");
translator.setTranslator("881f60f2-0802-411a-9228-ce5f47b64c7d");
translator.setString(text);
translator.setHandler("itemDone", function(obj, item) {
if (language){
item.language= language.replace(/%G\s*/, "");
}
item.complete();
});
translator.translate();
});
}
function referURL(url){
return url.replace(/\?.+/, "") + ".enw";
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://capitadiscovery.co.uk/bcu/items/324179?query=mannheim&resultsUri=items%3Fquery%3Dmannheim",
"items": [
{
"itemType": "book",
"title": "Mannheim and Vienna",
"creators": [
{
"firstName": "Wolfgang Amadeus",
"lastName": "Mozart",
"creatorType": "author"
}
],
"language": "English",
"libraryCatalog": "Library Catalog (Capita Prism)",
"publisher": "Archiv",
"url": "http://capitadiscovery.co.uk/bcu/items/324179",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://capitadiscovery.co.uk/bradford/items?query=shakespeare",
"items": "multiple"
},
{
"type": "web",
"url": "http://capitadiscovery.co.uk/worcs/items/693096",
"items": [
{
"itemType": "book",
"title": "Not quite Nice",
"creators": [
{
"firstName": "Celia",
"lastName": "Imrie",
"creatorType": "author"
}
],
"date": "2016",
"ISBN": "9781408846896",
"language": "English",
"libraryCatalog": "Library Catalog (Capita Prism)",
"place": "London",
"publisher": "Bloomsbury",
"url": "http://capitadiscovery.co.uk/worcs/items/693096",
"attachments": [],
"tags": [
"General.",
"Riviera (France) Fiction."
],
"notes": [
{
"note": "Celia Imrie"
}
],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/