document.addEventListener('DOMContentLoaded', () => {
// Select all country links
const countryLinks = document.querySelectorAll('.country-setter');
countryLinks.forEach(link => {
link.addEventListener('click', (event) => {
const isoCode = link.getAttribute('data-iso');
const currencyCode = link.getAttribute('data-cu');
setCookie('LAND', isoCode, 365); // Set the LAND cookie
setCookie('VALUTA', currencyCode, 365); // Set the VALUTA cookie
const data = new URLSearchParams();
data.append('funk', 'set_country_session_data');
data.append('ic', isoCode);
data.append('cc', currencyCode);
const response = fetch('/cgi-bin/ibutik/API.fcgi', {
method: 'POST',
body: data
});
});
});
// Select the parent
element
const ul = document.querySelector('.country-select-select');
if (ul) {
// Get all - elements inside the
as an array
const listItems = Array.from(ul.querySelectorAll('li'));
// Separate the - elements into two groups: with and without `data-domain="www"`
const withWWW = listItems.filter(li => li.getAttribute('data-domain') === 'www');
const withoutWWW = listItems.filter(li => li.getAttribute('data-domain') !== 'www');
// Sort the `withoutWWW` group based on `data-sort` attribute
withoutWWW.sort((a, b) => {
const sortA = (a.getAttribute('data-sort') || '').toLowerCase().trim();
const sortB = (b.getAttribute('data-sort') || '').toLowerCase().trim();
return sortA.localeCompare(sortB);
});
// Sort the `withWWW` group based on `data-sort` attribute
withWWW.sort((a, b) => {
const sortA = (a.getAttribute('data-sort') || '').toLowerCase().trim();
const sortB = (b.getAttribute('data-sort') || '').toLowerCase().trim();
return sortA.localeCompare(sortB);
});
// Clear the
content
ul.innerHTML = '';
// Append the `withoutWWW` group first, followed by the `withWWW` group
withoutWWW.forEach(li => ul.appendChild(li));
withWWW.forEach(li => ul.appendChild(li));
} else {
console.error('The element with the class "country-select-select" was not found.');
}
});
// Function to set a cookie
function setCookie(name, value, days) {
const d = new Date();
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "expires=" + d.toUTCString();
document.cookie = `${name}=${value}; ${expires}; path=/`;
}