-
Notifications
You must be signed in to change notification settings - Fork 763
/
Australian Dictionary of Biography.js
196 lines (177 loc) · 6.27 KB
/
Australian Dictionary of Biography.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
{
"translatorID": "0aea3026-a246-4201-a4b5-265f75b9a6a7",
"label": "Australian Dictionary of Biography",
"creator": "Sebastian Karcher",
"target": "^https?://adb\\.anu\\.edu\\.au/biograph(y|ies)/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-07-14 04:18:08"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2012-2021 Sebastian Karcher and Abe Jellinek
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.includes('/biography/')) {
return "bookSection";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('a.name');
for (let row of rows) {
let href = row.href;
let title = ZU.trimInternal(row.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) ZU.processDocuments(Object.keys(items), scrape);
});
}
else {
scrape(doc, url);
}
}
function scrape(doc, url) {
let item = new Zotero.Item('bookSection');
let main = doc.querySelector('#pageColumnMain');
item.title = text(main, 'h2');
item.abstractNote = text(main, '.biographyContent p');
item.bookTitle = 'Australian Dictionary of Biography';
let noticeMatches = text(main, '.textNotice')
.match(/([^,]+), \(MUP\), ([^,]+)/);
if (noticeMatches) {
item.volume = noticeMatches[1].replace(/^\s*volume/i, '');
item.date = ZU.strToISO(noticeMatches[2]);
}
else {
item.date = ZU.strToISO(text(main, '.textNotice'));
}
item.numberOfVolumes = '18';
item.publisher = 'National Centre of Biography, Australian National University';
item.place = 'Canberra';
item.language = 'en';
item.url = url;
for (let author of main.querySelectorAll('.authorName a')) {
item.creators.push(ZU.cleanAuthor(author.textContent, 'author'));
}
item.attachments.push({
title: 'Snapshot',
document: doc
});
item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://adb.anu.edu.au/biographies/search/?scope=all&query=Smith&x=0&y=0&rs=",
"items": "multiple"
},
{
"type": "web",
"url": "https://adb.anu.edu.au/biography/smith-robert-burdett-4613",
"items": [
{
"itemType": "bookSection",
"title": "Smith, Robert Burdett (1837–1895)",
"creators": [
{
"firstName": "Chris",
"lastName": "Cunneen",
"creatorType": "author"
}
],
"date": "1976",
"abstractNote": "Robert Burdett Smith (1837-1895), solicitor and politician, was born on 25 August 1837 in Sydney, baptized Robert Lloyd, twin son of John Lloyd Smith and his wife Mary Ann, née Salmon. John, a native of Northumberland, had been convicted of horse-stealing at Edinburgh on 8 January 1830 and sentenced to be transported for seven years, arriving in Sydney in the York on 7 February 1831. Mary Ann, whom he had married with the governor's permission on 2 February 1835, had come free to the colony in the Princess Victoria on 4 February 1834. With his brother-in-law Thomas Armitage Salmon and later on his own, John traded as a carcass butcher in 1838-43; but on 11 April, bankrupt, he was convicted in Port Phillip of forgery and sentenced to transportation for the term of his natural life.",
"bookTitle": "Australian Dictionary of Biography",
"language": "en",
"libraryCatalog": "Australian Dictionary of Biography",
"numberOfVolumes": "18",
"place": "Canberra",
"publisher": "National Centre of Biography, Australian National University",
"url": "https://adb.anu.edu.au/biography/smith-robert-burdett-4613",
"volume": "6",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://adb.anu.edu.au/biography/bjelkepetersen-hans-christian-5247/text8839",
"items": [
{
"itemType": "bookSection",
"title": "Bjelke-Petersen, Hans Christian (1872–1964)",
"creators": [
{
"firstName": "Chris",
"lastName": "Cunneen",
"creatorType": "author"
},
{
"firstName": "E. A.",
"lastName": "McLeod",
"creatorType": "author"
}
],
"date": "1979",
"abstractNote": "Hans Christian Bjelke-Petersen (1872-1964), physical culture teacher, was born on 14 April 1872 in Copenhagen, Denmark, son of Georg Peter Bjelke-Petersen, gardener, later master-builder, and his wife Caroline Vilhelmine, née Hansen. His sister was Marie Caroline Bjelke-Petersen. At first educated by his father at home, acquiring a thorough grounding in gymnastics, swimming and the Bible, he later attended schools at Dresden, Germany, and at Copenhagen, graduating from Copenhagen Teachers' College in 1890. The family then went to London and in October 1891 arrived in Tasmania in the Doric.",
"bookTitle": "Australian Dictionary of Biography",
"language": "en",
"libraryCatalog": "Australian Dictionary of Biography",
"numberOfVolumes": "18",
"place": "Canberra",
"publisher": "National Centre of Biography, Australian National University",
"url": "https://adb.anu.edu.au/biography/bjelkepetersen-hans-christian-5247/text8839",
"volume": "7",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/