`;
fragment.appendChild(notificationCard);
});
// Append all notification cards at once
notiOBJ.innerHTML = »;
notiOBJ.appendChild(fragment);
} catch (error) {
console.error(«Error fetching notifications:», error);
notiOBJ.innerHTML = ‘
Hubo un error al cargar las notificaciones. Inténtalo más tarde.
‘;
}
}
const userSessionFullName = localStorage.getItem(‘userSessionFullName’);
if (userSessionFullName) {
const nameUserSessionElements = document.querySelectorAll(‘.nameUserSession’);
// Verificar si hay elementos con la clase nameUserSession
if (0 < nameUserSessionElements.length) {
nameUserSessionElements.forEach((element) => {
element.textContent=»Hola, » + userSessionFullName.split(‘ ‘)[0]; // eslint-disable-line no-param-reassign
});
}
}
tp.push([«init», function() {
window.domBatch.add(() => {
const elements = document.querySelectorAll(‘.showPianoLoginPl’);
elements.forEach((element) => {
element.addEventListener(‘click’, () => {
// eslint-disable-next-line no-shadow
const tp = window.tp || [];
const isAuthenticated = tp.user.isUserValid();
const domainName = window.location.hostname;
const loginPath=»/login»;
const profilePath=»/mi-perfil»;
const url = `https://${domainName}${isAuthenticated ? profilePath : loginPath}`;
window.open(url, ‘_self’);
});
});
});
if (tp.pianoId.isUserValid()) {
const tokenUser = JSON.stringify({
tokenUser: tp.pianoId.getToken()
});
const myHeaders = new Headers();
myHeaders.append(‘Content-Type’, ‘application/json’);
const request = {
method: ‘POST’,
headers: myHeaders,
body: tokenUser,
mode: ‘cors’,
redirect: ‘follow’,
};
console.log(«https://foservices.prensalibre.com/pianoid/data/access/user»);
fetch(‘https://foservices.prensalibre.com/pianoid/data/access/user’, request)
.then(response => response.json())
.then((data) => {
console.log(«ACCESS/USER»);
let isSuscriptionActive=»no-suscriptor»;
if (data.status === ‘active’) {
isSuscriptionActive=»suscriptor»;
window.domBatch.add(() => {
jQuery(‘#ux-btn-impreso’).show();
});
}
if (data.status !== ‘active’) {
window.domBatch.add(() => {
jQuery(‘#btn-suscribase-header’).attr(‘style’, ‘display:inline-block !important’);
});
}
// SETEA EL BADGE DE NOTIFICACIONES
jQuery.ajax({
url: `https://foservices.prensalibre.com/usuario/notificaciones_piano/${tp.pianoId.getUser().uid}/${isSuscriptionActive}`,
type: ‘GET’,
success: (dataresp) => {
window.domBatch.add(() => {
const notifications = jQuery(‘.ux-notifications’);
const notificationsHeader = jQuery(‘.ux-notifications-header’);
const notiNumber = jQuery(‘.ux-noti-number’);
const unreadCount = dataresp?.unread || 0;
if (unreadCount > 0) {
// Show notification badges
notifications.css(‘display’, ‘inline-block’).text(unreadCount);
notificationsHeader.css(‘display’, ‘inline-block’).text(unreadCount);
notiNumber.css(‘display’, ‘block’)
.css(‘text-align’, ‘center’)
.html(`Hay ${unreadCount} notificación${unreadCount > 1 ? ‘es’ : »} nueva${unreadCount > 1 ? ‘s’ : »}
Leer`);
} else {
// Hide all notification elements
notifications.hide();
notificationsHeader.hide();
notiNumber.hide();
}
});
},
error: (xhr, status, error) => {
console.error(`Error fetching notifications: ${status} – ${error}`);
}
});
const cUrl = window.location.pathname;
if (‘/mis-notificaciones/’ === cUrl) {
//FETCH NOTIFICATIONS HERE
// Call the function to fetch notifications
fetchNotifications(isSuscriptionActive);
}
})
.catch((error) => {
console.error(‘Error:’, error)
});
} else {
window.domBatch.add(() => {
jQuery(‘#btn-suscribase-header’).removeClass(‘d-none’);
});
}
}]);
‘).insertAfter(‘blockquote p’);
});
jQuery(‘#save-fav’).click(function() {
if (tp.pianoId.getUser().uid != ‘0’ && this.className == ‘tosavefav’) {
jQuery.ajax({
type: ‘POST’,
crossDomain: true,
dataType: ‘json’,
url: ‘https://foservices.prensalibre.com/usuario/favoritos/save_piano’,
data: {
uid: tp.pianoId.getUser().uid,
aid: ‘22485811’,
},
success(data) {
jQuery(‘#save-fav .actions’).text(data.message);
console.log(‘Entra aquí’)
sendPostMessageGtag({
‘event_label’: ‘Artículo guardado’,
‘value’: ‘1’,
}, ‘articulos_guardados’);
sendPostMessageGtag({
‘event_label’: ‘De jalarse el pelo’,
‘value’: ‘1’,
}, ‘articulos_guardados_detalle’);
if (data.message != ‘guardar’) {
jQuery(‘#save-fav’).removeClass(‘tosavefav’).addClass(‘tomyfavs’);
}
},
error() {
},
});
}
if (this.className == ‘tomyfavs’) {
window.open(‘https://www.prensalibre.com/mis-articulos/’, ‘_blank’);
}
});