forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APS-Physics.js
165 lines (154 loc) · 4.53 KB
/
APS-Physics.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
158
159
160
161
162
163
164
165
{
"translatorID": "f318ab1e-71c6-4f67-8ac3-4b1144e5bf4e",
"label": "APS-Physics",
"creator": "Will Shanks",
"target": "^https?://(?:www\\.)?(physics)\\.aps\\.org([^/]*/(articles|story)/?|/browse(\\?|$))",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-12-06 17:44:20"
}
// Works for APS Physics Viewpoints and Focus articles: http://physics.aps.org/
function detectWeb(doc, url) {
if (url.indexOf("/browse")!=-1) return "multiple";
else return "journalArticle";
}
function doWeb(doc, url) {
if (detectWeb(doc, url)=="multiple"){
var items = {};
var articles = [];
var links = ZU.xpath(doc, '//div[@class="result-title"]/h2/a[contains(@href, "/story/") or contains(@href, "/articles/")]')
for (var i in links){
items[ZU.xpathText(links[i], './@href')] = ZU.xpathText(links[i], './text()')
}
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var itemurl in items) {
articles.push(itemurl);
}
ZU.processDocuments(articles, scrape)
});
}
else scrape(doc, url);
}
function scrape(doc, url){
Zotero.debug(doc.title);
//Get abstract (called 'byline' on page)
var abs = ZU.xpathText(doc, '//article/header/p[contains(@class, "byline")]');
//Check if page is a Viewpoint. Only Viewpoints have PDFs
var title = ZU.xpathText(doc, '//article/header/h1[contains(@class, "title")]');
var hasPDF = (title.indexOf('Viewpoint:') != -1);
//Get DOI
var doi = ZU.xpathText(doc, '//article/header/div[contains(@class, "pubinfo")]/text()');
doi = doi.match(/10\.[^\s]+/)[0]
//Set up urls
var pdfurl = 'http://physics.aps.org/articles/pdf/' + doi;
var urlRIS = 'http://physics.aps.org/articles/export/' + doi + '/ris';
Zotero.Utilities.HTTP.doGet(urlRIS, function(text) {
//DOI is stored in ID field. Fix it.
text = text.replace(/^ID\s\s?-\s/mg, 'DO - ');
// load translator for RIS
var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
translator.setHandler("itemDone", function(obj, item) {
item.attachments = [
{document:doc, title:"APS Snapshot"}];
if (hasPDF) {
item.attachments.push({url:pdfurl, title:"APS Full Text PDF", mimeType:"application/pdf"});
}
if (abs) item.abstractNote = abs;
item.complete();
});
translator.translate();
});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://physics.aps.org/articles/v5/100",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "de Beer",
"firstName": "Sissi",
"creatorType": "author"
},
{
"lastName": "Müser",
"firstName": "Martin H.",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "APS Snapshot"
},
{
"title": "APS Full Text PDF",
"mimeType": "application/pdf"
}
],
"publisher": "American Physical Society",
"DOI": "10.1103/Physics.5.100",
"title": "Surface Folds Make Tears and Chips",
"publicationTitle": "Physics",
"journalAbbreviation": "Physics",
"volume": "5",
"pages": "100",
"date": "September 4, 2012",
"url": "http://link.aps.org/doi/10.1103/Physics.5.100",
"abstractNote": "Fluidlike folding instabilities of solid surfaces complicate the machining of metals to perfection",
"libraryCatalog": "APS-Physics",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://physics.aps.org/articles/v5/101",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"lastName": "Schirber",
"firstName": "Michael",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "APS Snapshot"
}
],
"publisher": "American Physical Society",
"DOI": "10.1103/Physics.5.101",
"title": "Measuring the Smallest Trickle",
"publicationTitle": "Physics",
"journalAbbreviation": "Physics",
"volume": "5",
"pages": "101",
"date": "September 10, 2012",
"url": "http://link.aps.org/doi/10.1103/Physics.5.101",
"abstractNote": "Researchers used a nanoscale tunnel in a silicon chip to measure a flow rate of a few picoliters per minute, which is smaller than any previous observation.",
"libraryCatalog": "APS-Physics",
"accessDate": "CURRENT_TIMESTAMP"
}
]
}
]
/** END TEST CASES **/