Files
ai-dev-portal/public/js/main.js
0310700 6ff8034856 fix(ui): 토스트 표시 후 주소창의 ?toast·?egg·?open 쿼리 제거
initSignals 가 신호를 소비한 뒤 history.replaceState 로 1회성 쿼리만 제거.
POST→Redirect→GET·비-JS 폴백은 유지하고, 새로고침/공유 시 토스트 재출력도 방지.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 10:10:14 +09:00

59 lines
2.5 KiB
JavaScript

// 엔트리 — 각 모듈 초기화 + 서버 시작 신호(토스트/이스터에그/모달 열기) 처리.
// _header/dashboard/project 에서 <script type="module" src="/public/js/main.js"> 로 로드.
import { EGGS_ON, toast, burstThumbs, burstRocket } from "./util.js";
import { initTheme, initUserMenu, initLogoEgg } from "./ui.js";
import { initReactions } from "./reactions.js";
import { initModals, openDetail } from "./modals.js";
import { initComments } from "./comments.js";
import { initFeed, initMyFilter } from "./feed.js";
// 서버가 <body data-*> 로 전달한 1회성 신호 처리
function initSignals() {
const b = document.body;
if (b.getAttribute("data-toast")) toast(b.getAttribute("data-toast"));
const egg = b.getAttribute("data-egg");
if (egg === "lgtm") { burstThumbs(); toast("LGTM 👍 — Looks Good To Me!"); }
else if (egg === "rocket") burstRocket();
const open = b.getAttribute("data-open-modal");
if (open) openDetail(open);
stripSignalParams();
}
// 1회성 신호 쿼리(toast/egg/open)는 표시 후 주소창에서 지운다.
// history.replaceState 라 새 히스토리 항목 없이 URL 만 정리 → 새로고침/공유 시 토스트가 다시 뜨지 않는다.
function stripSignalParams() {
try {
const url = new URL(window.location.href);
const before = url.search;
["toast", "egg", "open"].forEach((k) => url.searchParams.delete(k));
if (url.search !== before) history.replaceState(null, "", url.pathname + url.search + url.hash);
} catch (e) {}
}
function consoleArt() {
if (!EGGS_ON) return;
try {
const art = [" ___ ____ ____ _______ __", " / | / _/ / __ \\/ ____/ | / /", " / /| | / / / / / / __/ | | / / ", "/ ___ |_/ / / /_/ / /___ | |/ / ", "/_/ |_/___/ /_____/_____/ |___/ "].join("\n");
console.log("%c" + art, "color:#0969da;font-family:monospace;font-size:11px;line-height:1.1");
console.log("%c👀 코드 구경 왔어요? 환영합니다.", "color:#1f883d;font-size:13px;font-weight:bold");
console.log("%c사내 개발팀은 늘 동료를 찾고 있어요 — git blame 하지 말고 git praise 합시다. 🙇", "color:#656d76;font-size:12px");
console.log("%cps. 댓글에 LGTM 한 번 쳐보세요.", "color:#8b949e;font-size:11px");
} catch (e) {}
}
function boot() {
initTheme();
initUserMenu();
initLogoEgg();
initReactions();
initModals();
initComments();
initFeed();
initMyFilter();
initSignals();
consoleArt();
}
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", boot);
else boot();