const translationsStrings = { phoneCode: { cs: "+420 ", sk: "+421 ", pl: "+48 ", }, contactHours: { cs: "Po–Pá 8:00–16:00", sk: "Po–Pá 8:00–16:00", pl: "Pn–Pt 8:00–16:00", }, showAllCategories: { cs: "Zobrazit další kategorie", sk: "Zobraziť ďalšie kategórie", pl: "Pokaż więcej kategorii", }, showNext: { cs: "Zobrazit další", sk: "Zobraziť ďalšie", pl: "Pokaż więcej", }, moreButtonMoreThanFour: { cs: "dalších ", sk: "ďalších ", pl: "kolejnych ", }, moreButtonLessThanFour: { cs: "další ", sk: "ďalšie ", pl: "kolejne ", }, moreButtonOne: { cs: "další ", sk: "ďalšia ", pl: "kolejna ", }, more: { cs: "Více", sk: "Viac", pl: "Więcej", }, moreThan: { cs: "více než ", sk: "viac ako ", pl: "więcej niż ", }, cartTotalLabel: { cs: "Cena celkem", sk: "Cena spolu", pl: "Cena łącznie", }, customFilterButton: { cs: "Filtrování výsledků", sk: "Filtrovanie výsledkov", pl: "Filtrowanie wyników", }, selectedFilters: { cs: "Vybrané filtry", sk: "Vybrané filtre", pl: "Wybrane filtry", }, product: { cs: "Produkt", sk: "Produkt", pl: "Produkt", }, verifiedReviews: { cs: "Ověřená hodnocení", sk: "Overené hodnotenia", pl: "Zweryfikowane opinie", }, shopRatingUrl: { cs: "/hodnoceni-obchodu", sk: "/hodnotenie-obchodu", pl: "/opinie-o-sklepie", }, noSaleCoupon: { cs: "U tohoto produktu není možné uplatnit slevový kód.", sk: "U tohto produktu nie je možné uplatniť zľavový kód.", pl: "U tego produktu nie można zastosować kodu rabatowego.", }, noLoyaltySale: { cs: "U tohoto produktu není možné uplatnit věrnostní slevu.", sk: "U tohto produktu nie je možné uplatniť vernostnú zľavu.", pl: "U tego produktu nie można zastosować zniżki lojalnościowej.", }, denDetiKupon: { cs: "Na tento produkt lze uplatnit kód PRODETI10 pro 10% slevu.", sk: "Na tento produkt je možné uplatniť kód PREDETI10 pre 10% zľavu.", pl: "Na ten produkt można użyć kod rabatowy DLADZIECI10 ze zniżką 10%.", }, descriptionTitle: { cs: "Popis", sk: "Popis", pl: "Opis", }, directionsTitle: { cs: "Dávkování", sk: "Dávkovanie", pl: "Dawkowanie", }, ingredientsTitle: { cs: "Složení", sk: "Zloženie", pl: "Skład", }, certificatesTitle: { cs: "Certifikáty", sk: "Certifikáty", pl: "Certyfikaty", }, reviewsTitle: { cs: "Hodnocení", sk: "Hodnotenie", pl: "Opinie", }, weSupportTitle: { cs: "Pomáháme", sk: "Pomáhame", pl: "Pomagamy", }, relatedProductsTitle: { cs: "Související produkty", sk: "Súvisiace produkty", pl: "Produkty powiązane", }, showRelatedProducts: { cs: "Zobrazit související produkty", sk: "Zobraziť súvisiace produkty", pl: "Pokaż produkty powiązane", }, relatedFilesTitle: { cs: "Dokumenty", sk: "Dokumenty", pl: "Dokumenty", }, show: { cs: "Zobrazit", sk: "Zobraziť", pl: "Pokaż", }, showCertificate: { cs: "Zobrazit certifikát", sk: "Zobraziť certifikát", pl: "Pokaż certyfikat", }, outOf: { cs: "z", sk: "z", pl: "z", }, natiosDescription: { cs: "Natios je česká značka, která se zaměřuje na výrobu kvalitních doplňků stravy s čistým složením bez zbytečných příměsí, konzervantů a éček.", sk: "Natios je česká značka, ktorá sa zameriava na výrobu kvalitných doplnkov stravy s čistým zložením bez zbytočných prísad, konzervantov a éčok.", pl: "Natios to czeska marka, która koncentruje się na produkcji wysokiej jakości suplementów diety o czystym składzie – bez zbędnych domieszek, konserwantów i sztucznych dodatków (E).", }, natiosSupportTextTop: { cs: "Nákupem přispějete 1 Kč dětské hematoonkologii.", sk: "Nákupom prispievate 1 Kč detskej hematoonkológii.", pl: "Kupując, wspierasz dziecięcą hematoonkologię kwotą 1 CZK.", }, natiosSupportHeaderBottom: { cs: "
' + translationsStrings.natiosDescription[activeLang] + '' + translationsStrings.more[activeLang] + '
' + translationsStrings.natiosSupportTextTop[activeLang] + '' + translationsStrings.more[activeLang] + "
" + translationsStrings.natiosSupportTextBottom[activeLang] + "
" + translationsStrings.natiosSupportTotalAmount[activeLang] + '
" + translationsStrings.noSaleCoupon[activeLang] + "
"); } if ($(".nelze-uplatnit-vernostni-slevu").length > 0) { $(".nelze-uplatnit-vernostni-slevu").html("" + translationsStrings.noLoyaltySale[activeLang] + "
"); } function addDenDetiTextToShortDescription() { if (!shortDescription) return; const denDetiFlag = document.querySelector(".product-top .flag-dendeti10"); if (!denDetiFlag) return; const denDetiDiv = document.createElement("div"); denDetiDiv.className = "den-deti-text"; const denDetiText = document.createElement("p"); denDetiText.innerHTML = translationsStrings.denDetiKupon[activeLang]; denDetiDiv.appendChild(denDetiText); shortDescription.appendChild(denDetiDiv); } addDenDetiTextToShortDescription(); document.addEventListener("DOMContentLoaded", function () { let thumbnailsWrapper = document.querySelector(".p-thumbnails-inner"); let thumbnailsParent = document.querySelector(".p-thumbnails-inner > div"); let thumbnails = document.querySelectorAll(".p-thumbnail"); if (thumbnails && thumbnailsParent && thumbnailsWrapper) { inicializeSliderElement(thumbnailsWrapper, thumbnailsParent, thumbnails, "thumbnails-slider", null); } inicializeReviewFromEmail(); }); function inicializeReviewFromEmail() { if (window.location.hash !== "#ratingTab") return; const params = new URLSearchParams(window.location.search); const name = params.get("name"); const trigger = document.querySelector("#ratingTab .rate-form-trigger"); if (trigger) trigger.click(); if (name) { const nameInput = document.querySelector('#ratingTab input[name="fullName"]'); if (nameInput) nameInput.value = name; } } /*Možnosti doručení popup*/ editDeliveryPricesPopup(); function editDeliveryPricesPopup() { let lastShippingCheck = Date.now(); const observerShippingOptions = new MutationObserver((mutationsList, observer) => { for (const mutation of mutationsList) { if (mutation.type === "childList") { const shippingOptionsPopup = document.querySelector(".shipping-options-popup"); const now = Date.now(); if (shippingOptionsPopup) { if (now - lastShippingCheck < 1000) { return; // Skip if the last check was less than 1 second ago } lastShippingCheck = now; /* observer.disconnect(); */ changePricesInShippingTooltip(); } } } }); observerShippingOptions.observe(document.body, { childList: true, subtree: true }); function changePricesInShippingTooltip() { let shippingOptionsPopup = document.querySelector(".shipping-options-popup"); if (!shippingOptionsPopup) return; let priceRange = shippingOptionsPopup.querySelector(".price-range"); if (!priceRange) return; let shippingPrices = {}; if (csLang) { shippingPrices = { "Zásilkovna (Odběrné místo)": "49 Kč", "Balíkovna - ČP (Výdejní místa)": "49 Kč", "DPD (Pick Up) - Výdejní místa": "49 Kč", "DPD (Doručení na adresu)": "79 Kč", "Balíkovna na adresu - ČP": "85 Kč", "Zásilkovna (Doručení na adresu)": "89 Kč", }; } if (skLang) { shippingPrices = { "Zásilkovna Z-point (odberné miesto)": "€3,20", "Slovenská pošta – Balík na poštu": "€2,80", "Slovenská pošta – Balík do BalíkoBOXU": "€2,80", "Slovenská pošta – Kuriér na adresu": "€3,30", "DPD (doručenie na adresu)": "€4,20", "Zásielkovňa (doručenie na adresu)": "€4,50", }; } if (plLang) { shippingPrices = { "UPS - Kurier na adres następnego dnia roboczego": "18 zł", "Inpost - Kurier na adres": "15 zł", "Inpost - Paczkomaty 24/7": "13 zł", }; } document.querySelectorAll(".shipping-billing-name").forEach((nameEl) => { const name = nameEl.textContent.trim().replace(/\s+/g, " "); const price = shippingPrices[name]; if (price) { const priceEl = nameEl.closest(".shipping-row")?.querySelector(".payment-shipping-price"); if (priceEl) { priceEl.textContent = price; priceEl.classList.remove("for-free"); } } }); } } } /*------------------------------------------------- Index*/ let addedWhiteBanners; let allProductsBlocks = document.querySelectorAll(".products-block"); let hodnoceniObchoduAdded = false; if (body.classList.contains("in-index")) { let carousel = document.querySelector("#carousel"); let carouselInner = document.querySelector(".carousel-inner"); let carouselItems = document.querySelectorAll("#carousel .item"); inicializeSliderElement(carousel, carouselInner, carouselItems, "carousel-slider", "a"); addedWhiteBanners = false; if (!addedWhiteBanners) { if (indexesOfWhiteBanners) { carouselItems.forEach((item, index) => { if (indexesOfWhiteBanners.includes(index)) { item.classList.add("white"); } }); } addedWhiteBanners = true; } document.addEventListener("DOMContentLoaded", function () { customLazyVideos(); }); function customLazyVideos() { let lazyVideos = document.querySelectorAll("a.carousel-video-lazy"); if (!lazyVideos || lazyVideos.length === 0) { return; } lazyVideos.forEach(function (videoLink) { let video = videoLink.querySelector("video"); if (video && !video.classList.contains("loaded")) { let sources = video.querySelectorAll("source"); sources.forEach(function (source) { let dataSrc = source.getAttribute("data-src"); if (dataSrc) { source.setAttribute("src", dataSrc); } }); // Listen for the video to be fully loaded video.addEventListener("loadeddata", function onLoaded() { videoLink.classList.add("loaded"); video.classList.add("loaded"); video.removeEventListener("loadeddata", onLoaded); }); video.load(); } }); } allProductsBlocks = document.querySelectorAll(".products-block"); if (allProductsBlocks && allProductsBlocks.length > 0) { allProductsBlocks.forEach((block) => { let productsBlockItems = block.querySelectorAll(".product"); inicializeSliderElement(null, block, productsBlockItems, "products-slider", "img"); }); } footerNatiosBanner(); function footerNatiosBanner() { let footerBanner = document.querySelector(".footer-banner"); if (!footerBanner) { console.warn("Footer banner not found."); return; } // Move the footer banner after the second products block allProductsBlocks = document.querySelectorAll(".products-block"); if (allProductsBlocks && allProductsBlocks.length >= 2) { allProductsBlocks[1].parentElement.insertAdjacentElement("afterend", footerBanner.parentElement); } else { console.warn("Not enough products blocks to move the footer banner."); } } hodnoceniObchoduAdded = false; welcomeWrapper(); function welcomeWrapper() { let welcomeSection = document.querySelector(".welcome-wrapper .welcome"); let welcomeWrapper = document.querySelector(".welcome-wrapper"); if (welcomeSection) { let h1Element = welcomeSection.querySelector("h1"); let welcomeTexts = welcomeSection.querySelector(".homepage-welcome-texts"); if (h1Element && welcomeTexts) { welcomeTexts.prepend(h1Element); } let homepageBlogWrapper = document.querySelector(".homepage-blog-wrapper"); if (homepageBlogWrapper && welcomeWrapper) { homepageBlogWrapper.parentNode.insertBefore(welcomeWrapper, homepageBlogWrapper); hodnoceniObchodu(); } else { console.warn("Homepage blog not found in the wrapper."); } } } document.addEventListener("votesWrapLoaded", () => { let votesWrap = document.querySelector(".votes-wrap"); let votesItems = document.querySelectorAll(".votes-wrap .vote-wrap"); inicializeSliderElement(null, votesWrap, votesItems, "votes-slider", null); }); hodnoceniObchodu(); async function hodnoceniObchodu() { if (plLang) { return; // Skip for Polish language } if (hodnoceniObchoduAdded) { return; } hodnoceniObchoduAdded = true; const hodnoceniObchoduSection = document.createElement("div"); hodnoceniObchoduSection.className = "hodnoceni-obchodu-section"; const hodnoceniTitle = document.createElement("h2"); hodnoceniTitle.className = "hodnoceni-obchodu-title"; hodnoceniTitle.textContent = translationsStrings.verifiedReviews[activeLang]; let welcomeWrapper = document.querySelector(".welcome-wrapper"); if (welcomeWrapper) { welcomeWrapper.parentNode.insertBefore(hodnoceniObchoduSection, welcomeWrapper); } hodnoceniObchoduSection.appendChild(hodnoceniTitle); let fetchAddress = translationsStrings.shopRatingUrl[activeLang]; if (isTestEshop) { fetchAddress = "/hodnoceni-obchodu.html"; } //get .content-inner from the adress and append it to the hodnoceniObchoduSection try { const response = await fetch(fetchAddress); if (!response.ok) { throw new Error("Failed to fetch data from the server."); } const html = await response.text(); const parser = new DOMParser(); const doc = parser.parseFromString(html, "text/html"); const votesWrap = doc.querySelector(".votes-wrap"); let numberOfReviews = doc.querySelector("#ratingWrapper .stars-label"); //change span number of reviews to a let numberOfReviewsLink = document.createElement("a"); if (numberOfReviews) { numberOfReviewsLink.href = fetchAddress; numberOfReviewsLink.classList.add("stars-label-link"); numberOfReviewsLink.appendChild(numberOfReviews); } if (votesWrap) { hodnoceniObchoduSection.appendChild(numberOfReviewsLink); hodnoceniObchoduSection.appendChild(votesWrap); console.log("CUSTOM EVENT DISPATCHED: votesWrapLoaded"); document.dispatchEvent(new CustomEvent("votesWrapLoaded")); } else { console.warn("No .content-inner found in the fetched content."); } } catch (error) { console.error("Error fetching or processing hodnoceni obchodu:", error); } } homepageGroupTitlesFunc(); function homepageGroupTitlesFunc() { let homepageGroupTitles = document.querySelectorAll(".homepage-group-title"); if (!homepageGroupTitles || homepageGroupTitles.length === 0) { return; } let zobrazitVseTexty = []; let nejprodavanejsiUrl = ""; let novinkyUrl = ""; let akceUrl = ""; let blogUrl = ""; if (document.body.classList.contains("cs")) { zobrazitVseTexty = [ "Zobrazit všechny nejprodávanější", "Zobrazit všechny novinky", "Zobrazit všechny akce", "Zobrazit všechny články", ]; nejprodavanejsiUrl = "/nejprodavanejsi/"; novinkyUrl = "/novinky/"; akceUrl = "/-akce-mesice/"; /* akceUrl = "/black-friday/"; */ blogUrl = "/blog/"; } if (document.body.classList.contains("sk")) { zobrazitVseTexty = [ "Zobraziť všetky najpredávanejšie", "Zobraziť všetky novinky", "Zobraziť všetky akcie", "Zobraziť všetky články", ]; nejprodavanejsiUrl = "/najpredavanejsie/"; novinkyUrl = "/novinky/"; akceUrl = "/--akcie-mesiaca/"; /* akceUrl = "/black-friday/"; */ blogUrl = "/blog/"; } if (document.body.classList.contains("pl")) { zobrazitVseTexty = [ "Zobacz wszystkie najczęściej kupowane", "Zobacz wszystkie nowości", "Zobacz wszystkie promocje", "Zobacz wszystkie artykuły", ]; nejprodavanejsiUrl = "/najczesciej-kupowane/"; novinkyUrl = "/nowosci/"; akceUrl = "/promocja-miesiaca/"; /* akceUrl = "/black-friday/"; */ blogUrl = "/blog/"; } const titleUrlMap = [nejprodavanejsiUrl, novinkyUrl, akceUrl, blogUrl]; homepageGroupTitles.forEach((titleElement, index) => { const titleHref = document.createElement("a"); titleHref.href = titleUrlMap[index] || "#"; titleHref.classList.add("homepage-group-title-link"); titleHref.textContent = titleElement.textContent; titleElement.innerHTML = titleHref.outerHTML; const titleHrefShowAll = document.createElement("a"); titleHrefShowAll.href = titleUrlMap[index] || "#"; titleHrefShowAll.classList.add("homepage-group-title-show-all"); titleHrefShowAll.classList.add("desktop"); titleHrefShowAll.textContent = zobrazitVseTexty[index] || "Show All"; titleElement.appendChild(titleHrefShowAll); let titleHrefShowAllBottom = titleHrefShowAll.cloneNode(true); titleHrefShowAllBottom.classList.remove("desktop"); titleHrefShowAllBottom.classList.add("mobile"); if (index !== 3) { // Find the next sibling .products-block-wrapper let sibling = titleElement.nextElementSibling; while (sibling && !sibling.classList.contains("products-slider")) { sibling = sibling.nextElementSibling; } if (sibling) { sibling.appendChild(titleHrefShowAllBottom); } } else { const homepageBlogWrapper = document.querySelector(".homepage-blog-wrapper"); if (homepageBlogWrapper) { homepageBlogWrapper.appendChild(titleHrefShowAllBottom); } } }); } } /*-------------------------------------------------- LUPA NA MOBILU VYHLEDEAVANI*/ let searchElement = document.querySelector("#header .search"); const searchInput = document.querySelector("#header .search .search-input"); if (searchInput) { searchElement.addEventListener("click", (e) => { if (e.target !== searchInput) { searchInput.classList.toggle("active"); if (searchInput.classList.contains("active")) { body.classList.add("custom-search-active"); searchInput.focus(); setTimeout(() => { function outsideClickHandler(f) { const luigiAc = document.querySelector(".luigi-ac"); const luigiAcClose = document.querySelector(".luigi-ac-close"); const luigiShowAll = document.querySelector(".luigi-ac-button-block--show-all .luigi-ac-button"); if (f.target == luigiAcClose || f.target == luigiShowAll) { searchInput.classList.remove("active"); document.removeEventListener("click", outsideClickHandler); body.classList.remove("custom-search-active"); } if (f.target !== searchInput && (!luigiAc || !luigiAc.contains(f.target))) { searchInput.classList.remove("active"); document.removeEventListener("click", outsideClickHandler); body.classList.remove("custom-search-active"); } } document.addEventListener("click", outsideClickHandler); document.addEventListener("luigiSearchDone", function () { searchInput.classList.remove("active"); body.classList.remove("custom-search-active"); document.removeEventListener("click", outsideClickHandler); }); }, 200); } } }); } let luigiHero = document.querySelector(".luigi-ac-hero"); if (searchElement && searchInput) { searchElement.addEventListener("click", function () { if (luigiHero) { luigiHero.classList.toggle("active"); } }); } /* document.addEventListener("luigiSearchDone", function () { addSwapImageLuigi(); function addSwapImageLuigi() { let lbResults = document.querySelector("#lb-results"); console.log(lbResults); if (!lbResults) { return; } let luigiProducts = lbResults.querySelectorAll(".product"); if (!luigiProducts || luigiProducts.length < 1) { return; } luigiProducts.forEach((product) => { let swapImage = product.querySelector(".swap-image"); if (!swapImage) { return; } let mainImage = swapImage.src; let nextImage = swapImage.getAttribute("data-next"); if (mainImage && nextImage) { product.addEventListener("mouseenter", function () { swapImage.src = nextImage; }); product.addEventListener("mouseleave", function () { swapImage.src = mainImage; }); } }); } }); */ /*custom scroll to anchor*/ document.addEventListener("DOMContentLoaded", function () { // Check if there's an anchor in the URL if (window.location.hash) { const anchor = window.location.hash.replace(/^[#\/]+|\/+$/g, ""); const target = document.getElementById(anchor); if (target) { // Scroll to the element with a small offset (e.g., 80px) const offset = 80; const elementPosition = target.getBoundingClientRect().top + window.pageYOffset; window.scrollTo({ top: elementPosition - offset, behavior: "smooth", }); } } }); /*-----------------------------------------------------BLOG*/ if (document.body.classList.contains("in-blog") && document.body.classList.contains("type-post")) { document.addEventListener("DOMContentLoaded", function () { oldBlog(); function oldBlog() { let timeElement = $(".news-item-detail time[datetime]"); let dateStr = timeElement.attr("datetime"); let [day, month, year] = dateStr.split(".").map(Number); let date = new Date(year, month - 1, day); let comparisonDate = new Date(2024, 6, 31); if (date < comparisonDate) { $("body").addClass("old-blog"); } else { articleNav(); blogAutor(); fetchAndAppendRelatedBlogs(); fetchAndAppendBlogProducts3(); fetchAndAppendBlogProducts2(); fetchAndAppendBlogProducts1(); fetchAndAppendBlogProducts(); fetchAndAppendBlogCategory(); } } function blogAutor() { $("#content p").each(function () { if (/##AUTOR##KATEŘINAT/i.test($(this).text())) { if (document.body.classList.contains("cs")) { $(this).replaceWith( '', ); } if (document.body.classList.contains("sk")) { $(this).replaceWith( '', ); } if (document.body.classList.contains("pl")) { $(this).replaceWith( '', ); } } if (/##AUTOR##BARBORAP/i.test($(this).text())) { if (document.body.classList.contains("cs")) { $(this).replaceWith( ` `, ); } if (document.body.classList.contains("sk")) { $(this).replaceWith( ` `, ); } if (document.body.classList.contains("pl")) { $(this).replaceWith( ` `, ); } } if (/##AUTOR##TEREZABERGLOWCOVA/i.test($(this).text())) { if (document.body.classList.contains("cs")) { $(this).replaceWith( ` `, ); } if (document.body.classList.contains("sk")) { $(this).replaceWith( ` `, ); } if (document.body.classList.contains("pl")) { $(this).replaceWith( ` `, ); } } }); } function generateId(text) { return text .normalize("NFD") .replace(/[\u0300-\u036f]/g, "") .replace(/\s+/g, "-") .toLowerCase(); } function articleNav() { const content = document.querySelector("#content"); const headings = Array.from(content.querySelectorAll("h2, h3, h4, h5")); const nav = document.createElement("div"); nav.classList.add("article-nav"); const navList = document.createElement("ul"); let currentUl = navList; let lastLevel = 2; // Remove the last h3 from the list const lastH3Index = headings.map((h) => h.tagName).lastIndexOf("H3"); if (lastH3Index !== -1) { headings.splice(lastH3Index, 1); } headings.forEach((heading) => { const level = parseInt(heading.tagName.substring(1)); const id = generateId(heading.textContent); heading.id = id; const li = document.createElement("li"); const a = document.createElement("a"); a.href = `#${id}`; a.textContent = heading.textContent; li.appendChild(a); if (level > lastLevel) { const newUl = document.createElement("ul"); currentUl.lastElementChild.appendChild(newUl); currentUl = newUl; } else if (level < lastLevel) { currentUl = navList; for (let i = 2; i < level; i++) { currentUl = currentUl.lastElementChild.querySelector("ul"); } } currentUl.appendChild(li); lastLevel = level; }); const articleContent = document.createElement("div"); articleContent.classList.add("article-content"); articleContent.appendChild(navList); const whatFind = document.createElement("div"); whatFind.id = "open-article-nav"; const span1whatFind = document.createElement("span"); const span2whatFind = document.createElement("span"); const spanShow = document.createElement("span"); const spanHide = document.createElement("span"); if (document.body.classList.contains("cs")) { span1whatFind.textContent = "Co v článku najdete?"; spanShow.textContent = "Zobrazit seznam"; spanHide.textContent = "Skrýt seznam"; } if (document.body.classList.contains("sk")) { span1whatFind.textContent = "Čo v článku nájdete?"; spanShow.textContent = "Zobraziť zoznam"; spanHide.textContent = "Skryť zoznam"; } if (document.body.classList.contains("pl")) { span1whatFind.textContent = "Co znajdziesz w artykule?"; spanShow.textContent = "Pokaż listę"; spanHide.textContent = "Ukryj listę"; } whatFind.appendChild(span1whatFind); spanShow.classList.add("show-article"); span2whatFind.appendChild(spanShow); spanHide.classList.add("hide-article"); span2whatFind.appendChild(spanHide); whatFind.appendChild(span2whatFind); nav.appendChild(whatFind); nav.appendChild(articleContent); whatFind.addEventListener("click", function () { nav.classList.toggle("open"); }); // Insert after the first img in #content const firstImg = content.querySelector("img"); if (firstImg) { const parent = firstImg.parentElement; parent.insertAdjacentElement("afterend", nav); } else { content.insertBefore(nav, content.firstChild); } document.querySelectorAll(".article-nav a").forEach((anchor) => { anchor.addEventListener("click", function (e) { e.preventDefault(); const targetId = this.getAttribute("href").substring(1); const targetElement = document.getElementById(targetId); let offsetPosition = 0; if (!isMobile) { offsetPosition = targetElement.getBoundingClientRect().top + window.scrollY - 150; } else { offsetPosition = targetElement.getBoundingClientRect().top + window.scrollY - 80; } window.scrollTo({ top: offsetPosition, behavior: "smooth", }); }); }); } async function fetchAndAppendRelatedBlogs() { let blogURLs = []; let maxNumberOfBlogs = 5; $("#content p").each(function () { let text = $(this).text(); if (/##BLOG##/i.test(text)) { let urlMatch = text.match(/https?:\/\/[^\s]+/); if (urlMatch && blogURLs.length < maxNumberOfBlogs) { blogURLs.push(urlMatch[0]); } $(this).remove(); $("#content .next-prev").remove(); } }); if (blogURLs.length > 0) { let relatedBlogsDiv = $("").text(metaDescription); // Append the img, section paragraph, and description paragraph elements to the anchor element anchorElement.append(blogImage); anchorElement.append(blogName); anchorElement.append(blogDescdription); // Append the anchor element to the relatedBlogsDiv relatedBlogsDiv.append(anchorElement); } } catch (error) { console.error("Error fetching related blog data:", error); } } // Append the relatedBlogsDiv to the body $(".content-wrapper-in").append(showBlogHeading); $(".content-wrapper-in").append(relatedBlogsDiv); $(".content-wrapper-in").append(showBlogButton); $(".content-wrapper-in").append($(".comments")); $(".content-wrapper-in").append($(".share")); } } async function fetchAndAppendBlogProducts() { let productURLs = []; let firstProductParagraph = null; let maxNumberOfProducts = 4; $("#content p").each(function () { let text = $(this).text(); if (/##PRODUKT##/i.test(text)) { if (!firstProductParagraph) { firstProductParagraph = $(this); } let urlMatch = text.match(/https?:\/\/[^\s]+/); if (urlMatch && productURLs.length < maxNumberOfProducts) { productURLs.push(urlMatch[0]); } } }); if (productURLs.length > 0 && firstProductParagraph) { let blogProductsDiv = $("
").text(metaName.getAttribute("content")); // Append the img element and the paragraph element to the anchor element anchorElement.append(blogImage); anchorElement.append(productName); // Append the anchor element to the blogProductsDiv blogProductsDiv.append(anchorElement); } } catch (error) { console.error("Error fetching product data:", error); } } // Insert the blogProductsDiv before the first found paragraph firstProductParagraph.before(blogProductsDiv); // Remove the paragraphs containing ##PRODUKT## $("p").each(function () { let text = $(this).text(); if (/##PRODUKT##/i.test(text)) { $(this).remove(); } }); } } async function fetchAndAppendBlogProducts1() { let productURLs = []; let firstProductParagraph = null; let maxNumberOfProducts = 4; $("#content p").each(function () { let text = $(this).text(); if (/##PRODUKT##1/i.test(text)) { if (!firstProductParagraph) { firstProductParagraph = $(this); } let urlMatch = text.match(/https?:\/\/[^\s]+/); if (urlMatch && productURLs.length < maxNumberOfProducts) { productURLs.push(urlMatch[0]); } } }); if (productURLs.length > 0 && firstProductParagraph) { let blogProductsDiv = $("
").text(metaName.getAttribute("content"));
// Create an img element
let blogImage = $("", {
src: metaImage.getAttribute("content"),
alt: productName.text(),
loading: "lazy",
});
// Append the img element and the paragraph element to the anchor element
anchorElement.append(blogImage);
anchorElement.append(productName);
/* const showBtn = document.createElement("div");
showBtn.classList.add("show-product-btn");
showBtn.textContent = "Zobrazit produkt";
anchorElement.append(showBtn); */
// Append the anchor element to the blogProductsDiv
blogProductsDiv.append(anchorElement);
}
} catch (error) {
console.error("Error fetching product data:", error);
}
}
// Insert the blogProductsDiv before the first found paragraph
firstProductParagraph.before(blogProductsDiv);
// Remove the paragraphs containing ##PRODUKT##
$("p").each(function () {
let text = $(this).text();
if (/##PRODUKT##1/i.test(text)) {
$(this).remove();
}
});
}
}
async function fetchAndAppendBlogProducts2() {
let productURLs = [];
let firstProductParagraph = null;
let maxNumberOfProducts = 4;
$("#content p").each(function () {
let text = $(this).text();
if (/##PRODUKT##2/i.test(text)) {
if (!firstProductParagraph) {
firstProductParagraph = $(this);
}
let urlMatch = text.match(/https?:\/\/[^\s]+/);
if (urlMatch && productURLs.length < maxNumberOfProducts) {
productURLs.push(urlMatch[0]);
}
}
});
if (productURLs.length > 0 && firstProductParagraph) {
let blogProductsDiv = $("
").text(metaName.getAttribute("content"));
// Create an img element
let blogImage = $("", {
src: metaImage.getAttribute("content"),
alt: productName.text(),
loading: "lazy",
});
// Append the img element and the paragraph element to the anchor element
anchorElement.append(blogImage);
anchorElement.append(productName);
/*
const showBtn = document.createElement("div");
showBtn.classList.add("show-product-btn");
showBtn.textContent = "Zobrazit produkt";
anchorElement.append(showBtn); */
// Append the anchor element to the blogProductsDiv
blogProductsDiv.append(anchorElement);
}
} catch (error) {
console.error("Error fetching product data:", error);
}
}
// Insert the blogProductsDiv before the first found paragraph
firstProductParagraph.before(blogProductsDiv);
// Remove the paragraphs containing ##PRODUKT##
$("p").each(function () {
let text = $(this).text();
if (/##PRODUKT##2/i.test(text)) {
$(this).remove();
}
});
}
}
async function fetchAndAppendBlogProducts3() {
let productURLs = [];
let firstProductParagraph = null;
let maxNumberOfProducts = 4;
$("#content p").each(function () {
let text = $(this).text();
if (/##PRODUKT##3/i.test(text)) {
if (!firstProductParagraph) {
firstProductParagraph = $(this);
}
let urlMatch = text.match(/https?:\/\/[^\s]+/);
if (urlMatch && productURLs.length < maxNumberOfProducts) {
productURLs.push(urlMatch[0]);
}
}
});
if (productURLs.length > 0 && firstProductParagraph) {
let blogProductsDiv = $("
").text(metaName.getAttribute("content"));
// Create an img element
let blogImage = $("", {
src: metaImage.getAttribute("content"),
alt: productName.text(),
loading: "lazy",
});
// Append the img element and the paragraph element to the anchor element
anchorElement.append(blogImage);
anchorElement.append(productName);
/* const showBtn = document.createElement("div");
showBtn.classList.add("show-product-btn");
showBtn.textContent = "Zobrazit produkt";
anchorElement.append(showBtn); */
// Append the anchor element to the blogProductsDiv
blogProductsDiv.append(anchorElement);
}
} catch (error) {
console.error("Error fetching product data:", error);
}
}
// Insert the blogProductsDiv before the first found paragraph
firstProductParagraph.before(blogProductsDiv);
// Remove the paragraphs containing ##PRODUKT##
$("p").each(function () {
let text = $(this).text();
if (/##PRODUKT##3/i.test(text)) {
$(this).remove();
}
});
}
}
fetchAndAppendBlogCategory();
async function fetchAndAppendBlogCategory() {
let productRequests = [];
let maxNumberOfProducts = 4;
$("#content p").each(function () {
let text = $(this).text();
if (/##KATEGORIE##/i.test(text)) {
let match = text.match(/##KATEGORIE##(\d+)\s+(https?:\/\/[^\s]+)/);
if (match) {
let numberOfProducts = Math.min(parseInt(match[1], 10), maxNumberOfProducts);
let url = match[2];
productRequests.push({ numberOfProducts, url, paragraph: $(this) });
}
}
});
if (productRequests.length > 0) {
for (let request of productRequests) {
let blogProductsDiv = $("