Skip to content

Commit 3490a75

Browse files
authored
Cleanup exceptions (#8)
* chore: remove non existing sites from exceptions * Support for pyszneeko.pl * Remove not supported exceptions * Add support for polskikoszyk * Add suport for emaja and marketbio
1 parent 2ec3f44 commit 3490a75

3 files changed

Lines changed: 40 additions & 28 deletions

File tree

README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ Wspierane sklepy
3737
* https://www.bee.pl/
3838
* https://e-prim.pl
3939
* https://lisek.app/
40+
* https://pyszneeko.pl/
41+
* https://polskikoszyk.pl/
42+
* https://www.emaja24.pl/
43+
* https://marketbio.pl/
4044

4145
Pracujemy nad wsparciem dla
4246
---------------------------
4347
* https://mamyito.pl
44-
* https://polskikoszyk.pl/
4548
* https://zakupy.biedronka.pl/
4649
* https://delio.com.pl/
4750
* https://topaz24.pl/
4851
* https://www.lidl.pl/
49-
* https://www.emaja24.pl/
50-
* https://marketbio.pl/

content_scripts/pola.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,7 @@
22
let domain = document.location.hostname || '';
33
let result = null;
44
let exceptions = {
5-
'www.neo24.pl': ['meta[property="og:image"][content]', 'content', /^.*\/(\d{13}|\d{8})..\.[a-z]{3,4}$/i],
6-
'www.neonet.pl': ['meta[property="og:image"][content]', 'content', /^.*\/(\d{13}|\d{8})..\.[a-z]{3,4}$/i],
7-
'www.megamarket24.pl': ['meta[property="og:url"][content]', 'content', /^.*\-(\d{13}|\d{8})\.html(?:\?.*)?$/i],
8-
'aptekasowa.pl': ['meta[property="og:url"][content]', 'content', /^.*\-(\d{13}|\d{8})\.html(?:\?.*)?$/i],
9-
'yesorganic.pl': ['meta[property="og:url"][content]', 'content', /^.*\-(\d{13}|\d{8})\.html(?:\?.*)?$/i],
10-
'biomarketcompany.pl': ['meta[property="og:url"][content]', 'content', /^.*\-(\d{13}|\d{8})\.html(?:\?.*)?$/i],
11-
'www.tvokazje.pl': ['meta[property="og:url"][content]', 'content', /^.*\-(\d{13}|\d{8})\.html(?:\?.*)?$/i],
12-
'sklepdietetyczny.pl': ['link[rel="canonical"][href]', 'href', /^.*\-(\d{13}|\d{8})\.html$/i],
135
'lisek.app': ['link[rel="canonical"][href]', 'href', /^.*\/(\d{13}|\d{8})$/i],
14-
'studencik.com.pl': ['meta[itemprop="url"][content]', 'content', /^.*\-(\d{13}|\d{8})\.html$/i],
15-
'polskikoszyk.pl': ['img[class="product-main-thumb"][src]', 'src', /^.*\/(\d{13}|\d{8})\.[a-z]{3,4}$/i],
16-
'www.leclerc24.pl': ['#productWindow .item-image img[src]', 'src', /^.*\/(\d{13}|\d{8}).*$/i],
17-
'www.douglas.pl': ['img[id^="addProductToBasketLink_"]', 'id', /^addProductToBasketLink_(\d{13}|\d{8})$/i]
18-
};
19-
let exceptions2 = {
20-
'ezakupy.tesco.pl': [/"gs1:gtin":"(\d{13}|\d{8})(?=")/, document.head],
21-
'www.electro-outlet.pl': [/"code_extern":"(\d{13}|\d{8})(?=")/, document.body],
22-
'pyszneeko.pl': [/"code_extern":"(\d{13}|\d{8})(?=")/, document.body],
23-
'sliv.com.pl': [/"code_producer":"(\d{13}|\d{8})(?=")/, document.body]
246
};
257
if (exceptions.hasOwnProperty(domain)) {
268
let e = exceptions[domain];
@@ -32,13 +14,7 @@
3214
}
3315
}
3416
}
35-
if (exceptions2.hasOwnProperty(domain)) {
36-
let e = exceptions2[domain];
37-
let tmp = e[0].exec(e[1].innerHTML);
38-
if (tmp !== null) {
39-
result = [tmp[1]];
40-
}
41-
}
17+
4218
if (result === null) {
4319
let text = document.body.innerHTML;
4420
text = text.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, ' ');
@@ -62,6 +38,17 @@
6238
for (let elem of flix) {
6339
result.push(elem.getAttribute('data-flix-ean'));
6440
}
41+
// Kody w danych strukturalnych schema.org (JSON-LD) — generyczny skan
42+
// ich nie widzi, bo usuwa wszystkie bloki <script>.
43+
let ldjson = document.querySelectorAll('script[type="application/ld+json"]');
44+
for (let elem of ldjson) {
45+
for (let m of elem.textContent.matchAll(/"gtin(?:13|8)?"\s*:\s*"(\d{13}|\d{8})(?=")/g)) {
46+
if (result === null) {
47+
result = [];
48+
}
49+
result.push(m[1]);
50+
}
51+
}
6552
}
6653
if (result !== null) {
6754
result = result.filter((v, i, a) => a.indexOf(v) === i);

test-e2e/ean-detection.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ const productPages = [
165165
product: 'Kujawski — Olej Kujawski 2 l',
166166
ean: '5900012003608',
167167
url: 'https://e-prim.pl/pl/products/olej-kujawski-2l-11380',
168+
},
169+
{
170+
store: 'polskikoszyk.pl',
171+
product: 'Dega Sałatka pikantna z makrelą 130 g',
172+
ean: '5907623267788',
173+
url: 'https://polskikoszyk.pl/dega-salatka-pikantna-z-makrela-130g',
174+
},
175+
{
176+
store: 'pyszneeko.pl',
177+
product: 'Mąka pszenna tortowa typ 480 1 kg Bio Planet EKO',
178+
ean: '5907814660121',
179+
url: 'https://pyszneeko.pl/product-pol-2744-Maka-pszenna-tortowa-typ-480-1-kg-Bio-Planet-EKO.html?rec=102002101',
180+
},
181+
{
182+
store: 'emaja24.pl',
183+
product: 'Aga-Holtex — Daktyle suszone 120 g',
184+
ean: '5905027000260',
185+
url: 'https://www.emaja24.pl/pl/p/Aga-Holtex-Daktyle-suszone-120g-Bakalie/5470',
186+
},
187+
{
188+
store: 'marketbio.pl',
189+
product: 'Sol Kłodawska kam. nat. do przetworów niej. 1,1 kg',
190+
ean: '5902587000952',
191+
url: 'https://marketbio.pl/sol-klodawska-kam-nat-do-przetworow-niej-1-1-kg.html',
168192
}
169193
];
170194

0 commit comments

Comments
 (0)