forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode4Lib Journal.js
143 lines (130 loc) · 4.36 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
"translatorID": "a326fc49-60c2-405b-8f44-607e5d18b9ad",
"label": "Code4Lib Journal",
"creator": "Michael Berkowitz",
"target": "^https?://journal\\.code4lib\\.org/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2018-03-05 07:15:21"
}
// attr()/text() v2
function attr(docOrElem,selector,attr,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.getAttribute(attr):null;}function text(docOrElem,selector,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.textContent:null;}
function detectWeb(doc, url) {
if (getSearchResults(doc, true) {
return "multiple";
} else if (text(doc, 'h1[class="articletitle"]')) {
return "journalArticle";
}
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('div.article>h2.articletitle>a');
for (let i=0; i<rows.length; i++) {
let href = rows[i].href;
let title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return true;
}
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
} 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 = url;
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({
document: doc,
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 **/