| 1 |
document.addEventListener('DOMContentLoaded', function () { |
| 2 |
var counters = document.querySelectorAll('.tptn_counter[data-tptn-url]'); |
| 3 |
|
| 4 |
counters.forEach(function (el) { |
| 5 |
fetch(el.getAttribute('data-tptn-url')) |
| 6 |
.then(function (response) { |
| 7 |
if (!response.ok) { |
| 8 |
throw new Error('Counter request failed'); |
| 9 |
} |
| 10 |
return response.json(); |
| 11 |
}) |
| 12 |
.then(function (data) { |
| 13 |
if (data && data.count) { |
| 14 |
el.innerHTML = data.count; |
| 15 |
} |
| 16 |
}) |
| 17 |
.catch(function (error) { |
| 18 |
console.error('Error:', error); |
| 19 |
}); |
| 20 |
}); |
| 21 |
}); |
| 22 |
|