/
RSC Publishing.js
237 lines (221 loc) · 6.75 KB
/
RSC Publishing.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
{
"translatorID": "ca0e7488-ef20-4485-8499-9c47e60dcfa7",
"label": "RSC Publishing",
"creator": "Sebastian Karcher",
"target": "^https?://(:?www\\.|google\\.)?pubs\\.rsc\\.org/",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsb",
"lastUpdated": "2012-10-20 09:32:44"
}
/*
RSC Publishing Translator
Copyright (C) 2011 Aurimas Vinckevicius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function getResults(doc) {
/**Both search result and book ToC pages use javascript to load content, so
* this actually doesn't work as intended. Search results will work, but
* will also trigger on empty result set. detectWeb for book ToC does not
* work, but doWeb does,
*/
return ZU.xpath(doc, '//div[@id="all" or @id="chapterList"]\
//div[contains(@class,"title_text")]\
//a[not(contains(@href,"/database/"))]');
}
function detectWeb(doc, url) {
if(url.search(/\/results[?\/]/i) != -1 || url.indexOf('/ebook/') != -1 &&
getResults(doc).length) {
return 'multiple';
}
//apparently URLs sometimes have upper case as in /Content/ArticleLanding/
if(url.search(/\/content\/articlelanding\//i) != -1) {
return 'journalArticle';
}
if(url.search(/\/content\/chapter\//i) != -1) {
return 'bookSection';
}
}
function scrape(doc, type) {
var translator = Zotero.loadTranslator('web');
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
translator.setDocument(doc);
translator.setHandler('itemDone', function(obj, item) {
item.itemType = type;
if(type == 'bookSection') {
//fix title for book chapters
var title = ZU.xpathText(doc, '//label[@id="lblTitle"]/node()',
null, ' ');
if(title) item.title = ZU.trimInternal(title);
//add bookTitle
item.bookTitle = ZU.xpathText(doc, '//h2[@class="sub_title"]');
} else if(type == 'journalArticle') {
//journal title is abbreviated. We can fetch full title from the page
item.publicationTitle = ZU.xpathText(doc, '//h2[@class="sub_title"]');
}
//keywords is frequently an empty string
if(item.tags.length == 1 && !item.tags[0]) {
item.tags = [];
}
item.complete();
});
translator.translate();
}
function doWeb(doc, url) {
var type = detectWeb(doc, url);
if(type == 'multiple') {
var results = getResults(doc);
var items = new Object();
for(var i=0, n=results.length; i<n; i++) {
items[results[i].href] = ZU.trimInternal(
ZU.xpathText(results[i], './node()', null, ' '));
}
Zotero.selectItems(items, function(selectedItems) {
if(!selectedItems) return true;
var urls = new Array();
for(var i in selectedItems) {
urls.push(i);
}
ZU.processDocuments(urls,
function(doc) { doWeb(doc, doc.location.href)});
});
} else {
scrape(doc, type);
}
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://pubs.rsc.org/en/content/articlelanding/2012/ee/c1ee02148f",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"firstName": "Wei",
"lastName": "Guo",
"creatorType": "author"
},
{
"firstName": "Ya-Xia",
"lastName": "Yin",
"creatorType": "author"
},
{
"firstName": "Sen",
"lastName": "Xin",
"creatorType": "author"
},
{
"firstName": "Yu-Guo",
"lastName": "Guo",
"creatorType": "author"
},
{
"firstName": "Li-Jun",
"lastName": "Wan",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
},
{
"title": "Snapshot"
}
],
"itemID": "http://pubs.rsc.org/en/content/articlelanding/2012/ee/c1ee02148f",
"title": "Superior radical polymer cathode material with a two-electron process redox reaction promoted by graphene",
"publisher": "The Royal Society of Chemistry",
"institution": "The Royal Society of Chemistry",
"company": "The Royal Society of Chemistry",
"label": "The Royal Society of Chemistry",
"distributor": "The Royal Society of Chemistry",
"date": "2012-01-01",
"DOI": "10.1039/C1EE02148F",
"language": "en",
"publicationTitle": "Energy & Environmental Science",
"journalAbbreviation": "Energy Environ. Sci.",
"volume": "5",
"issue": "1",
"abstractNote": "Poly(2,2,6,6-tetramethyl-1-piperidinyloxy-4-yl methacrylate) (PTMA) displays a two–electron process redox reaction, high capacity of up to 222 mA h g−1, good rate performance and long cycle life, which is promoted by graphene as cathode material for lithium rechargeable batteries.",
"pages": "5221-5225",
"ISSN": "1754-5706",
"url": "http://pubs.rsc.org/en/content/articlelanding/2012/ee/c1ee02148f",
"accessDate": "CURRENT_TIMESTAMP",
"libraryCatalog": "pubs.rsc.org"
}
]
},
{
"type": "web",
"url": "http://pubs.rsc.org/en/content/chapter/bk9781849730518-00330/978-1-84973-051-8",
"items": [
{
"itemType": "bookSection",
"creators": [
{
"firstName": "Michael T.",
"lastName": "Simonich",
"creatorType": "author"
},
{
"firstName": "Jill A.",
"lastName": "Franzosa",
"creatorType": "author"
},
{
"firstName": "Robert L.",
"lastName": "Tanguay*",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
},
{
"title": "Snapshot"
}
],
"itemID": "http://pubs.rsc.org/en/content/chapter/bk9781849730518-00330/978-1-84973-051-8",
"title": "Chapter 14 In Vivo Approaches to Predictive Toxicology Using Zebrafish",
"date": "2011/11/15",
"DOI": "10.1039/9781849733045-00330",
"language": "en",
"url": "http://pubs.rsc.org/en/content/chapter/bk9781849730518-00330/978-1-84973-051-8",
"accessDate": "CURRENT_TIMESTAMP",
"libraryCatalog": "pubs.rsc.org",
"bookTitle": "New Horizons in Predictive Toxicology: Current Status and Application"
}
]
},
{
"type": "web",
"url": "http://pubs.rsc.org/en/results?searchtext=open%20source",
"items": "multiple",
"defer": true
}
]
/** END TEST CASES **/