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 patheMedicine.js
123 lines (105 loc) · 3.57 KB
/
eMedicine.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
{
"translatorID": "ab88d517-d88c-4a73-a0ad-c94c76cca849",
"label": "eMedicine",
"creator": "William Smith",
"target": "^https?://emedicine\\.medscape\\.com/article/",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-04-15 18:04:37"
}
// Emedicine.Medscape.com translator.
// Version 1.00
// By William Smith, see http://www.willsmith.org/contactme/
function detectWeb(doc, url) {
if (doc.location.href.match("(overview|treatment|diagnosis|followup|media)")) {
return "journalArticle";
}
}
// Everything lives in Metas. Very convenient.
function useMeta (doc, newItem, field, zoteroField) {
xpath='//meta[@name="' + field + '"]/@content';
temp=doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext();
if(temp)
{
newItem[zoteroField] =temp.value;
}
}
function getMeta (doc, newItem, field) {
xpath='//meta[@name="' + field + '"]/@content';
temp=doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
return temp;
}
function scrape(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var fieldTitle;
var newItem = new Zotero.Item("journalArticle");
newItem.publication = 'Medscape - eMedicine';
// Geta few useful fields.
useMeta(doc, newItem, "title", "title");
useMeta(doc, newItem, "date" , "date" );
useMeta(doc, newItem, "book" , "repository");
useMeta(doc, newItem, "description" , "abstractNote");
newItem.abstractNote = newItem.abstractNote.replace(/^(Overview|Treatment|Diagnosis|Followup|Media):\s+/, "");
// Authors - we only handle one.
authors = getMeta(doc, newItem, "authors");
if (!String(authors).match(/[a-z]/)) {
authors = authors.iterateNext().textContent;
Zotero.debug('author: <'+authors+'>');
newItem.creators.push(Zotero.Utilities.cleanAuthor(authors, "author"));
}
// Keywords.
keywords = getMeta(doc, newItem, "keywords");
if (keywords) {
keywords = keywords.iterateNext().textContent;
Zotero.debug('keywords: <'+keywords+'>');
keywords = keywords.split(",");
for (var i=0;i<keywords.length; i++) {
Zotero.debug('keyword['+i+']: <'+keywords[i]+'>');
newItem.tags[i] = Zotero.Utilities.cleanTags(keywords[i], "");
}
}
newItem.url = url;
// Attachment doesn't seem to work - misses a stylesheet or something, and looks ugly.
// newItem.attachments.push({url:url, title:"eMedicine Snapshot",mimeType:"text/html"});
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;
scrape(doc,url);
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://emedicine.medscape.com/article/163751-overview",
"items": [
{
"itemType": "journalArticle",
"creators": [],
"notes": [],
"tags": [
" Brugada Syndrome articles",
"Brugada Syndrome information"
],
"seeAlso": [],
"attachments": [],
"title": "Brugada Syndrome",
"date": "2014-03-28-04:00",
"abstractNote": "Brugada Syndrome. Brugada syndrome is a disorder characterized by sudden death associated with one of several ECG patterns characterized by incomplete right bundle-branch block and ST-segment elevations in the anterior precordial leads.",
"url": "http://emedicine.medscape.com/article/163751-overview",
"libraryCatalog": "eMedicine"
}
]
}
]
/** END TEST CASES **/