forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CAOD.js
260 lines (249 loc) · 8.73 KB
/
CAOD.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
{
"translatorID": "d2a9e388-5b79-403a-b4ec-e7099ca1bb7f",
"label": "CAOD",
"creator": "Guy Aglionby",
"target": "^https?://caod\\.oriprobe\\.com/articles/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2018-09-08 13:38:50"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2018 Guy Aglionby
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('articles/found.htm?')) {
if (getSearchResults(doc, true)) {
return 'multiple';
}
} else {
return 'journalArticle';
}
}
function scrape(doc, url) {
var translator = Zotero.loadTranslator('web');
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
translator.setDocument(doc);
translator.setHandler('itemDone', function(obj, item) {
// Necessary as author surname comes first and is often capitalised, so Zotero thinks it's actually initials.
let authors = ZU.xpath(doc, '//span[@itemprop="author"]/a');
item.creators = authors.map(function(author) {
let authorNames = author.text.split(' ');
authorNames[0] = authorNames[0].charAt(0) + authorNames[0].substr(1).toLowerCase();
return ZU.cleanAuthor(authorNames.reverse().join(' '), 'author');
});
let keywords = ZU.xpath(doc, '//span[@itemprop="headline"]/a');
item.tags = keywords.map(function (keyword) {
return keyword.textContent;
});
item.complete();
});
translator.translate();
}
function getSearchResults(doc, checkOnly) {
let items = {};
let found = false;
let rows = ZU.xpath(doc, '//div[@class="searchlist"]/a[b]');
for (let i=0; i<rows.length; i++) {
let href = rows[i].href;
let title = ZU.trimInternal(rows[i].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 (selected) {
if (!selected) {
return true;
}
ZU.processDocuments(Object.keys(selected), scrape);
});
} else {
scrape(doc, url);
}
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://caod.oriprobe.com/articles/found.htm?keyword=Chinese+pedagogy&package=&key_author=&key_qkname=&key_year=&key_volumn=&key_issue=",
"items": "multiple"
},
{
"type": "web",
"url": "http://caod.oriprobe.com/articles/53639734/Characteristics_and_influencing_factors_of_daily_p.htm",
"items": [
{
"itemType": "journalArticle",
"title": "Characteristics and influencing factors of daily physical activity in preschool children",
"creators": [
{
"firstName": "Hai-jun",
"lastName": "Wu",
"creatorType": "author"
},
{
"firstName": "Zhi-jun",
"lastName": "Tan",
"creatorType": "author"
},
{
"firstName": "Ying",
"lastName": "Liang",
"creatorType": "author"
},
{
"firstName": "Xun",
"lastName": "Jiang",
"creatorType": "author"
},
{
"firstName": "Tong",
"lastName": "Xu",
"creatorType": "author"
},
{
"firstName": "Hao",
"lastName": "Zhang",
"creatorType": "author"
},
{
"firstName": "Jing",
"lastName": "Yuan",
"creatorType": "author"
},
{
"firstName": "Lei",
"lastName": "Shang",
"creatorType": "author"
}
],
"date": "2018",
"abstractNote": "Objective To investigate the daily activities of preschool children in recent one month to learn the characteristics and influencing factors of the daily physical activity among preschool children,so as to provide references for daily physical activity intervention in preschool children.Methods Daily activities of target group in recent one month was investigated by using daily physical activities questionnaire designed for preschool children(3 -6 years old)by research group and filled by children's caregivers.Influencing factors of frequency and time of daily physical activity were analyzed using univariate and multivariate analysis methods.Results The questionnaire contained 22 items of physical activity.There were significant differences in participation rates of physical activity among children of different gender,age,residence,caregiver with different educational level and family with different number of children(all P<0.05).Frequency of high intensity physical activity in preschool children per week was 11.2 ± 6.5 times,moderate intensity activity 19.1 ± 12.3 times and low intensity activity 19.3 ± 10.1 times.Frequency of high intensity physical activity and time were related with caregiver's educational level(P<0.05),while frequency of moderate and low intensity physical activity and time were related with children's gender and caregiver's educational level(both P<0.05). Frequency of physical activity was higher and time was longer in girls than those in boys.Children having caregivers with college or higher educational level had higher physical activity frequency and longer activity time,compared with children having caregivers with junior high school or below educational level.Conclusion Physical activities of preschool children are mainly moderate and low intensity.Frequency and time of physical activity are related with children's gender and caregiver's educational level.",
"issue": "4",
"libraryCatalog": "caod.oriprobe.com",
"pages": "393-398",
"publicationTitle": "Chinese Journal of Woman and Child Health Research",
"url": "http://caod.oriprobe.com/articles/53639734/Characteristics_and_influencing_factors_of_daily_p.htm",
"volume": "29",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
{
"tag": "influencing factor"
},
{
"tag": "physical activity"
},
{
"tag": "preschool children"
},
{
"tag": "survey"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://caod.oriprobe.com/articles/52762114/Preadolescents__refusal_skills_and_responses_emoti.htm",
"items": [
{
"itemType": "journalArticle",
"title": "Preadolescents’ refusal skills and responses emotional reactions to the offer of tobacco and ecstasy in Youjiang District in Baise City in 2014",
"creators": [
{
"firstName": "Rui",
"lastName": "Guo",
"creatorType": "author"
},
{
"firstName": "Jianying",
"lastName": "Liao",
"creatorType": "author"
},
{
"firstName": "Jiancheng",
"lastName": "Liang",
"creatorType": "author"
},
{
"firstName": "Yang",
"lastName": "Li",
"creatorType": "author"
},
{
"firstName": "Shusong",
"lastName": "Deng",
"creatorType": "author"
},
{
"firstName": "Management and Health Public of",
"lastName": "School",
"creatorType": "author"
},
{
"firstName": "Nationalities for University Medical",
"lastName": "Youjiang",
"creatorType": "author"
}
],
"date": "2018",
"abstractNote": "Objective To assess preadolescents’ emotional reactions and intended use of refusal responses to tobacco and ecstasy. Methods A total of 333 students from two junior schools in Baise City were recruited with cluster-sampling method,filled the questionnaire to assess a respondent’s emotional reactions and refusal skills in response to an offer of tobacco and MDMA from Feb to Jul 2014. Results 88. 89%-93. 39% of preadolescents would more likely to use",
"issue": "1",
"libraryCatalog": "caod.oriprobe.com",
"pages": "80-84+92",
"publicationTitle": "Journal of Hygiene Research",
"url": "http://caod.oriprobe.com/articles/52762114/Preadolescents__refusal_skills_and_responses_emoti.htm",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
{
"tag": "drug offers"
},
{
"tag": "emotion"
},
{
"tag": "preadolescents"
},
{
"tag": "refusal"
}
],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/