-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathHuman Rights Watch.js
450 lines (427 loc) · 15.5 KB
/
Human Rights Watch.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
{
"translatorID": "2bd6876f-26ce-43ec-a9af-88616a464ed0",
"label": "Human Rights Watch",
"creator": "Abe Jellinek",
"target": "^https?://www\\.hrw\\.org/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-08-14 03:16:54"
}
/*
***** 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) {
// can't go off URLs alone because some reports are under /news/
if (url.includes('/report/') || doc.querySelector('.report-header')) {
return "report";
}
else if (url.includes('world-report') || doc.querySelector('.wr-hero')) {
if (url.includes('/country-chapters/')) {
return "bookSection";
}
else {
return "book";
}
}
else if (doc.querySelector('.news-header')) {
return "blogPost";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('h3.media-block__title > a');
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) {
if (item.itemType == 'report') {
if (url.includes('/world-report/') || doc.querySelector('.wr-hero')) {
// world reports get the wrong title
item.title = text(doc, 'h1');
}
else {
// we only bother with subtitles for regular reports because they're
// just descriptions on news/briefings/blog posts/world reports.
let subtitle = text(doc, '.report-header__subtitle');
if (subtitle && !item.title.includes(': ')) {
item.title += `: ${subtitle}`;
}
}
item.institution = 'Human Rights Watch';
// HRW reports have ISBNs, but there's no way to get them from the page,
// only from some text in the PDF. Such a pain.
if (item.abstractNote) {
item.abstractNote = item.abstractNote.replace(/^Summary\b/, '');
}
}
else if (item.itemType == 'bookSection') {
item.title = text(doc, 'h1');
let subtitle = text(doc, '.chapter-header__subtitle');
if (subtitle && !item.title.includes(': ')) {
item.title += `: ${subtitle}`;
}
item.bookTitle = text(doc, 'header a[href*="/world-report/"]');
}
if (['book', 'bookSection'].includes(item.itemType)) {
// can't get the publisher...
item.creators = [{
lastName: 'Human Rights Watch',
creatorType: 'author',
fieldMode: 1
}];
}
let downloadLink = attr(doc, 'a.download-item-link, a.wr-hero__report-dl', 'href');
if (downloadLink) {
// replace snapshot
item.attachments = [
{
title: 'Full Text PDF',
mimeType: 'application/pdf',
url: downloadLink
}
];
}
item.libraryCatalog = 'Human Rights Watch';
item.complete();
});
translator.getTranslatorObject(function (trans) {
trans.itemType = detectWeb(doc, url);
trans.doWeb(doc, url);
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.hrw.org/report/2021/08/10/underwater/human-rights-impacts-china-belt-and-road-project-cambodia",
"items": [
{
"itemType": "report",
"title": "Underwater: Human Rights Impacts of a China Belt and Road Project in Cambodia",
"creators": [],
"date": "2021-08-10T10:31:33-0400",
"abstractNote": "“Dao,” an ethnic Lao man in his 40s, previously lived a largely self-sufficient life in the village of Srekor in northeastern Cambodia’s Stung Treng province. He fished on the Sesan River and farmed rice and fruit on the fertile soil along the river. His family gathered herbs, mushrooms, resins, and medicinal plants from his village’s communal forests and sold them at the local market.",
"institution": "Human Rights Watch",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "Underwater",
"url": "https://www.hrw.org/report/2021/08/10/underwater/human-rights-impacts-china-belt-and-road-project-cambodia",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/km/report/2021/08/10/379432",
"items": [
{
"itemType": "report",
"title": "នៅក្រោមផ្ទែទឹក: ផលប៉ះពាល់សិទ្ធិមនុស្សពីគម្រោងផ្លូវមួយ ខ្សែក្រវាត់មួយនៅកម្ពុជា របាការណ៍សង្ខេប",
"creators": [],
"date": "2021-08-10T17:28:43-0400",
"abstractNote": "“លោក ដាវ” ជាជនជាតិភាគតិចឡាវ មានអាយុ ជាង ៤០ ឆ្នាំ ធ្លាប់រស់នៅក្នុងជីវភាពដែលស្វ័យភាពបរិបូរក្នុងភូមិ ស្រែគ ខេត្តស្ទឹងត្រែង ភាគឦសាននៃប្រទេសកម្ពុជា។ គាត់ប្រកបរបរនេសាទក្នុងទន្លេសេសាន និងធ្វើស្រែចំការ នៅលើដីដ៏មានជីជាតិតាមដងទន្លេ។ គ្រួសាររបស់លោក ចេញទៅរករុក្ខជាតិ ផ្សិត ជ័រទឹក រុក្ខជាតិឱសថផ្សេងៗពីព",
"institution": "Human Rights Watch",
"language": "km",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "នៅក្រោមផ្ទែទឹក",
"url": "https://www.hrw.org/km/report/2021/08/10/379432",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/report/2018/07/01/scared-public-and-now-no-privacy/human-rights-and-public-health-impacts",
"items": [
{
"itemType": "report",
"title": "“Scared in Public and Now No Privacy”: Human Rights and Public Health Impacts of Indonesia’s Anti-LGBT Moral Panic",
"creators": [],
"date": "2018-07-01T21:01:01-0400",
"abstractNote": "On May 21, 2017, police in Indonesia’s capital, Jakarta, raided the Atlantis gym and sauna, arresting 141 people, most of whom were gay or bisexual men. Ten were ultimately prosecuted under Indonesia’s pornography law. The Atlantis was not just a “gay club,” but a public health outreach center—a well-known hub for HIV education, testing, and counseling among men who have sex with men (MSM).",
"institution": "Human Rights Watch",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "“Scared in Public and Now No Privacy”",
"url": "https://www.hrw.org/report/2018/07/01/scared-public-and-now-no-privacy/human-rights-and-public-health-impacts",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/report/2019/05/28/if-you-are-afraid-your-lives-leave-sinai/egyptian-security-forces-and-isis",
"items": [
{
"itemType": "report",
"title": "If You Are Afraid for Your Lives, Leave Sinai!: Egyptian Security Forces and ISIS-Affiliate Abuses in North Sinai",
"creators": [],
"date": "2019-05-28T00:59:01-0400",
"institution": "Human Rights Watch",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "If You Are Afraid for Your Lives, Leave Sinai!",
"url": "https://www.hrw.org/report/2019/05/28/if-you-are-afraid-your-lives-leave-sinai/egyptian-security-forces-and-isis",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/news/2021/08/05/afghanistan-justice-system-failing-women",
"items": [
{
"itemType": "blogPost",
"title": "Afghanistan: Justice System Failing Women",
"creators": [],
"date": "2021-08-05T08:00:00-0400",
"abstractNote": "The Afghan government’s failure to provide accountability for violence against women and girls has undermined progress to protect women’s rights, Human Rights Watch said in a report released today.",
"blogTitle": "Human Rights Watch",
"language": "en",
"shortTitle": "Afghanistan",
"url": "https://www.hrw.org/news/2021/08/05/afghanistan-justice-system-failing-women",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/the-day-in-human-rights/2021/07/26",
"items": [
{
"itemType": "blogPost",
"title": "Fears of Further Taliban Atrocities in Afghanistan: Daily Brief",
"creators": [],
"date": "2021-07-26T03:29:54-0400",
"abstractNote": "Afghanistan's civilian casualties have hit a record high, according to a new UN study.",
"blogTitle": "Human Rights Watch",
"language": "en",
"shortTitle": "Fears of Further Taliban Atrocities in Afghanistan",
"url": "https://www.hrw.org/the-day-in-human-rights/2021/07/26",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/sitesearch?search=test",
"items": "multiple"
},
{
"type": "web",
"url": "https://www.hrw.org/news/2021/08/11/left-fish-too-small-sell-cambodias-mekong-river-basin",
"items": [
{
"itemType": "report",
"title": "Left With Fish Too Small to Sell in Cambodia’s Mekong River Basin: How a China-Built Dam Destroyed an Ecosystem and Livelihoods",
"creators": [],
"date": "2021-08-10T17:16:06-0400",
"abstractNote": "Thousands have lost their homes and livelihoods since the completion of one of Asia’s widest dams, the Lower Sesan 2, in Cambodia’s Mekong River Basi",
"institution": "Human Rights Watch",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "Left With Fish Too Small to Sell in Cambodia’s Mekong River Basin",
"url": "https://www.hrw.org/news/2021/08/11/left-fish-too-small-sell-cambodias-mekong-river-basin",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/world-report/2019",
"items": [
{
"itemType": "book",
"title": "World Report 2019 | Human Rights Watch",
"creators": [
{
"lastName": "Human Rights Watch",
"creatorType": "author",
"fieldMode": 1
}
],
"date": "2018-12-04T13:10:21-0500",
"abstractNote": "World Report 2019 is Human Rights Watch’s 29th annual review of human rights practices around the globe. It summarizes key human rights issues in more than 100 countries and territories worldwide, drawing on events from late 2017 through November 2018.\n\nIn his keynote essay, “World’s Autocrats Face Rising Resistance,” Human Rights Watch Executive Director Kenneth Roth argues that while autocrats and rights abusers often captured headlines in 2018, rights defenders pushed back and gained strength in unexpected ways.",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"url": "https://www.hrw.org/world-report/2019",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/world-report/2019/country-chapters/australia",
"items": [
{
"itemType": "bookSection",
"title": "Australia: Events of 2018",
"creators": [
{
"lastName": "Human Rights Watch",
"creatorType": "author",
"fieldMode": 1
}
],
"date": "2018-12-20T19:12:50-0500",
"abstractNote": "Australia has a strong record of protecting civil and political rights, but serious human rights issues remain. In 2018, the government continued to hold refugees and asylum seekers who arrived by boat in Australian waters on Manus Island in Papua New Guinea and on Nauru, marking more than five years since the reintroduction of its draconian offshore processing and settlement policy.\n\nIn October, the Queensland government introduced a human rights act, becoming the third jurisdiction in Australia to do so behind the Australian Capital Territory and Victoria.",
"bookTitle": "World Report 2019",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "Australia",
"url": "https://www.hrw.org/world-report/2019/country-chapters/australia",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.hrw.org/world-report/2019/country-chapters/global-5",
"items": [
{
"itemType": "bookSection",
"title": "Caught in the Middle: Convincing “Middle Powers” to Fight Autocrats Despite High Costs",
"creators": [
{
"lastName": "Human Rights Watch",
"creatorType": "author",
"fieldMode": 1
}
],
"date": "2019-01-08T10:54:37-0500",
"abstractNote": "In a stifling political climate dominated by thin-skinned autocrats, governments that criticize another country’s human rights record risk paying an increasingly heavy price.\n\nIn August, a routine tweet by Canada’s Foreign Ministry calling for the release of Saudi women’s rights defenders triggered a full-blown diplomatic crisis, with Saudi Arabia retaliating by expelling Canada’s ambassador in Riyadh and freezing all new bilateral trade and investments.",
"bookTitle": "World Report 2019",
"language": "en",
"libraryCatalog": "Human Rights Watch",
"shortTitle": "Caught in the Middle",
"url": "https://www.hrw.org/world-report/2019/country-chapters/global-5",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/