|
2 | 2 | let domain = document.location.hostname || ''; |
3 | 3 | let result = null; |
4 | 4 | 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], |
13 | 5 | '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] |
24 | 6 | }; |
25 | 7 | if (exceptions.hasOwnProperty(domain)) { |
26 | 8 | let e = exceptions[domain]; |
|
32 | 14 | } |
33 | 15 | } |
34 | 16 | } |
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 | + |
42 | 18 | if (result === null) { |
43 | 19 | let text = document.body.innerHTML; |
44 | 20 | text = text.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, ' '); |
|
62 | 38 | for (let elem of flix) { |
63 | 39 | result.push(elem.getAttribute('data-flix-ean')); |
64 | 40 | } |
| 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 | + } |
65 | 52 | } |
66 | 53 | if (result !== null) { |
67 | 54 | result = result.filter((v, i, a) => a.indexOf(v) === i); |
|
0 commit comments