PageSourceSearch

https://www.gn2.de/wp-content/themes/astra-child/script.js?ver=1

js gn2.de collected 2026-10-04 02:41:03 UTC 9,725 bytes, 208 lines download raw bytes

1const kundenstimmenTeaser = document.querySelectorAll('div.kundenstimmen-teaser')
2if (kundenstimmenTeaser.length > 1) {
3    const randomKey = Math.floor(Math.random() * (kundenstimmenTeaser.length));
4    kundenstimmenTeaser.forEach(function (el, idx) {
5        if (idx !== randomKey) {
6            el.style.display = "none";
7        }
8    });
9}
10
11
12/** Astra Live-Suche Ergebnisse um FAQ-Kategorien ergänzen (Chat GPT)
13 * **/
14(function () {
15    function decodeHTMLEntities(string) {
16        var doc = new DOMParser().parseFromString(string, "text/html");
17        return doc.documentElement.textContent;
18    }
19
20    function getSearchResultPostMarkup(resultsData) {
21        let processedHtml = "";
22
23        Object.entries(resultsData).map(([postType, postsData]) => {
24            let postTypeLabel = astra_search.search_post_types_labels[postType]
25                ? astra_search.search_post_types_labels[postType]
26                : postType + "s";
27            processedHtml += `<label class="ast-search--posttype-heading"> ${postTypeLabel} </label>`;
28
29            // Füge die Ergebnisse erst hinzu, wenn alles vorbereitet ist
30            postsData.forEach((post) => {
31                const searchPostTitle = decodeHTMLEntities(post.title.rendered);
32                const faqCategories = post.faq_categories ? `<div class="faq-category">${post.faq_categories}</div>` : '';
33                const blogCategories = post.blog_categories ? `<div class="faq-category">${post.blog_categories}</div>` : '';
34                // Sammle das gesamte HTML für jedes Suchergebnis
35                processedHtml += `<a class="ast-search-item" role="option" target="_self" href="${post.link}">
36					<span>${searchPostTitle}</span>${faqCategories}${blogCategories}
37				</a>`;
38            });
39        });
40
41        return processedHtml;
42    }
43
44    window.addEventListener("load", function (e) {
45        var liveSearchTimer;
46        var liveSearchTimerSensitivity = 250;
47
48        const searchInputs = document.querySelectorAll('[name="s"]');
49        searchInputs.forEach((searchInput) => {
50            searchInput.addEventListener("input", function (event) {
51                // 24-21321 blocke "original" snippet aus live-search.min.js
52                event.stopImmediatePropagation();
53
54                liveSearchTimer && clearTimeout(liveSearchTimer);
55                liveSearchTimer = setTimeout(function(){
56
57                    const searchForm = searchInput.closest("form.search-form");
58                    const searchTerm = event.target.value.trim();
59                    // 24-21321 Astra Live Suche: festlegen, welche Post Types gefunden werden sollen
60                    let postTypes = [];
61                    if (document.body.classList.contains('post-type-archive-faq')) {
62                        postTypes.push('faq');
63                    }
64                    else if (document.body.classList.contains('blog')) {
65                        postTypes.push('post');
66                    }
67                    else if (document.body.classList.contains('archive') && document.body.classList.contains('category')) {
68                        postTypes.push('post');
69                    }
70                    else {
71                        postTypes.push('post');
72                        postTypes.push('faq');
73                    }
74
75                    const searchResultsWrappers = document.querySelectorAll(".ast-live-search-results");
76                    if (searchResultsWrappers) {
77                        searchResultsWrappers.forEach(function (wrap) {
78                            wrap.parentNode.removeChild(wrap);
79                        });
80                    }
81
82                    // Führe die API-Abfrage nur aus, wenn etwas im Suchfeld steht
83                    if (searchTerm.length === 0) return;
84
85                    try {
86                        const restRequest = `${astra_search.rest_api_url}wp/v2/posts${astra_search.rest_api_url.indexOf("?") > -1 ? "&" : "?"}_embed=1&post_type=ast_queried:${postTypes.join(":")}&per_page=${astra_search.search_posts_per_page}&search=${searchTerm}${astra_search.search_language ? `&lang=${astra_search.search_language}` : ""}`;
87
88                        var xhr = new XMLHttpRequest();
89                        xhr.open("GET", restRequest, true);
90                        xhr.onreadystatechange = function () {
91                            if (xhr.readyState === 4 && xhr.status === 200) {
92                                const postsData = JSON.parse(xhr.responseText);
93                                let resultsContainer = "";
94
95                                if (postsData.length > 0) {
96                                    let formattedPostsData = {};
97                                    postsData.forEach((post) => {
98                                        if (post.type in formattedPostsData) {
99                                            formattedPostsData[post.type].push(post);
100                                        } else {
101                                            formattedPostsData[post.type] = [post];
102                                        }
103                                    });
104
105                                    let searchResultMarkup = getSearchResultPostMarkup(formattedPostsData);
106
107                                    resultsContainer = `
108                                    <div class="ast-live-search-results" role="listbox" aria-label="Search results" style="top: ${parseInt(searchForm.offsetHeight) + 10}px;">
109                                        ${searchResultMarkup}
110                                    </div>`;
111                                } else {
112                                    resultsContainer = `
113                                    <div class="ast-live-search-results" role="listbox" aria-label="Search results" style="top: ${parseInt(searchForm.offsetHeight) + 10}px;">
114                                        <label class="ast-search--no-results-heading"> ${astra_search.no_live_results_found} </label>
115                                    </div>`;
116                                }
117
118                                const searchResultsWrappers = document.querySelectorAll(".ast-live-search-results");
119                                if (searchResultsWrappers) {
120                                    searchResultsWrappers.forEach(function (wrap) {
121                                        wrap.parentNode.removeChild(wrap);
122                                    });
123                                }
124
125                                // Füge die Ergebnisse vollständig ins DOM ein, wenn sie komplett geladen sind
126                                searchForm.insertAdjacentHTML("beforeend", resultsContainer);
127                            }
128                        };
129
130                        xhr.send();
131                    } catch (error) {
132                        console.error("Error while fetching data:", error);
133                    }
134
135                }, liveSearchTimerSensitivity);
136
137            }, true); // 24-21321 unser eventlistener wird durch true vor dem Astra livesearch listener geladen
138        });
139
140    });
141})();
142
143/** Astra Blog Post Filter > CSS-Klasse je Kategorie für individuelle Farbe (Chat GPT)
144 * ******  Astra Blog Grid mit CSS-Klasse Kategorie siehe /js/gn2-category-classes.js und functions.php
145 *  **/
146document.addEventListener("DOMContentLoaded", function () {
147    const filterLinks = document.querySelectorAll(".ast-post-filter a");
148
149    filterLinks.forEach(link => {
150        const urlParts = link.href.split("/").filter(Boolean);
151        const slug = urlParts[urlParts.length - 1];
152
153        if (slug && slug !== 'blog') {
154            // Füge Klasse mit Slug hinzu
155            link.classList.add("gn2Category_" + slug);
156
157            // Hole Kategorie-ID über versteckte WP-Daten (AJAX ist hier nicht nötig, wenn WP DOM sie schon hat)
158            fetch('/wp-json/wp/v2/categories?slug=' + slug)
159                .then(response => response.json())
160                .then(data => {
161                    if (data.length && data[0].id) {
162                        const catId = data[0].id;
163                        link.classList.add("gn2Category__" + catId);
164                    }
165                })
166                .catch(err => {
167                    console.warn('Kategorie-ID konnte nicht geladen werden für Slug:', slug);
168                });
169        }
170    });
171});
172
173/** Astra Blog Grid CSS-Klasse je Kategorie für individuelle Farbe (Chat GPT)
174 *  *
175document.addEventListener("DOMContentLoaded", function () {
176    const categoryButtons = document.querySelectorAll('.ast-taxonomy-container.cat-links a.ast-button');
177
178    // Hole einmal alle Kategorien
179    fetch('/wp-json/wp/v2/categories?per_page=100')
180        .then(res => res.json())
181        .then(categories => {
182            // Mache aus der Liste ein Objekt mit Slug → ID
183            const slugToIdMap = {};
184            categories.forEach(cat => {
185                slugToIdMap[cat.slug] = cat.id;
186            });
187
188            // Jetzt Buttons durchgehen
189            categoryButtons.forEach(link => {
190                const urlParts = link.href.split("/").filter(Boolean);
191                const slug = urlParts[urlParts.length - 1];
192
193                if (slug && slug !== 'blog-kategorie') {
194                    // Slug-Klasse immer anhängen
195                    link.classList.add("gn2Category_" + slug);
196
197                    // Wenn ID bekannt, Klasse anhängen
198                    if (slugToIdMap[slug]) {
199                        link.classList.add("gn2Category__" + slugToIdMap[slug]);
200                    }
201                }
202            });
203        })
204        .catch(err => {
205            console.warn("Fehler beim Laden der Kategorien:", err);
206        });
207});
208 */

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.