/
Encyclopedia of Korean Culture.js
221 lines (205 loc) · 5.92 KB
/
Encyclopedia of Korean Culture.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{
"translatorID": "dc879929-ae39-45b3-b49b-dab2c80815ab",
"label": "Encyclopedia of Korean Culture",
"creator": "jacoblee36251",
"target": "^https?://(www\\.)?encykorea\\.aks\\.ac\\.kr/Article/",
"minVersion": "5.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-09-15 20:07:33"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2023 jacoblee36251
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 (/^https?:\/\/[^/]+\/Article\/E\d+/.test(url)) {
return 'encyclopediaArticle';
}
else if (getSearchResults(doc, true)) {
return 'multiple';
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('li.item > a[href^="/Article/E"]');
for (let row of rows) {
let href = row.href;
let title = ZU.trimInternal(row.querySelector('div.title').textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
async function doWeb(doc, url) {
if (detectWeb(doc, url) == 'multiple') {
let items = await Zotero.selectItems(getSearchResults(doc, false));
if (!items) return;
for (let url of Object.keys(items)) {
await scrape(await requestDocument(url));
}
}
else {
await scrape(doc, url);
}
}
async function scrape(doc, url = doc.location.href) {
var item = new Zotero.Item('encyclopediaArticle');
item.title = ZU.trimInternal(text(doc, ".content-head-title"));
item.encyclopediaTitle = "한국민족문화대백과사전 [Encyclopedia of Korean Culture]";
item.publisher = "Academy of Korean Studies";
item.language = "ko";
// Clean url by removing # terms
item.url = url.replace(/#.*/, "");
// Author processing; may be 0 or more names, would be in Korean
var authors = doc.querySelector('div.author-wrap > span');
if (authors) {
authors = authors.textContent;
// For simplicity, assume one character surnames for everybody (there are rare exceptions)
for (let author of authors.split('·')) {
item.creators.push({
lastName: author[0],
firstName: author.slice(1),
creatorType: "author"
});
}
}
item.attachments.push({ title: "Snapshot", document: doc, mimeType: "text/html" });
item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://encykorea.aks.ac.kr/Article/E0013414#cm_multimedia",
"detectedItemType": "encyclopediaArticle",
"items": [
{
"itemType": "encyclopediaArticle",
"title": "다대포 (多大浦)",
"creators": [
{
"lastName": "오",
"firstName": "건환",
"creatorType": "author"
},
{
"lastName": "김",
"firstName": "건유",
"creatorType": "author"
}
],
"encyclopediaTitle": "한국민족문화대백과사전 [Encyclopedia of Korean Culture]",
"language": "ko",
"libraryCatalog": "Encyclopedia of Korean Culture",
"publisher": "Academy of Korean Studies",
"url": "https://encykorea.aks.ac.kr/Article/E0013414",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://encykorea.aks.ac.kr/Article/E0002855",
"detectedItemType": "encyclopediaArticle",
"items": [
{
"itemType": "encyclopediaArticle",
"title": "경주 남산 탑곡 마애불상군 (慶州 南山 塔谷 磨崖佛像群)",
"creators": [],
"encyclopediaTitle": "한국민족문화대백과사전 [Encyclopedia of Korean Culture]",
"language": "ko",
"libraryCatalog": "Encyclopedia of Korean Culture",
"publisher": "Academy of Korean Studies",
"url": "https://encykorea.aks.ac.kr/Article/E0002855",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://encykorea.aks.ac.kr/Article/E0025488",
"detectedItemType": "encyclopediaArticle",
"items": [
{
"itemType": "encyclopediaArticle",
"title": "사랑 (舍廊)",
"creators": [
{
"lastName": "김",
"firstName": "동욱",
"creatorType": "author"
}
],
"encyclopediaTitle": "한국민족문화대백과사전 [Encyclopedia of Korean Culture]",
"language": "ko",
"libraryCatalog": "Encyclopedia of Korean Culture",
"publisher": "Academy of Korean Studies",
"url": "https://encykorea.aks.ac.kr/Article/E0025488",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://encykorea.aks.ac.kr/Article/Search/%ED%95%99%EC%9B%90?field=&type=&alias=false&body=false&containdesc=false&keyword=%ED%95%99%EC%9B%90",
"detectedItemType": "multiple",
"items": "multiple"
},
{
"type": "web",
"url": "https://encykorea.aks.ac.kr/Article/List/Field/%EC%98%88%EC%88%A0%C2%B7%EC%B2%B4%EC%9C%A1%3E%EC%A1%B0%EA%B0%81",
"detectedItemType": "multiple",
"items": "multiple"
},
{
"type": "web",
"url": "https://encykorea.aks.ac.kr/Article/List/Type/%EC%9C%A0%EC%A0%81",
"detectedItemType": "multiple",
"items": "multiple"
}
]
/** END TEST CASES **/