0 €
6 prodotti selezionati
.
========================================================= */
(function () {
if (window.__VZ_SNIPERFAST_NATIVE_CTA__) {
return;
}
window.__VZ_SNIPERFAST_NATIVE_CTA__ = true;
const MOBILE_MAX = 779;
let currentRoot = null;
let observer = null;
let lastCount = null;
/* =====================================================
MOBILE
===================================================== */
function isMobile() {
return window.matchMedia(
'(max-width: ' + MOBILE_MAX + 'px)'
).matches;
}
/* =====================================================
RECUPERA CONTEGGIO
===================================================== */
function getCount() {
const mobileCounter =
document.querySelector(
'#sniperfast_results_found_mob'
);
const standardCounter =
document.querySelector(
'#sniperfast_results_found'
);
const counter =
mobileCounter || standardCounter;
if (!counter) {
return null;
}
const text =
(counter.textContent || '').trim();
const match =
text.match(/\d+/);
return match
? match[0]
: null;
}
/* =====================================================
TROVA TESTO NATIVO "MOSTRA RISULTATI"
===================================================== */
function getNativeResultText() {
return document.querySelector(
'#snpf_selected_filters_result_txt'
);
}
/* =====================================================
AGGIORNA SOLAMENTE IL TESTO
===================================================== */
function updateNativeText() {
if (!isMobile()) {
return;
}
const resultText =
getNativeResultText();
if (!resultText) {
return;
}
const count =
getCount();
if (
count &&
count === lastCount &&
resultText.textContent.trim() ===
'Visualizza ' +
count +
' risultati'
) {
return;
}
if (count) {
resultText.textContent =
'Visualizza ' +
count +
' risultati';
lastCount = count;
} else {
resultText.textContent =
'Visualizza risultati';
lastCount = null;
}
}
/* =====================================================
COLLEGA OBSERVER A SNIPERFAST
===================================================== */
function connect() {
const root =
document.querySelector(
'#sniperfast_search'
);
if (!root) {
return;
}
if (
currentRoot === root &&
observer
) {
updateNativeText();
return;
}
if (observer) {
observer.disconnect();
}
currentRoot = root;
observer =
new MutationObserver(
function () {
updateNativeText();
}
);
observer.observe(
root,
{
childList: true,
subtree: true,
characterData: true
}
);
updateNativeText();
}
/* =====================================================
SNIPERFAST POTREBBE APRIRSI DOPO
===================================================== */
const pageObserver =
new MutationObserver(
function () {
const root =
document.querySelector(
'#sniperfast_search'
);
if (
root &&
root !== currentRoot
) {
connect();
}
}
);
pageObserver.observe(
document.body,
{
childList: true,
subtree: true
}
);
/* =====================================================
AGGIORNA NUMERO DOPO INTERAZIONI
CON I FILTRI
===================================================== */
document.addEventListener(
'click',
function (event) {
if (!isMobile()) {
return;
}
const target =
event.target;
if (!target) {
return;
}
if (
target.closest(
'#sniperfast_search'
)
) {
window.setTimeout(
updateNativeText,
80
);
window.setTimeout(
updateNativeText,
250
);
}
},
false
);
/* =====================================================
AVVIO
===================================================== */
connect();
})();