forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AustLII and NZLII.js
155 lines (151 loc) · 3.99 KB
/
AustLII and NZLII.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
{
"translatorID": "5ed5ab01-899f-4a3b-a74c-290fb2a1c9a4",
"label": "AustLII and NZLII",
"creator": "Bill McKinney and Sebastian Karcher",
"target": "^https?://www\\.(?:austlii\\.edu\\.au|nzlii\\.org)",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2012-05-16 23:48:05"
}
function detectWeb(doc, url) {
var austliiRegexp = /\/cases\/.+\d\.html/
if(austliiRegexp.test(url)) {
return "case";
} else {
var aTags = doc.getElementsByTagName("a");
for(var i=0; i<aTags.length; i++) {
if(austliiRegexp.test(aTags[i].href)) {
return "multiple";
}
}
}
}
function scrape(doc) {
var newItem = new Zotero.Item("case");
var voliss = ZU.xpathText(doc, '//h2');
var title = voliss.match(/.+?\[/)[0].replace(/\[/, "");
newItem.title = newItem.caseName = title;
//ZU.capitalizeTitle(title.toLowerCase(), true);
newItem.url = doc.location.href;
var court = ZU.trim(voliss.match(/\].+?[\(\[]/)[0].replace(/[\]\(\[]/g, ""))
newItem.court = court.match(/[^0-9]+/)[0]
newItem.docketNumber=court.match(/\d+/)[0]
newItem.dateDecided = voliss.match(/\(\d[^\)]+\d{4}\)/)[0].replace(/[\(\)]/g, "");
newItem.attachments = [{ document:doc, title:"AustLII/NZLII snapshort", mimeType:"text/html"}];
newItem.complete();
}
function doWeb(doc, url) {
var austliiRegexp = /\/cases\/.+\d\.html/;
if(austliiRegexp.test(url)) {
scrape(doc);
} else {
var items = Zotero.Utilities.getItemArray(doc, doc, austliiRegexp);
var urls = new Array();
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var i in items) {
urls.push(i);
}
Zotero.Utilities.processDocuments(urls, scrape, function () {
Zotero.done();
});
Zotero.wait();
});
}
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.austlii.edu.au/au/cases/cth/FamCA/2006/212.html",
"items": [
{
"itemType": "case",
"creators": [],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "AustLII/NZLII snapshort",
"mimeType": "text/html"
}
],
"caseName": "C & M",
"title": "C & M",
"url": "http://www.austlii.edu.au/au/cases/cth/FamCA/2006/212.html",
"court": "FamCA",
"docketNumber": "212",
"dateDecided": "20 January 2006",
"libraryCatalog": "AustLII and NZLII",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://www.austlii.edu.au/au/cases/cth/FCA/2010/1.html",
"items": [
{
"itemType": "case",
"creators": [],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "AustLII/NZLII snapshort",
"mimeType": "text/html"
}
],
"caseName": "Yeo, in the matter of AES Services (Aust) Pty Ltd (ACN 111 306 543) (Administrators Appointed)",
"title": "Yeo, in the matter of AES Services (Aust) Pty Ltd (ACN 111 306 543) (Administrators Appointed)",
"url": "http://www.austlii.edu.au/au/cases/cth/FCA/2010/1.html",
"court": "FCA",
"docketNumber": "1",
"dateDecided": "5 January 2010",
"libraryCatalog": "AustLII and NZLII",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://www.nzlii.org/nz/cases/NZSC/2008/1.html",
"items": [
{
"itemType": "case",
"creators": [],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "AustLII/NZLII snapshort",
"mimeType": "text/html"
}
],
"caseName": "Bronwyn Estate Ltd and ors v Gareth Hoole and others",
"title": "Bronwyn Estate Ltd and ors v Gareth Hoole and others",
"url": "http://www.nzlii.org/nz/cases/NZSC/2008/1.html",
"court": "NZSC",
"docketNumber": "1",
"dateDecided": "8 February 2008",
"libraryCatalog": "AustLII and NZLII",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://www.austlii.edu.au/au/cases/act/ACTSC/2010/",
"items": "multiple"
}
]
/** END TEST CASES **/