Skip to content

Commit 250985d

Browse files
petervelosyzuphilip
authored andcommitted
Created a translator for Antikvarium.hu (zotero#1411)
1 parent b985f8b commit 250985d

File tree

1 file changed

+229
-0
lines changed

1 file changed

+229
-0
lines changed

Antikvarium.hu.js

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
{
2+
"translatorID": "68a54283-67e0-4e1c-ad3d-5b699868b194",
3+
"label": "Antikvarium.hu",
4+
"creator": "Velősy Péter Kristóf",
5+
"target": "^https?://(www\\.)?antikvarium\\.hu/",
6+
"minVersion": "3.0",
7+
"maxVersion": "",
8+
"priority": 100,
9+
"inRepository": true,
10+
"translatorType": 4,
11+
"browserSupport": "gcsibv",
12+
"lastUpdated": "2017-11-11 15:26:37"
13+
}
14+
15+
/*
16+
***** BEGIN LICENSE BLOCK *****
17+
18+
Copyright © 2017 Velősy Péter Kristóf
19+
20+
This file is part of Zotero.
21+
22+
Zotero is free software: you can redistribute it and/or modify
23+
it under the terms of the GNU Affero General Public License as published by
24+
the Free Software Foundation, either version 3 of the License, or
25+
(at your option) any later version.
26+
27+
Zotero is distributed in the hope that it will be useful,
28+
but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
GNU Affero General Public License for more details.
31+
32+
You should have received a copy of the GNU Affero General Public License
33+
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
34+
35+
***** END LICENSE BLOCK *****
36+
*/
37+
38+
39+
//Zotero attr() and text() functions:
40+
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;}
41+
42+
43+
function detectWeb(doc, url) {
44+
if (url.includes('konyv')) {
45+
return "book";
46+
} else if (url.includes('index.php?type=search') && getSearchResults(doc, true)){
47+
return "multiple";
48+
}
49+
}
50+
51+
52+
function getSearchResults(doc, checkOnly) {
53+
var items = {};
54+
var found = false;
55+
var rows = doc.querySelectorAll('.src-result-book');
56+
for (var i=0; i<rows.length; i++) {
57+
var href = attr(rows[i], '#searchResultKonyv-csempes', 'href');
58+
var title = ZU.trimInternal(text(rows[i], '.book-title-src'));
59+
if (!href || !title) continue;
60+
if (checkOnly) return true;
61+
found = true;
62+
items[href] = title;
63+
}
64+
return found ? items : false;
65+
}
66+
67+
68+
function doWeb(doc, url) {
69+
if (detectWeb(doc, url) == "multiple") {
70+
Zotero.selectItems(getSearchResults(doc, false), function (items) {
71+
if (!items) {
72+
return true;
73+
}
74+
var articles = [];
75+
for (var i in items) {
76+
articles.push(i);
77+
}
78+
ZU.processDocuments(articles, scrape);
79+
});
80+
} else {
81+
scrape(doc, url);
82+
}
83+
}
84+
85+
86+
function scrape(doc, url) {
87+
var newItem = new Zotero.Item('book');
88+
89+
newItem.title = text(doc, '[itemprop=name]', 0).trim();
90+
91+
var subtitle = text(doc, '[itemprop=alternateName]', 0) ? text(doc, '[itemprop=alternateName]', 0).trim() : null;
92+
if (subtitle) {
93+
newItem.title = newItem.title + ': ' + capitalizeHungarianTitle(subtitle, true);
94+
}
95+
96+
var authors = Array.from(doc.querySelectorAll('[itemprop=author]')).map(x => cleanHungarianAuthor(x.innerText));
97+
authors.forEach(x => newItem.creators.push(x));
98+
99+
var abstract = text(doc, 'fulszovegFull', 0) || text(doc, 'eloszoFull', 0);
100+
if (abstract) {
101+
newItem.abstractNote = abstract.replace(' Vissza', '').trim();
102+
}
103+
104+
var seriesElement = doc.getElementById('konyvAdatlapSorozatLink');
105+
if (seriesElement && seriesElement.length) {
106+
newItem.series = seriesElement.innerText;
107+
newItem.seriesNumber = getElementByInnerText('th', 'Kötetszám:').parentElement.children[1].innerText;
108+
newItem.volume = newItem.seriesNumber;
109+
}
110+
111+
var publisherElement = doc.querySelector('[itemprop=publisher]');
112+
if (publisherElement) {
113+
114+
var publisherName = text(publisherElement, '[itemprop=name]', 0);
115+
if (publisherName) {
116+
newItem.publisher = publisherName;
117+
}
118+
119+
var publisherPlace = text(publisherElement, '[itemprop=address]', 0);
120+
if (publisherPlace) {
121+
newItem.place = publisherPlace.replace('(', '').replace(')', '');
122+
}
123+
}
124+
newItem.date = text(doc, '[itemprop=datePublished]');
125+
126+
newItem.numPages = text(doc, '[itemprop=numberOfPages]', 0);
127+
128+
newItem.language = text(doc, '[itemprop=inLanguage]', 0);
129+
130+
var isbnElement = getElementByInnerText(doc, 'th', 'ISBN:');
131+
if (isbnElement) {
132+
newItem.ISBN = isbnElement.parentElement.children[1].innerText;
133+
}
134+
135+
var contentsElement = doc.getElementById('tartalomFull');
136+
if (contentsElement) {
137+
newItem.notes.push({note: contentsElement.innerText});
138+
}
139+
140+
newItem.attachments.push({document: doc, title: "Antikvarium.hu Snapshot", mimeType: "text/html" });
141+
142+
newItem.complete();
143+
}
144+
145+
function getElementByInnerText(doc, elementType, innerText) {
146+
var tags = doc.getElementsByTagName(elementType);
147+
148+
for (var i = 0; i < tags.length; i++) {
149+
if (tags[i].textContent == innerText) {
150+
return tags[i];
151+
}
152+
}
153+
return null;
154+
}
155+
156+
function cleanHungarianAuthor(authorName) {
157+
if (authorName.includes(',')) {
158+
return Zotero.Utilities.cleanAuthor(authorName, 'author', true);
159+
} else {
160+
var author = Zotero.Utilities.cleanAuthor(authorName, 'author', false);
161+
var firstName = author.lastName;
162+
var lastName = author.firstName;
163+
author.firstName = firstName;
164+
author.lastName = lastName;
165+
return author;
166+
}
167+
}
168+
169+
function capitalizeHungarianTitle(title) {
170+
title = title[0].toUpperCase() + title.substring(1).toLowerCase();
171+
var words = title.split(/[ !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/);
172+
words.forEach(w => {
173+
if (isRomanNumeral(w)) {
174+
title = title.replace(w, w.toUpperCase());
175+
}
176+
});
177+
return title;
178+
}
179+
180+
function isRomanNumeral(word) {
181+
var romanRegex = /^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/;
182+
return word.toUpperCase().match(romanRegex) ? true : false;
183+
}
184+
/** BEGIN TEST CASES **/
185+
var testCases = [
186+
{
187+
"type": "web",
188+
"url": "https://www.antikvarium.hu/konyv/erdei-janos-atlasz-almai-82276",
189+
"items": [
190+
{
191+
"itemType": "book",
192+
"title": "Atlasz álmai: Borges a szovjetunióban/az öröklét előszobája és egyéb történetek",
193+
"creators": [
194+
{
195+
"firstName": "János",
196+
"lastName": "Erdei",
197+
"creatorType": "author"
198+
}
199+
],
200+
"date": "1991",
201+
"language": "Magyar",
202+
"libraryCatalog": "Antikvarium.hu",
203+
"numPages": "140",
204+
"place": "Budapest",
205+
"publisher": "Aero & Rádió Kft.",
206+
"shortTitle": "Atlasz álmai",
207+
"attachments": [
208+
{
209+
"title": "Antikvarium.hu Snapshot",
210+
"mimeType": "text/html"
211+
}
212+
],
213+
"tags": [],
214+
"notes": [
215+
{
216+
"note": "TARTALOM\nElőszó\t5\nMásodik ébredés\t7\nMegvilágosodás\t9\nSzemelvények Gusavson műveiből\t17\nHalvány kétkedés\t17\nMegjegyzés\t20\nJótékony hazugság\t21\nA föltámadt Krisztus dilemmája\t23\nÁbrahám\t24\nSzerelmes ébredés és álom\t27\nRáébredés: a rabszolga\t33\nDacos ébredés, avagy az ötödik evangélista\t35\nElalvás előtt I.\t40\nKét álmodó\t40\nElalvás előtt II.\t43\nA kivégzési jegy\t45\nGyújtópont\t53\nFelvillanás\t55\nAngyali üdvözlet\t63\nA fellendülés okai\t65\nFéreg által homályosan\t71\nBorges a Szovjetunióban\t81\nA nevetés köve\t89\nA Nagy Rendszer\t93\nTúl az álmokon: az igazhitű\t97\nAz öröklét előszobája\t101\nElragadottság\t109\nA legvidámabb eretnek\t113\nÚjabb fejlemények az Oidipusz-ügyben\t117\nVisszahívták a Szfinxet!\t121\nAz egyetlen lehetőség\t125\nZavaros álom: letisztulás\t127\nN. és a tenger\t135\nUtószó\t137"
217+
}
218+
],
219+
"seeAlso": []
220+
}
221+
]
222+
},
223+
{
224+
"type": "web",
225+
"url": "https://www.antikvarium.hu/index.php?type=search&ksz=atlasz&reszletes=0&newSearch=1&searchstart=ksz&interfaceid=101",
226+
"items": "multiple"
227+
}
228+
]
229+
/** END TEST CASES **/

0 commit comments

Comments
 (0)