forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Access Science.js
391 lines (376 loc) · 12.1 KB
/
Access Science.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
{
"translatorID": "558330ca-3531-467a-8003-86cd9602cc48",
"label": "Access Science",
"creator": "Vinoth K - highwirepress.com",
"target": "^https?://www\\.accessscience\\.com/",
"minVersion": "5.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-10-17 20:19:39"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2023 Vinoth K - highwirepress.com
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) {
let title = attr(doc, 'meta[name="citation_title"]', 'content');
if (title) {
if (doc.querySelector('meta[name="citation_isbn"]')) {
let bookTitle = attr(doc, 'meta[name="citation_book_title"]', 'content');
if (!bookTitle || title == bookTitle) {
return "book";
}
else {
return "bookSection";
}
}
else if (url.includes('content/video/') || url.includes('content/video-biography')) {
return 'videoRecording';
}
else if (url.includes('content/article/')) {
return "journalArticle";
}
else if (url.includes('news') || url.includes('briefing')) {
return "magazineArticle";
}
else {
return "webpage";
}
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('.search-middle-right a[href]');
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) {
// Author
// Some of video pages having old content which does not contain the
// firstname and lastname. which is binding in a single string in
// metadata tags, So those cases we were split and mapped accordingly
if (item.itemType == 'videoRecording') {
let authorName = attr(doc, 'meta[name="citation_author"]', 'content');
if (authorName) {
item.creators = [];
if (authorName.includes(',') && authorName.split(',').length > 2) {
authorName = authorName.split(',')[0];
item.creators.push(ZU.cleanAuthor(authorName, "author", false));
}
}
}
let abstractNote = attr(doc, 'meta[name="citation_abstract"]', 'content');
item.abstractNote = abstractNote && ZU.cleanTags(abstractNote);
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.accessscience.com/content/book/9781260452297",
"items": [
{
"itemType": "book",
"title": "Casarett & Doull's Essentials of Toxicology",
"creators": [
{
"firstName": "Curtis D.",
"lastName": "Klaassen",
"creatorType": "editor"
},
{
"firstName": "John B. Watkins",
"lastName": "Iii",
"creatorType": "editor"
}
],
"date": "2022",
"ISBN": "9781260452297",
"abstractNote": "Doody9s Core Titles for 2021!\n\nFor more than 25 years, Casarett & Doull9s Toxicology: The Basic Science of Poisons has set the standard for providing thorough, academic, and authoritative information in clear and engaging ways. Distilling the major principles and concepts from that renowned text, Casarett & Doull9s Essentials of Toxicology delivers an accessible and highly readable introduction to the science and clinical field of medical toxicology. The book reflects the expertise of more than 60 renowned contributors.\n\nPresented in full-color, this new edition builds on the wide success of previous editions, with extensive updates that make the book more clinically relevant to students and beginners in toxicology, pharmacology, pharmacy, and environmental sciences. Chapter-ending self-assessment Q&As and other features make the learning process more effective and efficient.\n\nCasarett and Doull9s Essentials of Toxicology is organized into seven units:\n\n• General Principles of Toxicology\n\n• Disposition of Toxicants\n\n• Nonorgan-directed Toxicity\n\n• Target Organ Toxicity\n\n• Toxic Agents\n\n• Environmental Toxicology\n\n• Applications of Toxicology\n\nSuccinct, yet comprehensive, the text covers essential principles, toxicokinetics, how toxic effects are passed on to succeeding generations, how each body system responds to poisons, and the specific effects of a wide range of toxic agents—from pesticides to radiation.",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"publisher": "McGraw Hill",
"url": "https://www.accessscience.com/content/book/9781260452297",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/book/9781260452297/chapter/chapter2",
"items": [
{
"itemType": "bookSection",
"title": "Principles of Toxicology",
"creators": [
{
"firstName": "Lauren M.",
"lastName": "Aleksunes",
"creatorType": "author"
},
{
"firstName": "David L.",
"lastName": "Eaton",
"creatorType": "author"
},
{
"firstName": "Curtis D.",
"lastName": "Klaassen",
"creatorType": "editor"
},
{
"firstName": "John B. Watkins",
"lastName": "Iii",
"creatorType": "editor"
}
],
"date": "2022",
"ISBN": "9781260452297",
"bookTitle": "Casarett & Doull's Essentials of Toxicology",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"publisher": "McGraw Hill",
"url": "https://www.accessscience.com/content/book/9781260452297/chapter/chapter2",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/video/V2537194263001",
"items": [
{
"itemType": "videoRecording",
"title": "Supplementary Problem 10.12",
"creators": [
{
"firstName": "Rebecca B.",
"lastName": "DeVasher",
"creatorType": "author"
}
],
"date": "2013",
"abstractNote": "This video details a problem involving unit cells and the calculation of the mass of a cell, length of a cell and radius of an atom in the unit cell based on the density of a solid.",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"studio": "McGraw Hill",
"url": "https://www.accessscience.com/content/video/V2537194263001",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/video-biography/VB0014",
"items": [
{
"itemType": "videoRecording",
"title": "Anderson, John R.",
"creators": [],
"date": "2011",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"studio": "McGraw Hill",
"url": "https://www.accessscience.com/content/video-biography/VB0014",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/article/a694300?implicit-login=true",
"items": [
{
"itemType": "journalArticle",
"title": "3D printing",
"creators": [
{
"firstName": "Wenchao",
"lastName": "Zhou",
"creatorType": "author"
}
],
"date": "2023",
"DOI": "10.1036/1097-8542.694300",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"url": "https://www.accessscience.com/content/article/a694300",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/news/aSN2301171?implicit-login=true",
"items": [
{
"itemType": "magazineArticle",
"title": "These chemists cracked the code to long-lasting Roman concrete",
"creators": [
{
"firstName": "Carolyn",
"lastName": "Gramling",
"creatorType": "author"
}
],
"date": "2023",
"extra": "DOI: 10.1036/1097-8542.SN0000000",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"url": "https://www.accessscience.com/content/news/aSN2301171",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/video/an600010",
"items": [
{
"itemType": "videoRecording",
"title": "Henrietta Leavitt: The Woman Who Measured the Universe",
"creators": [],
"abstractNote": "Born in 1868, Henrietta Leavitt was an astronomer ahead of her time, whose work helped to revolutionize our understanding of the universe. While working at Harvard Observatory, Leavitt began to study stars of fluctuating brightness. This video describes her crucial observation about variable stars, which gave astronomers a new way to measure distances, ultimately leading to such impactful discoveries as the expansion of the universe.\n\nCredit: ESA Hubble Videos; Hubblecast 116: Henrietta Leavitt — ahead of her time; Directed by: Mathias Jäger; Visual design and editing: Martin Kornmesser; Written by: Sara Rigby; Narration: Sara Mendes da Costa; Images: ESA/Hubble and NASA, ESO, Hubble Heritage Team (STScI/AURA), Library of Congress Prints and Photographs Division Washington, Harvard College Observatory, Huntington Library, California Institute of Technology, Digitized Sky Survey 2, M. Kornmesser, R. Gendler, Arnold Reinhold, Davide De Martin; Videos: NASA, ESA, M. Kornmesser, Luis Calcada; Music: Johan B. Monell; Web and technical support: Mathias André and Raquel Yumi Shida; Executive producer: Lars Lindberg Christensen",
"language": "en",
"libraryCatalog": "www.accessscience.com",
"shortTitle": "Henrietta Leavitt",
"studio": "McGraw Hill",
"url": "https://www.accessscience.com/content/video/an600010",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/content/biography/m0073908",
"items": [
{
"itemType": "webpage",
"title": "Abbe, Cleveland (1838–1916)",
"creators": [],
"language": "en",
"url": "https://www.accessscience.com/content/biography/m0073908",
"websiteTitle": "McGraw Hill's AccessScience",
"websiteType": "text",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.accessscience.com/search?query=&items_per_page=10",
"items": "multiple"
}
]
/** END TEST CASES **/