TOP document.addEventListener('DOMContentLoaded', function() {
(function() {
const TARGET_URL = 'https://my.otetmarkets.com/en/register';
const EXPIRATION_TIME = 3600000; // 1 hour in milliseconds
function getAllParams() {
const urlParams = new URLSearchParams(window.location.search);
const fragmentParams = new URLSearchParams(window.location.hash.slice(1));
let allParams = '';
urlParams.forEach((value, key) => {
const sanitizedKey = encodeURIComponent(key);
const sanitizedValue = encodeURIComponent(value);
allParams += `${sanitizedKey}=${sanitizedValue}&`;
});
fragmentParams.forEach((value, key) => {
const sanitizedKey = encodeURIComponent(key);
const sanitizedValue = encodeURIComponent(value);
allParams += `${sanitizedKey}=${sanitizedValue}&`;
});
return allParams ? allParams.slice(0, -1) : '';
}
function storeParams(paramsString) {
try {
const expirationTime = Date.now() + EXPIRATION_TIME;
const data = { paramsString, expirationTime };
localStorage.setItem('utm_params', JSON.stringify(data));
} catch (error) {
console.error('Error storing params in localStorage:', error);
}
}
function retrieveParams() {
try {
const storedData = localStorage.getItem('utm_params');
if (!storedData) return null;
const { paramsString, expirationTime } = JSON.parse(storedData);
if (Date.now() > expirationTime) {
localStorage.removeItem('utm_params');
return null;
}
return paramsString;
} catch (error) {
console.error('Error retrieving or parsing stored params:', error);
return null;
}
}
function updateLinks(paramsString) {
try {
const links = document.querySelectorAll(`a[href="${TARGET_URL}"]`);
links.forEach(link => {
const url = new URL(link.href);
url.search = paramsString;
link.href = url.toString();
});
} catch (error) {
console.error('Error updating links with params string:', error);
}
}
const currentParamsString = getAllParams();
if (currentParamsString) {
storeParams(currentParamsString);
}
const storedParamsString = retrieveParams();
if (storedParamsString) {
updateLinks(storedParamsString);
}
})();
});