forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAIRN Info.js
111 lines (100 loc) · 3.32 KB
/
CAIRN Info.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
{
"translatorID": "f46cc903-c447-47d6-a2cf-c75ed22dc96b",
"label": "CAIRN Info",
"creator": "Sebastian Karcher",
"target": "^https?://www\\.cairn\\.info/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-04-17 03:09:28"
}
/*
Translator
Copyright (C) 2013 Sebastian Karcher
This program 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.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function detectWeb(doc,url) {
var xpath='//meta[@name="citation_journal_title"]';
if (ZU.xpath(doc, xpath).length > 0) {
return "journalArticle";
}
if (ZU.xpathText(doc, '//div[@class="content"]//div[@class="specs"]/div[@class="title" or contains(@class, "articleBookList")]')) {
return "multiple";
}
return false;
}
function doWeb(doc,url)
{
if (detectWeb(doc, url) == "multiple") {
var hits = {};
var urls = [];
var title;
var link;
var resultsrow = ZU.xpath(doc, '//div[@class="content"]//div[@class="specs"]/div[contains(@class, "articleBookList")]');
if (resultsrow.length <1){
var resultsrow = ZU.xpath(doc, '//div[@class="content"]//div[@class="specs"]');
Z.debug(resultsrow.length)
}
for (var i in resultsrow) {
title = ZU.xpathText(resultsrow[i], './div[@class="bookDescription"]/div[@class="title"]');
if (!title){
title = ZU.xpathText(resultsrow[i], './div[@class="title"]/text()');
}
link = ZU.xpathText(resultsrow[i], './/div[@class="links"]/span[@class="St1LIGNE" or @class="StRES"][1]/a/@href');
//Z.debug(title + ": " + link)
hits[link] = title.replace(/^[\s\,]+/, "").trim();
}
Z.selectItems(hits, function(items) {
if (items == null) return true;
for (var j in items) {
urls.push(j);
}
ZU.processDocuments(urls, function (myDoc) {
doWeb(myDoc, myDoc.location.href) });
});
} else {
// We call the Embedded Metadata translator to do the actual work
var translator = Zotero.loadTranslator("import");
translator.setTranslator("951c027d-74ac-47d4-a107-9c3069ab7b48");
translator.setHandler("itemDone", function(obj, item) {
item.tags= [];
var keywords = ZU.xpathText(doc, '//meta[@name="citation_keyword"]/@content');
if (keywords) keywords = keywords.split(/\s*[,;]\s*/);
for (i in keywords){
if (keywords[i].search(/[^\s]/) != -1){
tags.push(keywords[i])
}
}
item.complete();
});
translator.getTranslatorObject(function (obj) {
obj.doWeb(doc, url);
});
}
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.cairn.info/revue-d-economie-du-developpement-2012-4.htm",
"items": "multiple"
},
{
"type": "web",
"url": "http://www.cairn.info/resultats_recherche.php?searchTerm=artiste",
"items": "multiple"
}
]
/** END TEST CASES **/