diff --git a/js/main.js b/js/main.js index 2c31520..c09c2d6 100644 --- a/js/main.js +++ b/js/main.js @@ -7,9 +7,36 @@ document.addEventListener('DOMContentLoaded', () => { }); function getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); + console.log('DEBUG getCookie: all cookies =', document.cookie); + // Try multiple parsing strategies + const raw = document.cookie; + + // Strategy 1: standard split + const parts1 = raw.split(`; ${name}=`); + if (parts1.length === 2) { + const val = parts1.pop().split(';').shift(); + console.log('DEBUG getCookie: strategy1 result =', val, '(cleaned: ' + val.replace(/^"|"$/g, '') + ')'); + return val.replace(/^"|"$/g, ''); + } + + // Strategy 2: with quotes (n8n sets cookies quoted) + const parts2 = raw.split(`${name}="`); + if (parts2.length === 2) { + const val = parts2.pop().split('"').shift(); + console.log('DEBUG getCookie: strategy2 (quoted) result =', val); + return val; + } + + // Strategy 3: regex + const regex = new RegExp(`(?:^|;)\\s*${name}=([^;]*)`); + const match = raw.match(regex); + if (match && match[1]) { + const val = match[1].trim().replace(/^"|"$/g, ''); + console.log('DEBUG getCookie: strategy3 (regex) result =', val); + return val; + } + + console.log('DEBUG getCookie: NOT FOUND'); return ''; } @@ -27,6 +54,12 @@ const WIKI_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/wiki'; function checkSession() { const sessionid = getCookie('sessionid'); + console.log('DEBUG checkSession: sessionid found =', sessionid); + console.log('DEBUG checkSession: sessionid length =', sessionid ? sessionid.length : 'null'); + console.log('DEBUG checkSession: intro =', document.getElementById('intro-section') ? 'found' : 'NOT FOUND'); + console.log('DEBUG checkSession: login-panel =', document.getElementById('login-panel') ? 'found' : 'NOT FOUND'); + console.log('DEBUG checkSession: newsletter-panel =', document.getElementById('newsletter-panel') ? 'found' : 'NOT FOUND'); + console.log('DEBUG checkSession: notebook-panel =', document.getElementById('notebook-panel') ? 'found' : 'NOT FOUND'); const intro = document.getElementById('intro-section'); const news = document.getElementById('news-col'); const login = document.getElementById('login-panel');