0) {
paragraphs[i].classList.add('highlight');
break;
}
}
});
const adix = document.querySelectorAll('img.adix');
adix.forEach(image => {
const div = document.createElement('div');
// Extract and set inline styles from the image element
const style = image.getAttribute('style');
div.setAttribute('style', style);
div.style.width = image.attributes[1].value+"px";
div.style.height = image.attributes[2].value+"px";
div.style.margin = "6px";
div.style.maxWidth = "100%";
div.innerHTML =`
`;
// Replace the image element with the newly created div
image.parentNode.replaceChild(div, image);
(adsbygoogle = window.adsbygoogle || []).push({});
});
const applicationServerKey ='BCD5Y9pIEkbWl-xFaqje9GfWO-2FLyU46R_Wk6A6tZJ8QVugz4d8FlCLDbV5GLqIspTcUqD6er4Jpa0p0ejfLOo';
let isPushEnabled = false;
navigator.serviceWorker.register('/worker.js').then(
() => {
console.log('[SW] Service worker has been registered');
},
e => {
console.error('[SW] Service worker registration failed', e);
}
);
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
function checkNotificationPermission() {
return new Promise((resolve, reject) => {
if (Notification.permission === 'denied') {
return reject(new Error('Push messages are blocked.'));
}
if (Notification.permission === 'granted') {
return resolve();
}
if (Notification.permission === 'default') {
return Notification.requestPermission().then(result => {
if (result !== 'granted') {
reject(new Error('Bad permission result'));
} else {
resolve();
}
});
}
return reject(new Error('Unknown permission'));
});
}
function push_subscribe() {
return checkNotificationPermission()
.then(() => navigator.serviceWorker.ready)
.then(serviceWorkerRegistration =>
serviceWorkerRegistration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array(applicationServerKey),
})
)
.then(subscription => {
console.log('Subscription successful:', subscription);
return push_sendSubscriptionToServer(subscription, 'POST');
})
.then(subscription => {
console.log('Subscription sent to server:', subscription);
isPushEnabled = true; // Assuming successful subscription
// Update your UI here
})
.catch(e => {
if (Notification.permission === 'denied') {
console.warn('Notifications are denied by the user.');
// Change button state to 'incompatible'
} else {
console.error('Impossible to subscribe to push notifications', e);
// Change button state to 'disabled'
}
});
}
function push_updateSubscription() {
navigator.serviceWorker.ready
.then(serviceWorkerRegistration => serviceWorkerRegistration.pushManager.getSubscription())
.then(subscription => {
// Change button state to 'disabled'
if (!subscription) {
// User isn't subscribed to push, allow enabling push
return;
}
return push_sendSubscriptionToServer(subscription, 'PUT');
})
.then(subscription => {
if (subscription) {
console.log('Subscription updated on server:', subscription);
// Change button state to 'enabled'
}
})
.catch(e => {
console.error('Error when updating the subscription', e);
});
}
function push_unsubscribe() {
// Change button state to 'computing'
navigator.serviceWorker.ready
.then(serviceWorkerRegistration => serviceWorkerRegistration.pushManager.getSubscription())
.then(subscription => {
if (!subscription) {
// No subscription, allow the user to subscribe
// Change button state to 'disabled'
return;
}
return subscription.unsubscribe().then(() => push_sendSubscriptionToServer(subscription, 'DELETE'));
})
.then(() => {
console.log('User unsubscribed');
// Change button state to 'disabled'
})
.catch(e => {
console.error('Error when unsubscribing the user', e);
// Change button state to 'disabled'
});
}
function push_sendSubscriptionToServer(subscription, method) {
const key = subscription.getKey('p256dh');
const token = subscription.getKey('auth');
const contentEncoding = (PushManager.supportedContentEncodings || ['aesgcm'])[0];
return fetch('/_z0085/index.php', {
method,
body: JSON.stringify({
endpoint: subscription.endpoint,
publicKey: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : null,
authToken: token ? btoa(String.fromCharCode.apply(null, new Uint8Array(token))) : null,
contentEncoding,
}),
headers: {
'Content-Type': 'application/json'
}
}).then(response => {
if (!response.ok) {
throw new Error('Failed to send subscription to server');
}
localStorage.notifyMe=1;
document.querySelector(".animx").innerHTML = `
Gracias! ![](/assets/like.webp)
`;
setInterval(function(){
floatingDiv.style.top = '-272px';
},3000);
return subscription;
});
}
// Seleccionamos el div con la clase post-content
const postContent = document.querySelector('.post-content');
// Seleccionamos todos los párrafos dentro del div post-content
const paragraphs = postContent.querySelectorAll('p');
// Obtenemos el último párrafo
const lastParagraph = paragraphs[paragraphs.length - 1];
// Función para verificar si el último párrafo está visible
function isLastParagraphVisible() {
// Obtenemos la posición del último párrafo
const lastParagraphRect = lastParagraph.getBoundingClientRect();
// Verificamos si está completamente visible en el viewport
const isVisible = (
lastParagraphRect.top >= 0 &&
lastParagraphRect.left >= 0 &&
lastParagraphRect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
lastParagraphRect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
return isVisible;
}
// Función para mostrar la alerta cuando el último párrafo esté visible
function showReadCompleteAlert() {
if(localStorage.notifyMe=='1'){
return;
}
if (isLastParagraphVisible()) {
if(mobile()){
floatingDiv.style.top = '72px';
}else{
floatingDiv.style.top = '106px';
}
// Desactivamos el listener para evitar que se muestre la alerta más de una vez
window.removeEventListener('scroll', showReadCompleteAlert);
}
}
// Agregamos un listener para el evento scroll en la ventana
window.addEventListener('scroll', showReadCompleteAlert);
function mobile() {
// Expresión regular para detectar cadenas comunes en el user agent de móviles
const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
// Verificamos si alguna de las cadenas está presente en el user agent
return mobileRegex.test(navigator.userAgent);
}
const floatingDiv = document.createElement('div');
floatingDiv.innerHTML = `
¿Te gustó este articulo?
Toca la campanita para recibir más de lo que te gusta.
Es super fácil y puedes cancelar cuando quieras.
🔔
Tal vez más tarde
` ;
floatingDiv.classList="animx";
if(localStorage.late!=1){
document.body.appendChild(floatingDiv);
}
function late(){
localStorage.late=1;
document.querySelector(".animx").innerHTML = `
Gracias! ![](/assets/like.webp)
`;
setInterval(function(){
floatingDiv.style.top = '-272px';
},3000);
}