forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNKI.js
787 lines (721 loc) · 21.4 KB
/
CNKI.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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
{
"translatorID":"5c95b67b-41c5-4f55-b71a-48d5d7183063",
"label":"CNKI",
"creator":"Ace Strong <[email protected]> and Heromyth <[email protected]>",
"target":"^https?://(?:(?:(dlib|epub|acad|apj1|law1|www)\\.cnki\\.net)|(?:[0-9\\.]+))/(?:grid2008|kns50|Kns55|kcms)",
"minVersion":"2.0rc1",
"maxVersion":"",
"priority":100,
"inRepository":"1",
"translatorType":4,
"lastUpdated":"2010-12-10 14:32:46"
}
/*
CNKI(China National Knowledge Infrastructure) Translator
Copyright (C) 2009-2010 TAO Cheng, [email protected]
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/>.
*/
// #######################
// ##### Sample URLs #####
// #######################
/*
* The starting point for an search is the URL below.
* In testing, I tried the following:
*
* - A search listing of journals
* - A search listing of phd thesis
* - A search listing of master thesis
* - A search listing of conference papers
* - A search listing of newspaper articles
* - A journal paper page
* - A phd thesis page
* - A master thesis page
* - A conference paper page
* - A newspaper article page
*/
// http://epub.cnki.net/grid2008/index/ZKCALD.htm
// #################################
// #### Local utility functions ####
// #################################
function detectCode(url) {
var pattern = /(?:dbcode|dbname)=([A-Za-z]{4})/i;
if (pattern.test(url)) {
var code = pattern.exec(url)[1];
return code;
} else {
// parse from source page
var page = Zotero.Utilities.retrieveSource(url);
pattern = /id="nowdbname"[^>]*?>(.*?)<\/SPAN>/i;
if (pattern.test(page)) {
var dbname = pattern.exec(page)[1];
// Zotero.debug(dbname);
if (dbname == "中国期刊全文数据库") {
return "CJFD";
}
}
}
return "NONE";
}
function getResolver(doc) {
var namespace, resolver;
namespace = doc.documentElement.namespaceURI;
if (namespace) {
resolver = function(prefix) {
if (prefix == 'x') {
return namespace;
} else {
return null;
}
};
} else {
resolver = null;
}
return resolver;
}
function trimTags(text) {
var pattern = /(<.*?>)/g;
text = text.replace(pattern, "");
return text;
}
function trimMultiline(text) {
var pattern = /(\s{2,})/g;
text = text.replace(pattern, "\n");
return text;
}
// #############################
// ##### Scraper functions #####
// #############################
// work for journalArticle
function scrapeAndParse1(url) {
// Zotero.debug("journalArticle");
Zotero.Utilities.doGet(url, function(page) {
var pattern;
// 类型 & URL
var itemType = "journalArticle";
var newItem = new Zotero.Item(itemType);
// Zotero.debug(url);
newItem.url = url;
// 标题/Title
pattern = /<span (?:id="chTitle"|class='datatitle')>(.*?)<\/span>/;
if (pattern.test(page)) {
var title = trimTags(pattern.exec(page)[1]);
newItem.title = title;
// Zotero.debug("title: "+title);
}
// 作者/Authors
var authorNames;
pattern = /【作者】(?:[\s\S]*?)GetLinkListEx\('(.*?);','/;
if (pattern.test(page)) {
authorNames = pattern.exec(page)[1].split(";");
} else {
pattern = /【作者】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
authorNames = trimTags(pattern.exec(page)[1]).split(";");
}
}
if (authorNames) {
for (var i=0; i<authorNames.length; i++) {
var authorName = Zotero.Utilities.trim(authorNames[i]);
if (authorName.length > 0) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(authorNames[i],
"author", true));
}
}
// Zotero.debug("authorNames:\n"+authorNames);
}
// 摘要/Abstract
var abst;
pattern = /【摘要】\s*<[^>]*>(.*?)<\/span>/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
} else {
pattern = /【摘要】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
}
}
if (abst) {
// Zotero.debug("abstract:\n"+abst);
newItem.abstractNote = Zotero.Utilities.trim(abst);
}
pattern = /【Abstract】\s*<[^>]*>(.*?)<\/span>/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
} else {
pattern = /【英文摘要】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
}
}
if (abst) {
// Zotero.debug("abstract:\n"+abst);
if (newItem.abstractNote===undefined) {
newItem.abstractNote = Zotero.Utilities.trim(abst);
} else {
newItem.abstractNote = newItem.abstractNote + "\n"
+ Zotero.Utilities.trim(abst);
}
}
// Zotero.debug(newItem.abstractNote);
// 关键词/Keywords
var tags;
pattern = /【关键词】(?:[\s\S]*?)KeywordFilter\('(.*?)'\),'kw'/;
if (pattern.test(page)) {
tags = pattern.exec(page)[1].split(";");
} else {
pattern = /【(?:中文)?关键词】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
tags = trimTags(pattern.exec(page)[1]).split(";");
}
}
if (tags) {
for (var i=0; i<tags.length; i++) {
var tag = Zotero.Utilities.trim(tags[i]);
if (tag.length>0 && newItem.tags.indexOf(tag)<0) {
newItem.tags.push(tag);
}
}
// Zotero.debug("tags:\n"+tags);
}
pattern = /【Key words】(?:[\s\S]*?)GetLinkList\('(.*?)','kw'/;
if (pattern.test(page)) {
tags = pattern.exec(page)[1].split(";");
} else {
pattern = /【英文关键词】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
tags = trimTags(pattern.exec(page)[1]).split(";");
}
}
if (tags) {
for (var i=0; i<tags.length; i++) {
var tag = Zotero.Utilities.trim(tags[i]);
if (tag.length>0 && newItem.tags.indexOf(tag)<0) {
newItem.tags.push(tag);
}
}
// Zotero.debug("tags:\n"+tags);
}
// 文献出处 & DOI & 出版时间
pattern = /【(?:文献出处|刊名)】([\s\S]*?)<\/a>/;
if (pattern.test(page)) {
var publicationTitle = trimTags(pattern.exec(page)[1]);
newItem.publicationTitle = Zotero.Utilities.trim(publicationTitle);
// Zotero.debug("publicationTitle: "+publicationTitle);
}
var doi;
pattern = /【DOI】(.*?)<\/li>/;
if (pattern.test(page)) {
doi= pattern.exec(page)[1];
} else {
pattern = /【DOI】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
doi= trimTags(pattern.exec(page)[1]);
}
}
if (doi) {
newItem.DOI = Zotero.Utilities.trim(doi);
// Zotero.debug("doi: "+doi);
}
pattern = /【(?:文献出处|刊名)】(?:[\s\S]*?)(\d{4})年\s*([0-9A-Z]{2})(卷|期)/;
if (pattern.test(page)) {
var date = pattern.exec(page)[1];
newItem.date = date;
var val = pattern.exec(page)[2];
var attr = pattern.exec(page)[3];
if (attr == "卷") {
newItem.volume = val;
} else {
newItem.issue = val;
}
// Zotero.debug("date: "+date);
// Zotero.debug("val: "+val);
// Zotero.debug("attr: "+attr);
}
newItem.complete();
});
}
// work for thesis
function scrapeAndParse2(url) {
// Zotero.debug("thesis");
Zotero.Utilities.doGet(url, function(page) {
var pattern;
// 类型 & URL
var itemType = "thesis";
var newItem = new Zotero.Item(itemType);
// Zotero.debug(url);
newItem.url = url;
var code = detectCode(url);
if (code == "CDFD") {
newItem.thesisType = "博士论文"
} else {
newItem.thesisType = "硕士论文"
}
// Zotero.debug(newItem.thesisType);
// 标题/Title
pattern = /<span (?:id="chTitle"|class='datatitle')>(.*?)<\/span>/;
if (pattern.test(page)) {
var title = pattern.exec(page)[1];
pattern = /(<.*?>)/g;
title = title.replace(pattern, "");
newItem.title = title;
// Zotero.debug("title: "+title);
}
// 作者/Author
pattern = /【作者】([\s\S]*?)<\/a>/;
if (pattern.test(page)) {
var authorNames = trimTags(pattern.exec(page)[1]).split(";");
for (var i=0; i<authorNames.length; i++) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(authorNames[i],
"author", true));
}
// Zotero.debug("authorNames:\n"+authorNames);
}
// 导师/Tutors
pattern = /【导师】([\s\S]*?)<\/a>/;
if (pattern.test(page)) {
var directors = trimTags(pattern.exec(page)[1]).split(";");
for (var i=0; i<directors.length; i++) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(trimTags(directors[i]),
"director", true));
}
// Zotero.debug("directors: "+directors);
}
// 摘要/Abstract
var abst;
pattern = /ReplaceFont\('ChDivSummary','(.*?)(?='\);ReplaceFont)/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
} else {
pattern = /【中文摘要】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
}
}
if (abst) {
// Zotero.debug("abstract:\n"+abst);
newItem.abstractNote = trimMultiline(abst);
}
pattern = /ReplaceFont\('EnDivSummary','(.*?)(?='\);if)/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
} else {
pattern = /【英文摘要】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
abst = trimTags(pattern.exec(page)[1]);
}
}
if (abst) {
// Zotero.debug("abstract:\n"+abst);
if (newItem.abstractNote===undefined) {
newItem.abstractNote = Zotero.Utilities.trim(abst);
} else {
newItem.abstractNote = newItem.abstractNote + "\n"
+ trimMultiline(abst);
}
}
// Zotero.debug(newItem.abstractNote);
// 关键词/Keywords
var tags;
pattern = /【关键词】\s*<span[^>]*>(.*?)<\/a>*<\/span>/;
if (pattern.test(page)) {
tags = trimTags(pattern.exec(page)[1]).split(";");
} else {
pattern = /【关键词】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
tags = trimTags(pattern.exec(page)[1]).split(";");
}
}
if (tags) {
for (var i=0; i<tags.length; i++) {
var tag = Zotero.Utilities.trim(tags[i]);
if (tag.length>0 && newItem.tags.indexOf(tag)<0) {
newItem.tags.push(tag);
}
}
// Zotero.debug("tags:\n"+tags);
}
pattern = /【Key words】\s*<span[^>]*>(.*?)<\/a>*<\/span>/;
if (pattern.test(page)) {
tags = trimTags(pattern.exec(page)[1]).split(";");
} else {
pattern = /【英文关键词】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
tags = trimTags(pattern.exec(page)[1]).split(";");
}
}
if (tags) {
for (var i=0; i<tags.length; i++) {
var tag = Zotero.Utilities.trim(tags[i]);
if (tag.length>0 && newItem.tags.indexOf(tag)<0) {
newItem.tags.push(tag);
}
}
// Zotero.debug("tags:\n"+tags);
}
// Zotero.debug(newItem.tags);
// 出版学校 & DOI & 出版时间
var university;
pattern = /【网络出版投稿人】\s*<a[^>]*>(.*?)<\/a>/;
if (pattern.test(page)) {
university = pattern.exec(page)[1];
} else {
pattern = /【网络出版投稿人】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
university = Zotero.Utilities.trim(
trimTags(pattern.exec(page)[1]));
}
}
if (university) {
pattern = /(.*?)((.*?))/;
if (pattern.test(university)) {
newItem.university = pattern.exec(university)[1];
newItem.place = pattern.exec(university)[2];
} else {
newItem.publisher = university;
}
// Zotero.debug("university: "+university);
}
var doi;
pattern = /【DOI】(.*?)<\/li>/;
if (pattern.test(page)) {
doi= pattern.exec(page)[1];
} else {
pattern = /【DOI】([\s\S]*?)<\/tr>/;
if (pattern.test(page)) {
var doi= trimTags(pattern.exec(page)[1]);
}
}
if (doi) {
newItem.DOI = Zotero.Utilities.trim(doi);
// Zotero.debug("doi: "+doi);
}
var date;
pattern = /【网络出版投稿时间】(.*?)\s*<\/li>/;
if (pattern.test(page)) {
date = pattern.exec(page)[1];
} else {
pattern = /【网络出版投稿时间】([\s\S]*?)\s*<\/tr>/;
if (pattern.test(page)) {
date = trimTags(pattern.exec(page)[1]);
}
}
if (date) {
newItem.date = Zotero.Utilities.trim(date);
// Zotero.debug("date: "+date);
}
newItem.complete();
});
}
// work for conferencePaper
function scrapeAndParse3(url) {
// Zotero.debug("conferencePaper");
Zotero.Utilities.doGet(url, function(page) {
var pattern;
// 类型 & URL
var itemType = "conferencePaper";
var newItem = new Zotero.Item(itemType);
// Zotero.debug(url);
newItem.url = url;
// 标题/Title
pattern = /<span id="chTitle">(.*?)<\/span>/;
if (pattern.test(page)) {
var title = trimTags(pattern.exec(page)[1]);
newItem.title = title;
// Zotero.debug("title: "+title);
}
// 作者/Authors
pattern = /【作者】(.*?)<\/p>/;
if (pattern.test(page)) {
var authorNames = trimTags(pattern.exec(page)[1]).split(";");
for (var i=0; i<authorNames.length; i++) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(
Zotero.Utilities.trim(authorNames[i]),
"author", true));
}
// Zotero.debug("authorNames:\n"+authorNames);
}
// 摘要/Abstract
var abst;
pattern = /ReplaceFont\('ChDivSummary','(.*?)(?='\);ReplaceFont)/;
if (pattern.test(page)) {
abst = pattern.exec(page)[1];
// Zotero.debug("raw:\n"+abst);
pattern = /(<.*?>)/g;
abst = abst.replace(pattern, "");
// Zotero.debug("after:\n"+abst);
newItem.abstractNote = Zotero.Utilities.trim(abst);
}
pattern = /ReplaceFont\('EnDivSummary','(.*?)(?='\);if)/;
if (pattern.test(page)) {
abst = pattern.exec(page)[1];
// Zotero.debug("raw:\n"+abst);
if (abst != undefined && abst != null) {
pattern = /(<.*?>)/g;
abst = abst.replace(pattern, "");
// Zotero.debug("after:\n"+abst);
if (newItem.abstractNote===undefined) {
newItem.abstractNote = Zotero.Utilities.trim(abst);
} else {
newItem.abstractNote = newItem.abstractNote + "\n"
+ Zotero.Utilities.trim(abst);
}
}
}
// Zotero.debug("abst:\n"+newItem.abstractNote);
// 关键词/Keywords
pattern = /【关键词】\s*<span[^>]*>(.*?)<\/a>*<\/span>/;
if (pattern.test(page)) {
var tags = trimTags(pattern.exec(page)[1]).split(";");
for (var i=0; i<tags.length; i++) {
var tag = Zotero.Utilities.trim(tags[i]);
if (tag.length>0 && newItem.tags.indexOf(tag)<0) {
newItem.tags.push(tag);
}
}
// Zotero.debug("tags:\n"+tags);
}
pattern = /【Key words】\s*<span[^>]*>(.*?)<\/a>*<\/span>/;
if (pattern.test(page)) {
var tags = trimTags(pattern.exec(page)[1]).split(";");
for (var i=0; i<tags.length; i++) {
var tag = Zotero.Utilities.trim(tags[i]);
if (tag.length>0 && newItem.tags.indexOf(tag)<0) {
newItem.tags.push(tag);
}
}
// Zotero.debug("tags:\n"+tags);
}
// Zotero.debug(newItem.tags);
// 会议名称 & 会议录名称 & 会议地点 & 会议时间
pattern = /【会议名称】(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var conferenceName = trimTags(pattern.exec(page)[1]);
newItem.conferenceName = conferenceName;
// Zotero.debug("conferenceName: "+conferenceName);
}
pattern = /【会议录名称】(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var proceedingsTitle = trimTags(pattern.exec(page)[1]);
newItem.proceedingsTitle = proceedingsTitle;
// Zotero.debug("proceedingsTitle: "+proceedingsTitle);
}
pattern = /【会议地点】(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var place = trimTags(pattern.exec(page)[1]);
newItem.place = place;
// Zotero.debug("place: "+place);
}
pattern = /【会议时间】(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var date = trimTags(pattern.exec(page)[1]);
newItem.date = date;
// Zotero.debug("date: "+date);
}
newItem.complete();
});
}
// work for newspaperArticle
function scrapeAndParse4(url) {
// Zotero.debug("newspaperArticle");
Zotero.Utilities.doGet(url, function(page) {
var pattern;
// 类型 & URL
var itemType = "newspaperArticle";
var newItem = new Zotero.Item(itemType);
// Zotero.debug(url);
newItem.url = url;
// 标题/Title
pattern = /<span id="chTitle">(.*?)<\/span>/;
if (pattern.test(page)) {
var title = trimTags(pattern.exec(page)[1]);
newItem.title = title;
// Zotero.debug("title: "+title);
}
// 副标题/引题
var shortTitle;
pattern = /<p>【(?:副标题|引题)】(.*?)(?=<\/p>)/;
if (pattern.test(page)) {
shortTitle = pattern.exec(page)[1];
// Zotero.debug("shortTitle: "+shortTitle);
newItem.shortTitle = Zotero.Utilities.trimInternal(shortTitle);
}
// Zotero.debug(newItem.shortTitle);
// 作者/Authors
pattern = /【作\s*者】(.*?)<\/p>/;
if (pattern.test(page)) {
var authorNames = trimTags(pattern.exec(page)[1]).split(";");
for (var i=0; i<authorNames.length; i++) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(
Zotero.Utilities.trim(authorNames[i]),
"author", true));
}
// Zotero.debug("authorNames:\n"+authorNames);
}
// 正文快照/Abstract
var abst;
pattern = /<p>【正文快照】(.*?)(?=<\/p>)/;
if (pattern.test(page)) {
abst = pattern.exec(page)[1];
// Zotero.debug("abst:\n"+abst);
newItem.abstractNote = Zotero.Utilities.trimInternal(abst);
}
// Zotero.debug(newItem.abstractNote);
// 报纸名称 & DOI & 出版时间 & 版名 & 版号
pattern = /【报纸名称】\s*<[^>]*>(.*?)<\/a>/;
if (pattern.test(page)) {
var publicationTitle = trimTags(pattern.exec(page)[1]);
newItem.publicationTitle = publicationTitle;
// Zotero.debug("publicationTitle: "+publicationTitle);
}
pattern = /【DOI】\s*(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var doi = pattern.exec(page)[1];
newItem.DOI = doi;
// Zotero.debug("doi: "+doi);
}
pattern = /【报纸日期】\s*(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var date = pattern.exec(page)[1];
newItem.date = date;
// Zotero.debug("date: "+date);
}
pattern = /【版名】\s*(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var section = pattern.exec(page)[1];
newItem.section = section;
// Zotero.debug("section: "+section);
}
pattern = /【版号】\s*(.*?)\s*<\/li>/;
if (pattern.test(page)) {
var edition = pattern.exec(page)[1];
newItem.edition = edition;
// Zotero.debug("edition: "+edition);
}
newItem.complete();
});
}
// #########################
// ##### API functions #####
// #########################
function detectWeb(doc, url) {
var pattern = /detail.aspx/;
if (pattern.test(url)) {
var code = detectCode(url).toUpperCase();
// Zotero.debug(code);
if (code == "CJFQ" || code == "CJFD") {
return "journalArticle";
} else if (code == "CDFD") {
return "thesis";
} else if (code == "CMFD" || code == "CLKM") {
return "thesis";
} else if (code == "CPFD") {
return "conferencePaper";
} else if (code == "CCND") {
return "newspaperArticle";
} else if (code == "NONE") {
Zotero.debug("Not support yet.");
}
}
pattern = /brief/;
if (pattern.test(url)) {
return "multiple"
}
return false;
}
function doWeb(doc, url) {
var nsResolver = getResolver(doc);
var urls, tds, pages;
// Zotero.debug(url);
if (detectWeb(doc, url) == "multiple") {
// Zotero.debug("Enter multiple.");
// search page
var items = new Array();
var xpath = '//iframe[@id="iframeResult"]';
var iframe = doc.evaluate(xpath, doc, nsResolver,
XPathResult.ANY_TYPE, null).iterateNext();
if (iframe) {
// fetch iframe's element
// Zotero.debug(iframe.src);
pages = Zotero.Utilities.retrieveSource(iframe.src);
} else {
// already in iframe
// Zotero.debug("url:"+url);
pages = Zotero.Utilities.retrieveSource(url);
}
pattern = /<tr class=["']GTContentTitle["']>[\s\S]*?<\/tr>([\s\S]*?)<table class=["']pageBar_bottom["']/;
var content;
try {
content = pattern.exec(pages)[1];
// Zotero.debug(content);
pattern = /<\/table>[\s\S]*?<a href=["'](.*?)["'][^>]*?><script[\s\S]*?(?:Replace[^\(]*?\()'(.*?)'\)/g;
} catch (err) {
content = pages;
pattern = /<div class=["']GridTitleDiv["']>.*?<a href=["'](.*?)["'][^>]*?><script[\s\S]*?(?:Replace[^\(]*?\()'(.*?)'\)/g;
}
var res = pattern.exec(content);
if (!res) {
pattern = /<div class=["']GridTitleDiv["']>.*?<a href=["'](.*?)["'][^>]*?>(.*?)<\/a>/g;
res = pattern.exec(content);
if (!res) {
pattern = /<\/table>[\s\S]*?<a href=["'](.*?)["'][^>]*?>(.*?)<\/a>/g;
res = pattern.exec(content);
}
}
var link;
var title;
while (res) {
title = Zotero.Utilities.cleanTags(res[2]);
link = res[1];
patt = /^(http:\/\/.*?)\//;
link = patt.exec(url)[1] + link;
items[link] = trimTags(title);
// Zotero.debug("title:"+title);
// Zotero.debug("link:"+link);
res = pattern.exec(content);
}
// Zotero.debug(items);
if (items.__count__) {
// 让用户选择要保存哪些文献
items = Zotero.selectItems(items);
if (!items) return true;
urls = new Array();
for (var url in items) {
urls.push(url);
}
}
} else {
urls = [url];
}
if (urls) {
// Zotero.debug(urls);
for (var i=0; i<urls.length; i++) {
var type = detectWeb(null, urls[i]);
// Zotero.debug(type);
if (type == "journalArticle") {
scrapeAndParse1(urls[i]);
} else if (type == "thesis") {
scrapeAndParse2(urls[i]);
} else if (type == "conferencePaper") {
scrapeAndParse3(urls[i]);
} else if (type == "newspaperArticle") {
scrapeAndParse4(urls[i]);
} else {
Zotero.debug("Not supported type.");
}
}
}
}