-
Notifications
You must be signed in to change notification settings - Fork 0
/
Engineering Village.js
125 lines (110 loc) · 3.56 KB
/
Engineering Village.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
{
"translatorID":"1f40baef-eece-43e4-a1cc-27d20c0ce086",
"translatorType":4,
"label":"Engineering Village",
"creator":"Ben Parr",
"target":"^https?://(?:www\\.)?engineeringvillage(2)?\\.(?:com|org)",
"minVersion":"1.0.0b4.r1",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2007-07-31 19:40:00"
}
function detectWeb(doc, url)
{
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var xpath='//a[img/@style="vertical-align: middle;"][@href]';
if(doc.evaluate(xpath, doc,
nsResolver,XPathResult.ANY_TYPE,null).iterateNext())
{ return "journalArticle";}
xpath='//input[@name="cbresult"]/@onclick';
if(doc.evaluate(xpath, doc,
nsResolver,XPathResult.ANY_TYPE,null).iterateNext())
{ return "multiple";}
return null;
}
function parseRIS(uris)
{
Zotero.Utilities.HTTP.doGet(uris, function(text){
// load translator for RIS
var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
translator.translate();
Zotero.done();
}, function() {});
Zotero.wait();
}
//creates the link to the RIS file
function createURL(EISESSION,docidlist,curURL)
{
var milli = (new Date()).getTime();
var temp = curURL.split('/');
var url = temp.slice(0,temp.length-1).join('/') + "/Controller?EISESSION="+EISESSION;
url+="&CID=downloadSelectedRecordsris&format=ris&displayformat=fullDoc×tamp="
url+=milli;
url+="&docidlist=";
url+=docidlist;
url+="&handlelist=1";
return url;
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var url;
var xpath='//a[img/@style="vertical-align: middle;"][@href]';
if(doc.evaluate(xpath, doc,
nsResolver,XPathResult.ANY_TYPE,null).iterateNext())
{
xpath='//a[@class="MedBlueLink"][img]/@onclick';
var temp=doc.evaluate(xpath, doc,
nsResolver,XPathResult.ANY_TYPE,null).iterateNext();
var docidlist=temp.value;
docidlist=docidlist.split("MID=")[1];
docidlist=docidlist.split("&")[0];
xpath='//a[img/@style="vertical-align: middle;"][@href]';
temp=doc.evaluate(xpath, doc,
nsResolver,XPathResult.ANY_TYPE,null).iterateNext();
var EISESSION =temp.href;
EISESSION=EISESSION.split("('")[1];
EISESSION=EISESSION.split("'")[0];
url=createURL(EISESSION,docidlist,doc.location.href);
parseRIS(url);
}
else
{
xpath='//input[@NAME="sessionid"]';
var EISESSION=doc.evaluate(xpath, doc,
nsResolver,XPathResult.ANY_TYPE,null).iterateNext().value;
xpath='//input[@name="cbresult"]/@onclick';
var items=new Array();
var rows=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE,null);
var xpath2='//a[@class="MedBlackText"]/b';
xpath2=doc.evaluate(xpath2, doc, nsResolver,XPathResult.ANY_TYPE,null);
var title;
var docidlist;
while(row=rows.iterateNext())
{
docidlist=row.value;
docidlist=docidlist.split("'")[1];
url=createURL(EISESSION,docidlist,doc.location.href);
title=xpath2.iterateNext();
title=title.textContent;
items[url]=title;
}
items = Zotero.selectItems(items);
if(!items) return true;
var dois="";
var theurls= new Array();
for(var thelink in items)
{
theurls.push(thelink);
}
parseRIS(theurls);
}
}