Skip to content

Commit 219f9bb

Browse files
committed
Add litres bookstore translator
1 parent fd56161 commit 219f9bb

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

Litres.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"translatorID": "02bde528-c86d-42d5-904b-e74f85bd45f9",
3+
"label": "Litres",
4+
"creator": "Ilya Zonov",
5+
"target": "^https://(www\\.)?litres\\.ru/",
6+
"minVersion": "5.0",
7+
"maxVersion": "",
8+
"priority": 100,
9+
"inRepository": true,
10+
"translatorType": 4,
11+
"browserSupport": "gcsibv",
12+
"lastUpdated": "2025-03-29 17:26:32"
13+
}
14+
15+
/*
16+
***** BEGIN LICENSE BLOCK *****
17+
18+
Copyright © 2025 Ilya Zonov
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+
function detectWeb(doc, url) {
40+
if (url.includes('/book/')) {
41+
return 'book';
42+
}
43+
return false;
44+
}
45+
46+
async function doWeb(doc, url) {
47+
await scrape(doc, url);
48+
}
49+
50+
async function scrape(doc, url = doc.location.href) {
51+
const translator = Zotero.loadTranslator('web');
52+
53+
// Embedded Metadata
54+
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
55+
translator.setDocument(doc);
56+
57+
translator.setHandler('itemDone', function (obj, item) {
58+
item.publicationTitle = "";
59+
60+
item.title = text(doc, 'h1[itemprop="name"]');
61+
62+
const authors = doc.querySelectorAll('div[data-testid="art__author--details"] a[data-testid="art__personName--link"] span');
63+
for (const author of authors) {
64+
item.creators.push(ZU.cleanAuthor(author.textContent, 'author'));
65+
}
66+
67+
item.series = text(doc, 'div[data-testid="art__inSeries--title"] a').replaceAll(/[«»]/g, '');
68+
69+
const seriesInfo = text(doc, 'div[data-testid="art__inSeries--title"] div');
70+
const seriesMatch = seriesInfo.match(/([0-9]+) .+ из [0-9]+ в серии/);
71+
if (seriesMatch) {
72+
item.seriesNumber = seriesMatch[1];
73+
}
74+
75+
item.ISBN = text(doc, 'span[itemprop="isbn"]');
76+
77+
item.publisher = text(doc, 'div[data-testid="book__characteristicsCopyrightHolder"] a');
78+
79+
item.complete();
80+
});
81+
82+
const em = await translator.getTranslatorObject();
83+
em.itemType = 'book';
84+
em.doWeb(doc, url);
85+
}
86+
87+
/** BEGIN TEST CASES **/
88+
var testCases = [
89+
{
90+
"type": "web",
91+
"url": "https://www.litres.ru/book/daron-asemoglu/pochemu-odni-strany-bogatye-a-drugie-bednye-proishozhdenie-10748980/",
92+
"items": [
93+
{
94+
"itemType": "book",
95+
"title": "Почему одни страны богатые, а другие бедные. Происхождение власти, процветания и нищеты",
96+
"creators": [],
97+
"date": "2016-02-17",
98+
"ISBN": "9785170927364",
99+
"abstractNote": "Исследовать экономическую ситуацию страны можно с различных позиций. Географический принцип берет за основу местоположение государства. Культурологический – особенности развития культурной составляющ…",
100+
"language": "ru",
101+
"libraryCatalog": "www.litres.ru",
102+
"publisher": "Издательство АСТ",
103+
"series": "Даймонд",
104+
"url": "https://www.litres.ru/book/daron-asemoglu/pochemu-odni-strany-bogatye-a-drugie-bednye-proishozhdenie-10748980/",
105+
"attachments": [
106+
{
107+
"title": "Snapshot",
108+
"mimeType": "text/html"
109+
}
110+
],
111+
"tags": [],
112+
"notes": [],
113+
"seeAlso": []
114+
}
115+
]
116+
},
117+
{
118+
"type": "web",
119+
"url": "https://www.litres.ru/book/dzho-aberkrombi/luchshe-podavat-holodnym-5025444/",
120+
"items": [
121+
{
122+
"itemType": "book",
123+
"title": "Лучше подавать холодным",
124+
"creators": [],
125+
"date": "2018-11-12",
126+
"ISBN": "9785699632114",
127+
"abstractNote": "Весна в Стирии означает войну…Девятнадцать лет длятся Кровавые Годы. Безжалостный великий герцог Орсо погряз в жестокой борьбе со вздорной Лигой Восьми. Белая земля меж ними залита кровью. Армии марш…",
128+
"language": "ru",
129+
"libraryCatalog": "www.litres.ru",
130+
"publisher": "Эксмо",
131+
"series": "Земной Круг",
132+
"seriesNumber": "4",
133+
"url": "https://www.litres.ru/book/dzho-aberkrombi/luchshe-podavat-holodnym-5025444/",
134+
"attachments": [
135+
{
136+
"title": "Snapshot",
137+
"mimeType": "text/html"
138+
}
139+
],
140+
"tags": [],
141+
"notes": [],
142+
"seeAlso": []
143+
}
144+
]
145+
},
146+
{
147+
"type": "web",
148+
"url": "https://www.litres.ru/book/maksim-ilyahov/pishi-sokraschay-2025-kak-sozdavat-silnyy-tekst-70193008/",
149+
"items": [
150+
{
151+
"itemType": "book",
152+
"title": "Пиши, сокращай 2025: Как создавать сильный текст (PDF + EPUB)",
153+
"creators": [],
154+
"date": "2023-12-31",
155+
"ISBN": "9785961494266",
156+
"abstractNote": "После покупки предоставляется дополнительная возможность скачать книгу в формате epub.«Пиши, сокращай» – книга о создании текста для всех, кто пишет по работе. Неважно, работает ли человек профессион…",
157+
"language": "ru",
158+
"libraryCatalog": "www.litres.ru",
159+
"publisher": "Альпина Диджитал",
160+
"shortTitle": "Пиши, сокращай 2025",
161+
"url": "https://www.litres.ru/book/maksim-ilyahov/pishi-sokraschay-2025-kak-sozdavat-silnyy-tekst-70193008/",
162+
"attachments": [
163+
{
164+
"title": "Snapshot",
165+
"mimeType": "text/html"
166+
}
167+
],
168+
"tags": [],
169+
"notes": [],
170+
"seeAlso": []
171+
}
172+
]
173+
}
174+
]
175+
/** END TEST CASES **/

0 commit comments

Comments
 (0)