'use strict'; /* 관리자 페이지에서 고친 홈페이지 문구와 공지 띠 및 회원가입 허용 여부를 적용한다. * 모든 값은 글자로만 넣어 HTML로 해석되지 않는다. 마지막으로 받은 값을 이 브라우저에 기억해 * 다음 접속 때 서버 응답을 기다리지 않고 바로 보여 준다. 서버가 응답하지 않으면 HTML의 기본 문구를 그대로 쓴다. */ (function () { const KEY = 'duty-site-settings'; function setLines(node, text) { node.replaceChildren(); String(text).split('\n').forEach((line, index) => { // 휴대폰에서 줄바꿈을 숨기는 곳(.welcome-caption)에서도 낱말이 붙지 않게 띄어쓰기를 함께 넣는다. if (index) node.append(' ', document.createElement('br')); node.append(line); }); } function apply(settings) { if (!settings || typeof settings !== 'object') return; document.querySelectorAll('[data-site]').forEach(node => { const value = settings[node.dataset.site]; if (typeof value === 'string' && value) setLines(node, value); }); document.querySelectorAll('[data-site-href]').forEach(node => { const value = settings[node.dataset.siteHref]; if (typeof value === 'string' && /^https:\/\//.test(value)) node.href = value; }); if (typeof settings.brandName === 'string' && settings.brandName) document.title = settings.brandName + ' · 블리어'; const notice = document.getElementById('site-notice'); if (notice) { const text = typeof settings.noticeText === 'string' ? settings.noticeText.trim() : ''; notice.hidden = !(settings.noticeOn === true && text); notice.classList.toggle('warn', settings.noticeTone === 'warn'); document.getElementById('site-notice-text').textContent = text; } const create = document.getElementById('create'); if (create) create.hidden = settings.registrationOpen === false; } let cached = null; try { cached = JSON.parse(localStorage.getItem(KEY) || 'null'); } catch {} if (cached) apply(cached); fetch('api/site', { cache: 'no-store' }) .then(response => response.ok ? response.json() : null) .then(result => { if (!result || !result.settings) return; apply(result.settings); try { localStorage.setItem(KEY, JSON.stringify(result.settings)); } catch {} }) .catch(() => {}); })();