PageSourceSearch

https://www.slezak-rav.cz/user/documents/js/main.js?25

js slezak-rav.cz collected 2026-10-08 18:32:27 UTC 5,279 bytes, 114 lines download raw bytes

1$(document).ready(function() {
2    var dalsiTr = $(".extended-description th:contains('dalsiprodukty')").closest("tr");
3    if (dalsiTr.length === 0) return;
4
5    $.ajax({
6        url: "https://www.slezak-rav.cz/nahradnidily.xml",
7        dataType: "text",
8        success: function(rawXml) {
9            var mapCodes = {};
10            
11            // Místo regexu použijeme DOMParser pro přesnou shodu
12            var parser = new DOMParser();
13            var xmlDoc = parser.parseFromString(rawXml, "text/xml");
14            var shopItems = xmlDoc.getElementsByTagName("SHOPITEM");
15
16            for (var i = 0; i < shopItems.length; i++) {
17                var item = shopItems[i];
18                var codeNode = item.getElementsByTagName("CODE")[0];
19                var urlNode = item.getElementsByTagName("URL")[0];
20                
21                if (codeNode && urlNode) {
22                    var code = codeNode.textContent.trim();
23                    var url = urlNode.textContent.trim();
24                    mapCodes[code] = url;
25                }
26            }
27
28            var productsString = dalsiTr.find("td").text().trim();
29            // 1. OŠETŘENÍ DUPLICIT v zadání (aby se nekreslil jeden produkt víckrát)
30            var productCodesRaw = productsString.split(",").map(c => c.trim());
31            var uniqueProductCodes = [...new Set(productCodesRaw)].filter(code => mapCodes[code]);
32
33            if (uniqueProductCodes.length === 0) return;
34
35            var relatedBlock = $(`
36                <div class="related-block">
37                    <h2>Náhradní díly</h2>
38                    <div class="swiper related-swiper">
39                        <div class="swiper-wrapper"></div>
40                        <div class="swiper-pagination"></div>
41                        <div class="swiper-arrow swiper-arrow-prev js-swiper-arrow-prev"><div class="swiper-arrow-content"><span class="icon-svg icon-chevron-left"></span></div></div>
42                        <div class="swiper-arrow swiper-arrow-next js-swiper-arrow-next"><div class="swiper-arrow-content"><span class="icon-svg icon-chevron-right"></span></div></div>
43                    </div>
44                </div>
45            `);
46
47            relatedBlock.appendTo(".type-detail #content-wrapper");
48
49            var swiperLoadedCount = 0;
50            var totalSlides = uniqueProductCodes.length;
51
52            uniqueProductCodes.forEach(function(code) {
53                var url = mapCodes[code];
54
55                $.ajax({
56                    url: url,
57                    method: "GET",
58                    success: function(data) {
59                        var $html = $('<div>').html(data);
60                        
61                        // Zde vytáhneme jen to co potřebujeme
62                        var h1 = $html.find("h1").first().text().trim();
63                        var starsWrapper = $html.find(".stars-wrapper").prop("outerHTML") || '<div class="stars-wrapper">...</div>';
64                        var price = $html.find(".price-final-holder").html() || `<strong>Cena u prodejce</strong>`;
65                        var imageSrc = $html.find(".p-image img").attr("src") || "";
66
67                        var slide = `
68                        <div class="swiper-slide" data-code="${code}">
69                            <div class="product active related-sm-screen-show no-code no-button">
70                                <div class="p">
71                                    <a href="${url}" class="image" style="max-height:203px;"><img src="${imageSrc}" alt="${h1}"></a>
72                                    <div class="p-in">
73                                        <div class="p-in-in">
74                                            <div class="ratings-wrapper">${starsWrapper}</div>
75                                            <a href="${url}" class="name"><span>${h1}</span></a>
76                                        </div>
77                                        <div class="p-bottom no-buttons">
78                                            <div class="prices"><div class="price price-final">${price}</div></div>
79                                        </div>
80                                    </div>
81                                </div>
82                            </div>
83                        </div>`;
84
85                        relatedBlock.find(".swiper-wrapper").append(slide);
86
87                        swiperLoadedCount++;
88                        if (swiperLoadedCount === totalSlides) {
89                            initSwiper();
90                        }
91                    }
92                });
93            });
94        }
95    });
96
97    function initSwiper() {
98        new Swiper('.related-swiper', {
99            slidesPerView: 4,
100            spaceBetween: 20,
101            navigation: {
102                nextEl: '.js-swiper-arrow-next',
103                prevEl: '.js-swiper-arrow-prev',
104            },
105            pagination: { el: '.swiper-pagination', clickable: true },
106            breakpoints: {
107                0:   { slidesPerView: 'auto', spaceBetween: 8 },
108                576: { slidesPerView: 2, spaceBetween: 15 },
109                992: { slidesPerView: 3, spaceBetween: 20 },
110                1430:{ slidesPerView: 4, spaceBetween: 20 }
111            }
112        });
113    }
114});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.