-
Notifications
You must be signed in to change notification settings - Fork 0
/
Archeion.js
157 lines (116 loc) · 4.88 KB
/
Archeion.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
{
"translatorID":"f6717cbb-2771-4043-bde9-dbae19129bb3",
"translatorType":4,
"label":"Archeion",
"creator":"Adam Crymble",
"target":"http://archeion-aao",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2008-07-24 05:15:00"
}
function detectWeb(doc, url) {
if (doc.evaluate('//td[@class="full"]/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "multiple";
} else if (doc.evaluate('//div[@class="main"]/h1', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "book";
}
}
//Archeion translator. code by Adam Crymble
//The way the site is formatted, I can't split the creators up logically. I have left them off for now.
function associateData (newItem, dataTags, field, zoteroField) {
if (dataTags[field]) {
newItem[zoteroField] = dataTags[field];
}
}
function scrape(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
newItem = new Zotero.Item("book");
var xPathHeadings = doc.evaluate('//th', doc, nsResolver, XPathResult.ANY_TYPE, null);
var xPathContent = doc.evaluate('//table[@class="results"]/tbody/tr/td', doc, nsResolver, XPathResult.ANY_TYPE, null);
var xPathCount = doc.evaluate('count (//th)', doc, nsResolver, XPathResult.ANY_TYPE, null);
var fieldTitle;
var dataTags = new Object();
var multiAuthorCheck = new Array();
for (var i = 0; i < xPathCount.numberValue; i++) {
fieldTitle=xPathHeadings.iterateNext().textContent.replace(/\s+/g, '');
//This was Michael Berkowitz's suggested Fix.
/*var ts = doc.getElementsByTagName(("table"), 1) = ts.length, ar = [];
while ((i--)) {
if (ts[i].className&&ts[i].className.match("results")) {
ar[ar.length] = ts[i].getElementsByTagName("td")[0].split(/\<br\>/);
}
}
Zotero.debug(ar[0][0]); */
//COULDN"T SPLIT BY ("\n") TO SEPARATE MULTIPLE CREATORS.
if (fieldTitle == "Creator:" | fieldTitle == "Créateur:") {
fieldTitle == "Creator:";
var authorContent = xPathContent.iterateNext().textContent;
//Zotero.debug(authorContent);
//if (authorContent.match(' (*) ')) {
// Zotero.debug(doc.title);
//}
//var test = authorContent.split(/\<br\>/);
//Zotero.debug(test);
authors = authorContent.match(/\w+,?\s+[\w\(\)\.]+/g);
//Zotero.debug(authors);
for (i = 0; i < authors.length; i++) {
var author = authors[i].split(", ");
if (author.length < 2) {
dataTags["Creator:"] = author[0];
newItem.creators.push({lastName: dataTags["Creator:"], creatorType: "creator"});
} else {
dataTags["Creator:"] = (author[1] + (" ") + author[0]);
//Zotero.debug(authorArranged);
newItem.creators.push(Zotero.Utilities.cleanAuthor(dataTags["Creator:"], "creator"));
}
}
} else {
dataTags[fieldTitle] = Zotero.Utilities.cleanTags(xPathContent.iterateNext().textContent);
//Zotero.debug(fieldTitle);
}
}
associateData (newItem, dataTags, "Datesofmaterial:", "date");
associateData (newItem, dataTags, "Repository:", "repository");
associateData (newItem, dataTags, "ReferenceNumber:", "callNumber");
associateData (newItem, dataTags, "PhysicalDescription:", "extra");
associateData (newItem, dataTags, "Scopeandcontent", "abstractNote");
associateData (newItem, dataTags, "Dates:", "date");
associateData (newItem, dataTags, "Centred'archives:", "repository");
associateData (newItem, dataTags, "Numéroderéférence:", "callNumber");
associateData (newItem, dataTags, "Descriptionmatérielle:", "extra");
associateData (newItem, dataTags, "Portéeetcontenu", "abstractNote");
newItem.title = doc.evaluate('//h1', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
newItem.url = doc.location.href;
newItem.complete();
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var xPathLinks = doc.evaluate('//td[@class="full"]/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
var linksCounter = doc.evaluate('count (//td[@class="full"]/a)', doc, nsResolver, XPathResult.ANY_TYPE, null);
var xPathTitles = doc.evaluate('//table[@class="results"]/tbody/tr[1]/td', doc, nsResolver, XPathResult.ANY_TYPE, null);
var next_link;
for (var i = 0; i < linksCounter.numberValue; i++) {
next_link = xPathLinks.iterateNext().href;
items[next_link] = xPathTitles.iterateNext().textContent;
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
} else {
articles = [url];
}
Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
Zotero.wait();
}