// Ver 1.04 / 2026-11-13 11:21 / 김경현 (function(){ if(window.top!==window.self)return; const style=document.createElement('style'); style.textContent='.wexcel-login-dialog{box-sizing:border-box;width:360px;max-width:calc(100vw - 28px);max-height:calc(100dvh - 28px);padding:0;border:1px solid #dae3df;border-radius:18px;background:#fff;overflow:auto;box-shadow:0 18px 70px #163c342b}.wexcel-login-dialog::backdrop{background:rgba(225,237,231,.62)}.wexcel-login-dialog iframe{display:block;width:100%;height:380px;border:0;background:#fff}.wexcel-login-status{padding:28px;text-align:center;color:#415d51;font:14px sans-serif}.wexcel-login-status button{display:block;margin:16px auto 0;padding:8px 22px;border:1px solid #cdded5;border-radius:7px;background:#edf6f1;color:#176344;cursor:pointer}'; document.head.append(style); const dialog=document.createElement('dialog');dialog.className='wexcel-login-dialog';dialog.setAttribute('aria-label','로그인');document.body.append(dialog); let frame=null,checking=false,openerRefreshed=false,navigating=false; function refreshLoginOpener(){ if(openerRefreshed)return;openerRefreshed=true; try{const opener=window.opener;if(opener&&!opener.closed&&opener.location.origin===location.origin)opener.location.reload();}catch(error){} } function closeLogin(){dialog.close();dialog.replaceChildren();frame=null;dialog.style.width='360px';document.querySelector('[data-wexcel-login]')?.focus();} function showError(){dialog.replaceChildren();const status=document.createElement('div'),button=document.createElement('button');status.className='wexcel-login-status';status.textContent='로그인 화면을 불러오지 못했습니다.';button.type='button';button.textContent='둘러보기';button.onclick=closeLogin;status.append(button);dialog.append(status);frame=null;} function openLogin(event){ event?.preventDefault();if(dialog.open)return; dialog.style.width='360px';frame=document.createElement('iframe');frame.title='문자나라 공통 로그인';frame.src='/WEXCEL/login_layer.php';dialog.replaceChildren(frame); frame.addEventListener('load',async()=>{if(!frame)return;const loadedFrame=frame;try{const url=new URL(frame.contentWindow.location.href);if(url.origin!==location.origin){showError();return;}if(url.pathname==='/WEXCEL/login_layer.php'){if(!frame.contentDocument.querySelector('form[name="loginFm"]'))showError();return;}if(url.pathname==='/user/join_s1.htm'){window.location.replace(url.href);return;}await finishLogin(url.href,true,loadedFrame);}catch(error){if(frame===loadedFrame)showError();}}); frame.addEventListener('error',showError);dialog.showModal(); } async function finishLogin(href,authenticated,loginFrame,code){ if(navigating||frame!==loginFrame)return; let url,allowed=false; try{url=new URL(href,location.origin);allowed=!url.username&&!url.password&&(url.origin===location.origin||(!authenticated&&code==='ACTION_REQUIRED'&&url.href==='https://www.munjanara.co.kr/'));}catch(error){} if(!allowed){loginFrame.contentWindow.postMessage({channel:'wexcel-login',type:'error'},location.origin);return;} navigating=true; if(authenticated){ let loggedIn=false; try{const response=await fetch('/WEXCEL/tour.html?auth=1',{credentials:'same-origin',cache:'no-store'});loggedIn=response.ok&&(await response.json()).loggedIn===true;}catch(error){} if(frame!==loginFrame){navigating=false;return;} if(!loggedIn){navigating=false;loginFrame.contentWindow.postMessage({channel:'wexcel-login',type:'error'},location.origin);return;} refreshLoginOpener(); } location.replace(url.href); } async function checkLogin(){if(checking||navigating||document.hidden)return;checking=true;const loginFrame=frame;try{const response=await fetch('/WEXCEL/tour.html?auth=1',{credentials:'same-origin',cache:'no-store'});if(response.ok&&(await response.json()).loggedIn){if(navigating||frame!==loginFrame)return;navigating=true;if(frame)refreshLoginOpener();location.replace('/WEXCEL/');}}catch(error){}finally{checking=false;}} document.querySelectorAll('[data-wexcel-login]').forEach(button=>button.addEventListener('click',openLogin)); dialog.addEventListener('cancel',event=>{event.preventDefault();closeLogin();}); window.addEventListener('message',event=>{ if(!frame||event.source!==frame.contentWindow||event.origin!==location.origin||event.data?.channel!=='wexcel-login')return; const data=event.data; if(data.type==='navigate'&&typeof data.url==='string'){finishLogin(data.url,data.authenticated===true,frame,data.code);return;} if(data.type==='close'||data.type==='tour'){closeLogin();checkLogin();} else if(data.type==='resize'&&Number.isFinite(data.height)){dialog.style.width=data.expanded?'680px':'360px';frame.style.height=Math.max(300,Math.min(data.height,window.innerHeight-32))+'px';} }); window.setInterval(checkLogin,5000); window.addEventListener('pageshow',checkLogin);window.addEventListener('focus',checkLogin);document.addEventListener('visibilitychange',checkLogin); if(document.body.hasAttribute('data-login-open'))openLogin(); })();