forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code4Lib Journal.js
127 lines (121 loc) · 4.19 KB
/
Code4Lib Journal.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
{
"translatorID": "a326fc49-60c2-405b-8f44-607e5d18b9ad",
"label": "Code4Lib Journal",
"creator": "Michael Berkowitz",
"target": "http://journal.code4lib.org/",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "g",
"lastUpdated": "2012-04-02 20:50:45"
}
function detectWeb(doc, url) {
if (doc.evaluate('//h2[@class="articletitle"]/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "multiple";
} else if (doc.evaluate('//h1[@class="articletitle"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "journalArticle";
}
}
function doWeb(doc, url) {
var items = new Object();
var articles = new Array();
var xpath = '//div[@class="article"]/h2[@class="articletitle"]/a';
if (detectWeb(doc, url) == "multiple") {
var xpath = '//div[@class="article"]/h2[@class="articletitle"]/a';
var titles = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
var next_title = titles.iterateNext();
while (next_title) {
items[next_title.href] = next_title.textContent;
next_title = titles.iterateNext();
}
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var i in items) {
articles.push(i);
}
Zotero.Utilities.processDocuments(articles, scrape, function () {
Zotero.done();
});
Zotero.wait();
});
} else {
scrape(doc, url);
}
}
function scrape(doc, url){
var newItem = new Zotero.Item("journalArticle");
newItem.repository = "Code4Lib Journal";
newItem.publicationTitle = "The Code4Lib Journal";
newItem.ISSN = "1940-5758";
newItem.url = doc.location.href;
newItem.title = ZU.xpathText(doc, '//div[@class="article"]/h1[@class="articletitle"]');
newItem.abstractNote = ZU.xpathText(doc, '//div[@class="article"]/div[@class="abstract"]/p');
var issdate = ZU.xpathText(doc, '//p[@id="issueDesignation"]');
newItem.issue = issdate.match(/([^,]*)/)[0].match(/\d+/)[0];
newItem.date = issdate.match(/,\s+(.*)$/)[1];
var axpath = '//div[@class="article"]/div[@class="entry"]/p[1]';
var authors = ZU.xpathText(doc, axpath).replace(/By\s+/i, "");
var next_author = authors.split(/\s*and\s*|\s*,\s*/);
for (var i in next_author) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(next_author[i], "author"));
}
newItem.attachments.push({url:doc.location.href, title:"Code4Lib Journal Snapshot", mimeType:"text/html"});
newItem.complete();
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://journal.code4lib.org/articles/5001",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"firstName": "Joe",
"lastName": "Ryan",
"creatorType": "author"
},
{
"firstName": "Josh",
"lastName": "Boyer",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"title": "Code4Lib Journal Snapshot",
"mimeType": "text/html"
}
],
"publicationTitle": "The Code4Lib Journal",
"ISSN": "1940-5758",
"url": "http://journal.code4lib.org/articles/5001",
"title": "GroupFinder: A Hyper-Local Group Study Coordination System",
"abstractNote": "GroupFinder is a system designed to help users working in groups let each other know where they are, what they are working on, and when they started. Students can use the GroupFinder system to arrange meetings within the library. GroupFinder also works with the phpScheduleIt room reservation system used to reserve group study rooms at the D.H. Hill Library at NCSU. Information from GroupFinder is presented on the GroupFinder web site, the mobile web site and on electronic bulletin boards within the library. How GroupFinder was developed from the initial concept through the implementation is covered in the article.",
"issue": "13",
"date": "2011-04-11",
"libraryCatalog": "Code4Lib Journal",
"accessDate": "CURRENT_TIMESTAMP",
"shortTitle": "GroupFinder"
}
]
},
{
"type": "web",
"url": "http://journal.code4lib.org/?s=zotero",
"items": "multiple"
},
{
"type": "web",
"url": "http://journal.code4lib.org/issues/issue14",
"items": "multiple"
}
]
/** END TEST CASES **/