This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary Catalog (DRA).js
88 lines (79 loc) · 2.5 KB
/
Library Catalog (DRA).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
{
"translatorID": "fb12ae9e-f473-cab4-0546-27ab88c64101",
"label": "Library Catalog (DRA)",
"creator": "Simon Kornblith",
"target": "/web2/tramp2\\.exe/(?:see\\_record/|authority\\_hits/|do_keyword_search|form/|goto/.*\\?.*screen=(MARC)?Record\\.html)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 260,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsbv",
"lastUpdated": "2014-08-26 03:57:40"
}
/* No more libraries with permalinks that I know of
sample URLs: http://libraries.nc-pals.org
http://web2.libraries.vermont.gov/web2/tramp2.exe/log_in?SETTING_KEY=English
*/
function detectWeb(doc, url) {
if(doc.location.href.search(/\/authority_hits|\/form\//) > 0) {
return "multiple";
} else {
return "book";
}
}
function doWeb(doc, url) {
var checkItems = false;
if(detectWeb(doc, url)== "multiple") {
checkItems = Zotero.Utilities.gatherElementsOnXPath(doc, doc, "//ol//tr/td|//ol/li//ul/li", null);
}
if(checkItems && checkItems.length) {
var items = Zotero.Utilities.getItemArray(doc, checkItems, 'https?://.*/web2/tramp2\.exe/(goto|see\_record)');
uris=[];
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var i in items) {
uris.push(i);
}
scrape(uris)
});
} else {
if (url.indexOf("/do_keyword_search/")!=-1){
url = "http://" + doc.location.host + ZU.xpathText(doc, '//td[@class="enrichcontent"]/a[contains(@href, "MARCRecord")]/@href');
}
scrape([url]);
}
}
function scrape(uris){
for(var i in uris) {
var uri = uris[i];
var uriRegexp = /^(https?:\/\/.*\/web2\/tramp2\.exe\/)(?:goto|see\_record|authority\_hits)(\/.*)\?(?:screen=Record\.html\&)?(.*)$/i;
var m = uriRegexp.exec(uri);
if(uri.indexOf("/authority_hits") < 0) {
var newUri = m[1]+"download_record"+m[2]+"/RECORD.MRC?format=marc&"+m[3];
} else {
var newUri = m[1]+"download_record"+m[2]+"/RECORD.MRC?format=marc";
}
// Keep track of how many requests have been completed
var j = 0;
var translator = Zotero.loadTranslator("import");
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
var domain = uri.match(/https?:\/\/([^/]+)/);
translator.setHandler("itemDone", function(obj, item) {
item.repository = domain[1]+" Library Catalog";
item.complete();
});
Zotero.Utilities.HTTP.doGet(newUri, function(text) {
translator.setString(text);
translator.translate();
j++;
if(j == uris.length) {
Zotero.done();
}
});
}
}/** BEGIN TEST CASES **/
var testCases = []
/** END TEST CASES **/