-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathRAND.js
283 lines (265 loc) · 7.41 KB
/
RAND.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
{
"translatorID": "4a49257a-035f-4b8b-ba26-6ddfe3b9008d",
"label": "RAND",
"creator": "Abe Jellinek",
"target": "^https://www\\.rand\\.org/(pubs/|search\\.html)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-08-10 16:23:46"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2021 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('/pubs/external_publications/')) {
return "journalArticle";
}
else if (url.includes('/pubs/')) {
return "report";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('main h3.title a[href*="/pubs/"]');
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) {
var translator = Zotero.loadTranslator('web');
// Embedded Metadata
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
translator.setDocument(doc);
translator.setHandler('itemDone', function (obj, item) {
item.attachments = item.attachments.filter(a => a.title != 'Snapshot');
if (item.itemType == 'journalArticle') {
let citation = text(doc, '.citation');
if (!item.publicationTitle) {
item.publicationTitle = (citation.match(/Published in: ([^,]+)/) || [])[1];
}
if (!item.volume) {
item.volume = (citation.match(/Volume ([0-9]+)/) || [])[1];
}
if (!item.issue) {
item.issue = (citation.match(/Issue ([0-9]+)/) || [])[1];
}
if (!item.pages) {
item.pages = (citation.match(/pages ([0-9\-–]+)/) || [])[1];
}
}
delete item.reportType;
item.complete();
});
translator.getTranslatorObject(function (trans) {
trans.itemType = detectWeb(doc, url);
if (trans.itemType == 'multiple') return;
trans.doWeb(doc, url);
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.rand.org/pubs/conf_proceedings/CFA1299-1.html",
"items": [
{
"itemType": "report",
"title": "COVID-19 and the Courts: Lessons from the Pandemic",
"creators": [
{
"firstName": "Nicholas M.",
"lastName": "Pace",
"creatorType": "author"
},
{
"firstName": "Bethany",
"lastName": "Saunders-Medina",
"creatorType": "author"
},
{
"firstName": "Jamie",
"lastName": "Morikawa",
"creatorType": "author"
},
{
"firstName": "Sanjana",
"lastName": "Manjeshwar",
"creatorType": "author"
},
{
"firstName": "Anne",
"lastName": "Bloom",
"creatorType": "author"
}
],
"date": "2021/6/4",
"abstractNote": "<p>The U.S. civil justice system was forced to restructure almost overnight due to the coronavirus pandemic in 2020. Panelists in this virtual conference discussed how the pandemic has affected civil juries and pretrial case management, addressed implications that the pandemic might have for federal and state civil rules, and discussed solutions that could be applied to the civil justice system after circumstances eventually return to",
"institution": "RAND Corporation",
"language": "en",
"libraryCatalog": "www.rand.org",
"reportType": "Product Page",
"shortTitle": "COVID-19 and the Courts",
"url": "https://www.rand.org/pubs/conf_proceedings/CFA1299-1.html",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [
{
"tag": "Civil Law"
},
{
"tag": "Coronavirus Disease 2019 (COVID-19)"
},
{
"tag": "Juries"
},
{
"tag": "Legal Case and Court Management"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.rand.org/pubs/perspectives/PEA787-1.html",
"items": [
{
"itemType": "report",
"title": "Opportunities for the Brazilian Navy to Employ Additional Unmanned Systems",
"creators": [
{
"firstName": "Scott",
"lastName": "Savitz",
"creatorType": "author"
}
],
"date": "2021/8/10",
"abstractNote": "<p>This Perspective is an exploration of some of the ways the Brazilian Navy could use unmanned systems to improve effectiveness and, potentially, reduce risks and costs while meeting a wide range of demands over vast and diverse geographic areas. This analysis can also serve as a basic template for how other navies could employ unmanned vehicles.</p>",
"institution": "RAND Corporation",
"language": "en",
"libraryCatalog": "www.rand.org",
"reportType": "Product Page",
"url": "https://www.rand.org/pubs/perspectives/PEA787-1.html",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [
{
"tag": "Brazil"
},
{
"tag": "Unmanned Aerial Vehicles"
},
{
"tag": "Unmanned Maritime Vessels"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.rand.org/pubs/external_publications/EP68699.html",
"items": [
{
"itemType": "journalArticle",
"title": "Absenteeism and Presenteeism Among American Workers",
"creators": [
{
"firstName": "Nicole",
"lastName": "Maestas",
"creatorType": "author"
},
{
"firstName": "Kathleen J.",
"lastName": "Mullen",
"creatorType": "author"
},
{
"firstName": "Stephanie",
"lastName": "Rennane",
"creatorType": "author"
}
],
"date": "2021/8/10",
"abstractNote": "We analyze the relationship between absences, presenteeism, and work outcomes using data from the American Working Conditions Survey.",
"issue": "1",
"language": "en",
"libraryCatalog": "www.rand.org",
"pages": "13–23",
"publicationTitle": "Journal of Disability Policy Studies",
"url": "https://www.rand.org/pubs/external_publications/EP68699.html",
"volume": "32",
"attachments": [],
"tags": [
{
"tag": "Disability Insurance"
},
{
"tag": "People with Disabilities"
},
{
"tag": "Workplace Well-Being"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.rand.org/search.html?query=test",
"items": "multiple"
}
]
/** END TEST CASES **/