forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNational Library of Australia.js
65 lines (63 loc) · 2.22 KB
/
National Library of Australia.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
{
"translatorID":"fc410e64-0252-4cd3-acb1-25e584775fa2",
"translatorType":4,
"label":"National Library of Australia",
"creator":"Michael Berkowitz",
"target":"http://librariesaustralia.nla.gov.au/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2009-01-08 08:19:07"
}
function detectWeb(doc, url) {
if (url.match("action=Search")) {
return "multiple";
} else if (url.match("action=Display")) {
return "book";
}
}
function doWeb(doc, url) {
var n = doc.documentElement.namespaceURI;
var ns = n ? function(prefix) {
if (prefix == 'x') return n; else return null;
} : null;
var books = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = Zotero.Utilities.getItemArray(doc, doc, 'action=Display&');
items = Zotero.selectItems(items);
for (var i in items) {
books.push(i);
}
} else {
books = [url];
}
Zotero.Utilities.processDocuments(books, function(doc) {
var table = doc.evaluate('//tbody/tr[td[1][@class="CellAlignRight"]/strong]', doc, ns, XPathResult.ANY_TYPE, null);
var row;
var data = new Object();
while (row = table.iterateNext()) {
var heading = doc.evaluate('./td[1]', row, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var value = doc.evaluate('./td[2]', row, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
data[Zotero.Utilities.trimInternal(heading)] = value;
}
item = new Zotero.Item("book");
item.title = Zotero.Utilities.trimInternal(data['Title:'].match(/^[^/]+/)[0]);
if (data['Author:']) item.creators.push(Zotero.Utilities.cleanAuthor(data['Author:'], "author", true));
if (data['Published:'].match(/\w+/)) {
var pub = data['Published:'].match(/^([^:]+):(.*)\s+([^\s]+)$/);
item.location = Zotero.Utilities.trimInternal(pub[1]);
item.publisher = Zotero.Utilities.trimInternal(pub[2]);
item.date = Zotero.Utilities.trimInternal(pub[3].replace(/\D/g, ""));
}
if (data['Subjects:']) {
var kws = data['Subjects:'].split(".");
for each (var key in kws) {
if (key.match(/\w+/)) item.tags.push(key);
}
}
if (data['ISBN:']) item.ISBN = Zotero.Utilities.trimInternal(data['ISBN:'].match(/^[^(]+/)[0]);
item.complete();
}, function() {Zotero.done();});
Zotero.wait();
}