forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdref.js
107 lines (92 loc) · 3.04 KB
/
Idref.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
{
"translatorID": "271ee1a5-da86-465b-b3a5-eafe7bd3c156",
"label": "Idref",
"creator": "Sylvain Machefert",
"target": "^https?://www\\.idref\\.fr/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2018-02-12 13:03:06"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2018 Sylvain Machefert
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 (ZU.xpathText(doc, '//div[@class="detail_bloc_biblio"]') && getSearchResults(doc, true)) {
return "multiple";
}
}
function getSearchResults(doc, checkOnly) {
var resultsTitle = ZU.xpath(doc, '//div[@id="perenne-references-docs"]/span[contains(@class, "detail_value")]');
var resultsHref = ZU.xpath(doc, '//div[@id="perenne-references-docs"]/span[contains(@class, "detail_label")]/a/@href');
var found = false;
items = {};
for (let i=0; i<resultsTitle.length; i++) {
href = resultsHref[i].textContent;
// We need to replace the http://www.sudoc.fr/XXXXXX links are they are redirects and aren't handled correctly from subtranslator
href = href.replace(/http:\/\/www\.sudoc\.fr\/(.*)$/, "http://www.sudoc.abes.fr/xslt/DB=2.1//SRCH?IKT=12&TRM=$1");
if ( (href.includes("www.sudoc.abes.fr")) || (href.includes("archives-ouvertes")) ) {
if (checkOnly) return true;
found = true;
items[href] = resultsTitle[i].textContent;
}
}
return found ? items : false;
}
function doWeb(doc, url)
{
Zotero.selectItems(getSearchResults(doc, false), function (selectedItems) {
if (!selectedItems) {
return true;
}
var articles = [];
for (var i in selectedItems) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
}
function scrape(doc, url) {
var translator = Zotero.loadTranslator('web');
if (url.includes("archives-ouvertes")){
// HAL Archives ouvertes
translator.setTranslator('58ab2618-4a25-4b9b-83a7-80cd0259f896');
} else if (url.includes("sudoc.abes.fr")) {
// Sudoc
translator.setTranslator('1b9ed730-69c7-40b0-8a06-517a89a3a278');
} else {
Z.debug("Undefined website");
return false;
}
translator.setHandler('itemDone', function (obj, item) {
item.complete();
});
translator.getTranslatorObject(function(trans) {
trans.doWeb(doc, url);
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.idref.fr/199676100",
"items": "multiple"
}
]
/** END TEST CASES **/