forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgencia del ISBN.js
95 lines (92 loc) · 3.29 KB
/
Agencia del ISBN.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
{
"translatorID": "b8a86e36-c270-48c9-bdd1-22aaa167ef46",
"label": "Agencia del ISBN",
"creator": "Michael Berkowitz",
"target": "^https?://www\\.mcu\\.es/webISBN",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "g",
"lastUpdated": "2011-10-20 00:53:36"
}
function detectWeb(doc, url) {
if (doc.evaluate('//div[@class="isbnResultado"]/div[@class="isbnResDescripcion"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "multiple";
} else if (doc.evaluate('//div[@class="fichaISBN"]/div[@class="cabecera"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "book";
}
}
function doWeb(doc, url) {
var books = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var boxes = doc.evaluate('//div[@class="isbnResultado"]/div[@class="isbnResDescripcion"]', doc, null, XPathResult.ANY_TYPE, null);
var box;
while (box = boxes.iterateNext()) {
var book = doc.evaluate('./p/span/strong/a', box, null, XPathResult.ANY_TYPE, null).iterateNext();
items[book.href] = book.textContent;
}
items = Zotero.selectItems(items);
for (var i in items) {
books.push(i);
}
} else {
books = [url];
}
Zotero.Utilities.processDocuments(books, function(newDoc) {
var data = new Object();
var rows = newDoc.evaluate('//div[@class="fichaISBN"]/table/tbody/tr', newDoc, null, XPathResult.ANY_TYPE, null);
var next_row;
while (next_row = rows.iterateNext()) {
var heading = newDoc.evaluate('./th', next_row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var value = newDoc.evaluate('./td', next_row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
data[heading.replace(/\W/g, "")] = value;
}
var isbn = Zotero.Utilities.trimInternal(newDoc.evaluate('//span[@class="cabTitulo"]/strong', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
var item = new Zotero.Item("book");
item.ISBN = isbn;
item.title = Zotero.Utilities.trimInternal(data['Ttulo']);
author = data['Autores'];
if (author) {
var authors = author.match(/\b.*,\s+\w+[^([]/g);
for each (aut in authors) {
item.creators.push(Zotero.Utilities.cleanAuthor(Zotero.Utilities.trimInternal(aut), "author", true));
}
}
if (data['Publicacin']) item.publisher = Zotero.Utilities.trimInternal(data['Publicacin']);
if (data['FechaEdicin']) item.date = Zotero.Utilities.trimInternal(data['FechaEdicin']);
item.complete();
}, function() {Zotero.done();});
Zotero.wait();
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.mcu.es/webISBN/tituloDetalle.do?sidTitul=1696742&action=busquedaInicial&noValidating=true&POS=0&MAX=50&TOTAL=0&prev_layout=busquedaisbn&layout=busquedaisbn&language=es",
"items": [
{
"itemType": "book",
"creators": [
{
"firstName": "Adrian",
"lastName": "Fernández García",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"ISBN": "978-84-9934-054-8",
"title": "Argentina : causas y efectos de la crisis económica",
"publisher": "Tutorial Formación, S.L.L.",
"date": "10/2009",
"libraryCatalog": "Agencia del ISBN",
"shortTitle": "Argentina"
}
]
}
]
/** END TEST CASES **/