-
Notifications
You must be signed in to change notification settings - Fork 0
/
AJHG.js
84 lines (79 loc) · 2.57 KB
/
AJHG.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
{
"translatorID":"0a01d85e-483c-4998-891b-24707728d83e",
"translatorType":4,
"label":"AJHG",
"creator":"Michael Berkowitz",
"target":"http://(www.)?ajhg.org/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2008-02-14 23:15:00"
}
function detectWeb(doc, url) {
if (doc.evaluate('//div[@class="article_links"]/a[1]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "multiple";
} else if (url.indexOf("abstract") != -1 || url.indexOf("fulltext") != -1) {
return "journalArticle";
}
}
function getID(str) {
str = str.match(/\/([^/]+)$/)[1];
if (str.indexOf("#") != -1) {
str = str.substr(0, str.length - 1);
}
return str;
}
function doWeb(doc, url) {
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
if (doc.title.indexOf("Search Results") != -1) {
var xpath = '//table[@id="search_results"]/tbody/tr/td[1]';
var titlex = './strong';
var linkx = './div/a[1]';
} else {
var xpath = '//div[@id="main_toc"]/dl';
var titlex = './dt';
var linkx = './dd/div/a[1]';
}
var blocks = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
var next_block;
while (next_block = blocks.iterateNext()) {
var title = doc.evaluate(titlex, next_block, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var link = doc.evaluate(linkx, next_block, null, XPathResult.ANY_TYPE, null).iterateNext().href;
items[link] = title;
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(getID(i));
}
} else {
articles = [getID(url)];
}
Zotero.debug(articles);
for (var i in articles) {
var poststr = 'format=cite-abs&citation-type=RIS&pii=' + articles[i] + '&action=download&Submit=Export';
var pdfurl = 'http://download.ajhg.org/AJHG/pdf/PII' + articles[i].replace(/(\(|\)|\-)/g, "") + '.pdf';
var newurl = 'http://www.ajhg.org/AJHG/fulltext/' + articles[i];
Zotero.Utilities.HTTP.doPost('http://ajhg.org/AJHG/citationexport', poststr, function(text) {
var trans = Zotero.loadTranslator("import");
trans.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
trans.setString(text);
trans.setHandler("itemDone", function(obj, item) {
item.attachments = [
{url:newurl, title:"AJHG Snapshot", mimeType:"text/html"},
{url:pdfurl, title:"AJHG Full Text PDF", mimeType:"application/pdf"}
];
if (item.notes[0]["note"]) {
item.abstractNote = item.notes[0]["note"];
}
item.notes = [];
item.complete();
});
trans.translate();
Zotero.done();
});
}
Zotero.wait();
}