-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cornell LII.js
209 lines (183 loc) · 6.16 KB
/
Cornell LII.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
{
"translatorID":"930d49bc-44a1-4c22-9dde-aa6f72fb11e5",
"translatorType":4,
"label":"Cornell LII",
"creator":"Bill McKinney",
"target":"^http://www\\.law\\.cornell\\.edu/supct/html/.+",
"minVersion":"1.0.0b4.r1",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2009-03-19 17:36:00"
}
function detectWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var liiRegexp = /http:\/\/www\.law\.cornell\.edu\/supct\/html\/.+/
if(liiRegexp.test(url)) {
return "book";
} else {
var aTags = doc.getElementsByTagName("a");
for(var i=0; i<aTags.length; i++) {
if(articleRegexp.test(aTags[i].href)) {
return "multiple";
}
}
}
}
function associateMeta(newItem, metaTags, field, zoteroField) {
var field = metaTags.namedItem(field);
if(field) {
newItem[zoteroField] = field.getAttribute("content");
}
}
function scrape(doc) {
var caselawCourt = "U.S. Supreme Court";
var caselawJurisdiction = "Federal";
var caselawSourceReporter = "U.S.";
var caselawSourceVolume = "___";
var caselawSourceStartPage = "___";
var caselawParallelSourceVolume = "___";
var caselawParallelSourceStartPage = "___";
var caselawParallelSourceReporter = "___";
var caselawDecisionYear = "";
var newItem = new Zotero.Item("case");
newItem.url = doc.location.href;
newItem.language = "en-us";
newItem.court = "U.S. Supreme Court";
newItem.reporter = "U.S.";
// LII provides a bunch of meta tags to harvest
var metaTags = doc.getElementsByTagName("meta");
associateMeta(newItem, metaTags, "CASENAME", "title");
associateMeta(newItem, metaTags, "CASENAME", "caseName");
//associateMeta(newItem, metaTags, "DOCKET", "caselawDocket");
//associateMeta(newItem, metaTags, "PARTY1", "caselawParty1");
//associateMeta(newItem, metaTags, "PARTY2", "caselawParty2");
//associateMeta(newItem, metaTags, "ARGDATE", "caselawArguedDate");
//associateMeta(newItem, metaTags, "DECDATE", "dateDecided");
associateMeta(newItem, metaTags, "COURTBELOW", "history");
//associateMeta(newItem, metaTags, "ACTION", "caselawCourtAction");
var tmpCasename = newItem.caseName;
tmpCasename = Zotero.Utilities.capitalizeTitle(tmpCasename.toLowerCase());
tmpCasename = tmpCasename.replace("V.", "v.");
newItem.caseName = tmpCasename;
newItem.shortTitle = tmpCasename;
// judge
var j = metaTags.namedItem("AUTHOR");
if(j) {
// Some entries the AUTHOR meta tag content is empty, this makes zotero unhappy, adding a default
newItem.creators.push({lastName:j.getAttribute("content") ? j.getAttribute("content") : "Author Not Provided", creatorType:"judge", fieldMode:true});
}
// group meta tags
for(var i=0; i<metaTags.length; i++) {
var key = metaTags[i].getAttribute("name");
var value = metaTags[i].getAttribute("content");
if (key == "GROUP") {
newItem.tags.push(value);
}
}
// parse year out of decision date
var decdateField = metaTags.namedItem("DECDATE");
if(decdateField ) {
var decisionYearRegex = /(\w+)\s+(\d+),\s+(\d+)/
var decisionDateMatch = decisionYearRegex.exec(decdateField.getAttribute("content"));
var dy;
var dm;
var dd;
if (decisionDateMatch ) {
dm = decisionDateMatch[1];
dd = decisionDateMatch[2];
dy = decisionDateMatch [3];
caselawDecisionYear = dy;
newItem.dateDecided = dy + " " + dm + " " + dd;
}
}
// create attachment to pdf
var dyRegex = /^(.+)\/html\/(.+)(\.Z\w+)\.html$/;
var dyMatch = dyRegex.exec(newItem.url);
if (dyMatch) {
var pdfUrl = dyMatch[1]+"/pdf/"+dyMatch[2]+"P"+dyMatch[3];
newItem.attachments.push({url:pdfUrl, title:"PDF version", mimeType:"application/pdf", downloadable:true});
}
// parse disposition
var dis = doc.getElementsByTagName("DISPOSITION");
if (dis.length > 0) {
var tmpDis = dis[0].innerHTML;
tmpDis = tmpDis.replace(/\s+/g, " ");
newItem.title = newItem.title + " (" + tmpDis + ")";
newItem.caseName= newItem.caseName + " (" + tmpDis + ")";
}
// parse citation into parts so that bluebook can be constructed
var cite = doc.getElementsByTagName("CASENUMBER");
if (cite.length > 0) {
var citeRegex = /([0-9]+)\s+U\.S\.\s+([0-9]+)/;
var citeMatch = citeRegex.exec(cite[0].innerHTML);
if (citeMatch) {
caselawSourceVolume = citeMatch[1];
newItem.reporterVolume = citeMatch[1];
caselawSourceStartPage = citeMatch[2];
newItem.firstPage = citeMatch[2];
}
}
// look for offcite span element
var spanTags = doc.getElementsByTagName("span");
if (spanTags.length > 0) {
for(var i=0; i<spanTags.length; i++) {
if(spanTags[i].className == "offcite") {
var citeRegex = /([0-9]+)\s+U\.S\.\s+([0-9]+)/;
var citeMatch = citeRegex.exec(spanTags[i].innerHTML);
if (citeMatch) {
caselawSourceVolume = citeMatch[1];
newItem.reporterVolume = citeMatch[1];
caselawSourceStartPage = citeMatch[2];
newItem.firstPage = citeMatch[2];
}
break;
}
}
}
// bluebook citation
var bbCite = newItem.shortTitle + ", " +
caselawSourceVolume + " " +
caselawSourceReporter + " " +
caselawSourceStartPage;
// paralell cite
if (caselawParallelSourceVolume != "___") {
bbCite = bbCite + ", " + caselawParallelSourceVolume +
" " + caselawParallelSourceReporter + " " +
caselawParallelSourceStartPage;
}
// jurisdiction and year
bbCite = bbCite + " (" + caselawDecisionYear + ")";
// closing period
bbCite = "Bluebook citation: " + bbCite + ".";
newItem.notes.push({note:bbCite});
// parse out publication notice
var notice = doc.getElementsByTagName("NOTICE");
if (notice .length > 0) {
var tmpNotice= notice [0].innerHTML;
tmpNotice= tmpNotice.replace(/\s+/g, " ");
newItem.notes.push({note:tmpNotice});
}
newItem.complete();
}
function doWeb(doc, url) {
var liiRegexp = /http:\/\/www\.law\.cornell\.edu\/supct\/html\/.+/
if(liiRegexp.test(url)) {
scrape(doc);
} else {
var items = Zotero.Utilities.getItemArray(doc, doc, liiRegexp);
items = Zotero.selectItems(items);
if(!items) {
return true;
}
var urls = new Array();
for(var i in items) {
urls.push(i);
}
Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); });
Zotero.wait();
}
}