-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathOpen Conf.js
172 lines (151 loc) · 4.79 KB
/
Open Conf.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
166
167
168
169
170
171
172
{
"translatorID": "3d180fcf-8005-4a2b-a0cd-1fe31ba1f996",
"label": "Open Conf",
"creator": "Sebastian Karcher",
"target": "^https?://(www\\.)?openconf\\.(com|org)/.+/request\\.php",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2017-05-26 15:41:56"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2017 Sebastian Karcher
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
if (ZU.xpathText(doc, '//div[@id="oc_program_summary_main"]')) {
return "presentation";
}
else if (url.indexOf('action=program.php')>-1 && getSearchResults(doc, true)) {
return "multiple";
}
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//span[@class="oc_program_concurrentSessionPaperTitle"]/a');
for (var i=0; i<rows.length; i++) {
var href = rows[i].href;
var 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 item = new Z.Item("presentation");
var data = ZU.xpath(doc, '//div[@id="oc_program_summary_main"]');
//info from h1 and following line
item.title = ZU.xpathText(data, '//h1');
if (!item.title) item.title = ZU.xpathText(doc, '//h1');
//info from top level li
var authors = ZU.xpath(data, '//div[@id="oc_program_summary_authors"]/p/strong');
for (var i = 0; i<authors.length; i++) {
item.creators.push(ZU.cleanAuthor(authors[i].textContent, "author"));
}
item.abstractNote = ZU.xpathText(data, '//div[@id="oc_program_summary_main"]/p[1]');
item.meetingName = ZU.xpathText(doc, '//div/a[@class="confName"]');
var files = ZU.xpath(data, '//div[@id="oc_program_summary_files"]//a[img[contains(@alt, "View File")]]');
for (var i = 0; i<files.length; i++) {
item.attachments.push({
title: "OpenConf Presentation",
url: "files[i].href"
})
}
item.attachments.push({
title: "Snapshot",
document: doc
});
var fullprogramURL = ZU.xpathText(doc, '//div[@id="mainbody"]/a[contains(@href, "action=program.php")]/@href');
ZU.processDocuments(fullprogramURL, function (full){
var dates = ZU.xpath(full, '//div[@class="oc_program_Date"]');
if (dates.length) {
var firstdate = dates[0].id;
var lastdate;
if (dates.length>1) {
lastdate = dates[dates.length-1].id;
item.date = firstdate + " to " + lastdate;
}
else {
item.date = firstdate;
}
}
item.complete();
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.openconf.com/demo/openconf6/modules/request.php?module=oc_program&action=program.php",
"items": "multiple"
},
{
"type": "web",
"url": "https://www.openconf.com/demo/openconf6/modules/request.php?module=oc_program&action=summary.php&id=27",
"items": [
{
"itemType": "presentation",
"title": "The Infinite Monkey Protocol Suite (IMPS)",
"creators": [
{
"firstName": "S.",
"lastName": "Christey",
"creatorType": "author"
}
],
"date": "2015-12-01 to 2015-12-02",
"abstractNote": "This memo describes a protocol suite which supports an infinite number of monkeys that sit at an infinite number of typewriters in order to determine when they have either produced the entire works of William Shakespeare or a good television show. The suite includes communications and control protocols for monkeys and the organizations that interact with them.",
"meetingName": "OpenConf Conference 2020",
"attachments": [
{
"title": "OpenConf Presentation"
},
{
"title": "OpenConf Presentation"
},
{
"title": "Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/