-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
508 lines (471 loc) · 29.9 KB
/
index.html
File metadata and controls
508 lines (471 loc) · 29.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>콘티 메이커 🎵</title>
<link rel="icon" href="icon.png">
<link rel="apple-touch-icon" href="icon.png">
<meta name="apple-mobile-web-app-title" content="콘티 메이커">
<meta name="theme-color" content="#181d3a">
<link rel="manifest" href="manifest.json">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<!-- Open Graph (카카오톡, 슬랙, 디스코드 등 링크 미리보기) -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://score-fetcher.vercel.app/">
<meta property="og:title" content="콘티 메이커 🎵">
<meta property="og:description" content="예배 콘티 관리 · 악보 뷰어 · 실시간 푸시 알림">
<meta property="og:image" content="https://score-fetcher.vercel.app/og-image-premium.png?v=2">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:locale" content="ko_KR">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="콘티 메이커 🎵">
<meta name="twitter:description" content="예배 콘티 관리 · 악보 뷰어 · 실시간 푸시 알림">
<meta name="twitter:image" content="https://score-fetcher.vercel.app/og-image-premium.png?v=2">
<!-- Firebase SDK (Cloud Messaging 푸시 알림 및 Database 용) -->
<script src="firebase-config.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.0/firebase-database-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.0/firebase-messaging-compat.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<span class="header-title">콘티 메이커 🎵</span>
<button class="header-notif-btn" id="btn-notif" onclick="openNotifModal()" title="알림센터">
🔔<span class="notif-badge" id="notif-badge" style="display:none"></span>
</button>
<button class="header-settings-btn" id="btn-settings" onclick="openSettings()" title="설정">⚙️</button>
</header>
<!-- 카카오톡 인앱 브라우저 안내 배너 -->
<div id="kakao-banner">
<button class="kb-close" onclick="document.getElementById('kakao-banner').style.display='none'">×</button>
<div class="kb-title">📲 앱으로 설치하려면 외부 브라우저를 사용해 주세요</div>
<div class="kb-desc" id="kakao-banner-desc"></div>
<button class="kb-btn" id="kakao-banner-btn"></button>
</div>
<main>
<div class="app-layout" id="app-layout">
<!-- 왼쪽: 입력 영역 (세로 모드에서는 아래) -->
<div class="panel-left">
<div class="input-card" id="input-section">
<label class="field-label">콘티 제목</label>
<input type="text" id="setlist-title" class="title-input" placeholder="예: 2026-03-15 수요예배">
<label class="field-label">찬양 목록 입력</label>
<textarea id="song-input" placeholder="276 햇살보다 밝게 빛나는 주의 123 당신은 지금 어디로 168 하나님은 너를 만드신 분" oninput="handleInputPrefetch(this.value)"></textarea>
<div class="input-action-row">
<button class="btn-input-action btn-input-reset" onclick="resetAll()">🔄 초기화</button>
<button class="btn-input-action btn-input-divider" onclick="addDivider()">— 구분선 추가</button>
</div>
</div>
<!-- 가로 모드: 악보 만들기 후 콘티 공유 이미지 -->
<div class="ls-conti-area" id="ls-conti-area">
<img id="ls-conti-img" src="" alt="콘티 이미지">
</div>
</div>
<!-- 오른쪽 상단: 상단 버튼 (세로: order 1 | 가로: 우측 상단) -->
<div class="panel-right">
<div class="controls-card" id="controls-section">
<div class="top-btn-group">
<div class="top-btn-row">
<button class="top-btn btn-show-list" onclick="openSongModal()" aria-label="찬양 목록 열기">📖 찬양 목록</button>
<button class="top-btn btn-history" onclick="openHistoryModal()" aria-label="콘티함 열기">🕒 콘티함</button>
</div>
</div>
</div>
<!-- 가로 ls-active: 악보 뷰어 (controls-card 대체) -->
<div class="ls-sheet-area" id="ls-sheet-area">
<div class="ls-sheet-header">
<span id="ls-sheet-title"></span>
<button class="ls-back-btn" onclick="closeLandscapeView()" aria-label="가로 뷰어 닫기">✕ 돌아가기</button>
</div>
<div class="ls-sheet-body">
<img id="ls-sheet-img-next" src="" alt="" style="position:absolute;top:0;left:0;width:100%;height:100%;object-fit:contain;opacity:0;pointer-events:none;">
<img id="ls-sheet-img" src="" alt="악보 이미지">
</div>
<div class="ls-sheet-footer">
<button class="fullscreen-nav ls-nav-prev" onclick="navigateLandscapeSheet(-1)" aria-label="이전 악보">‹</button>
<button class="fullscreen-nav ls-nav-next" onclick="navigateLandscapeSheet(1)" aria-label="다음 악보">›</button>
</div>
</div>
</div>
<!-- 하단 버튼: 세로 order 3 | 가로: 우측 하단 -->
<div class="panel-bottom" id="panel-bottom">
<div class="controls-card">
<div class="btn-group">
<button class="btn-search" onclick="startSearch()">악보 불러오기 🎵</button>
<div id="loaded-conti-indicator" style="display:none; align-items:center; gap:8px; padding:8px 12px; background:rgba(99,102,241,0.15); border:1px solid rgba(99,102,241,0.4); border-radius:8px; font-size:13px; color:#a5b4fc;">
<span>✏️ 수정 중:</span>
<span class="loaded-conti-name" style="font-weight:700; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;"></span>
<button onclick="clearLoadedConti()" style="background:none; border:none; color:#94a3b8; cursor:pointer; font-size:16px; padding:0; line-height:1;">✕</button>
</div>
<div class="btn-row">
<button class="btn-save" onclick="saveConti()">콘티함에 저장 💾</button>
<button class="btn-share" onclick="shareConti()">콘티 공유하기 📤</button>
</div>
</div>
</div>
</div>
</div>
<!-- 악보 카드 그리드 (세로 모드 전용 — 가로 모드에서는 CSS로 숨김) -->
<div id="result-container" class="result-area"></div>
</main>
<footer>
<div class="footer-btn-group">
<button class="footer-btn btn-install" id="btn-install" onclick="installApp()">앱 설치 📲</button>
</div>
</footer>
<!-- 악보 전체화면 뷰어 (좌우 이동 포함) -->
<div class="fullscreen-overlay" id="fullscreenViewer">
<div class="fullscreen-header">
<span class="fs-title" id="fullscreen-title"></span>
<button class="btn-close" onclick="closeFullscreen()" aria-label="전체화면 닫기">×</button>
</div>
<div class="fullscreen-body" id="fullscreen-body">
<img id="fullscreen-img-next" src="" alt="" style="position:absolute;top:0;left:0;width:100%;height:100%;object-fit:contain;opacity:0;pointer-events:none;">
<img id="fullscreen-img" src="" alt="">
</div>
<div class="fullscreen-footer">
<button class="fullscreen-nav nav-prev" onclick="navigateSheet(-1)" aria-label="이전 악보">‹</button>
<button class="fullscreen-nav nav-next" onclick="navigateSheet(1)" aria-label="다음 악보">›</button>
</div>
</div>
<div class="modal-overlay" id="songModal" onclick="if(event.target===this)closeSongModal()">
<div class="modal-content">
<div class="modal-header">
<h3>📖 찬양 목록</h3>
<button class="btn-close" onclick="closeSongModal()" aria-label="찬양 목록 닫기">×</button>
</div>
<!-- 탭 -->
<div class="modal-tabs">
<button id="tab-ccm" class="modal-tab tab-active" onclick="switchTab('ccm')">🎵 찬양</button>
<button id="tab-hymn" class="modal-tab" onclick="switchTab('hymn')">📖 새찬송가</button>
<button id="tab-tongil" class="modal-tab" onclick="switchTab('tongil')">📖 통일찬송가</button>
</div>
<div class="modal-search">
<input type="text" id="searchInput" placeholder="검색어 또는 번호를 입력하세요..." onkeyup="filterHymns()">
<div id="ccm-toolbar" style="display:flex;gap:6px;align-items:center;">
<button id="btn-recent-filter" onclick="toggleRecentFilter()" class="btn-sort-freq btn-recent-filter" title="최근 사용곡만 보기">🕐 최근</button>
<button id="btn-fav-filter" onclick="toggleFavFilter()" class="btn-sort-freq btn-fav-filter" title="즐겨찾기만 보기">⭐</button>
<button id="btn-sort-freq" onclick="cycleSortMode()" class="btn-sort-freq">🔢 번호순</button>
</div>
<div id="hymn-toolbar" style="display:none;gap:6px;align-items:center;">
<button id="btn-hymn-sort" onclick="cycleHymnSortMode()" class="btn-sort-freq">🔢 번호순</button>
</div>
</div>
<div style="position:relative; flex:1; display:flex; flex-direction:column; overflow:hidden; min-height:0;">
<ul class="modal-body" id="songListContainer" style="flex:1;"></ul>
<div id="quickIndexNav" class="quick-index-nav"></div>
</div>
</div>
</div>
<div class="modal-overlay" id="lyricsModal" onclick="if(event.target===this)closeLyricsModal()">
<div class="modal-content">
<div class="modal-header">
<h3 id="lyrics-title">가사</h3>
<button class="btn-close" onclick="closeLyricsModal()" aria-label="가사 모달 닫기">×</button>
</div>
<div id="lyrics-tags" style="display:none; flex-wrap:wrap; gap:6px; padding:10px 16px; border-bottom:1px solid rgba(199,197,206,0.2);"></div>
<div class="lyrics-body" id="lyrics-content"></div>
<div class="modal-footer" style="padding: 12px 16px; border-top: 1px solid rgba(199, 197, 206, 0.1); display: flex; justify-content: flex-end;">
<button class="btn-report" id="btn-report-lyrics" onclick="handleLyricReport()">🛠️ 가사 오류 신고</button>
</div>
</div>
</div>
<div class="modal-overlay" id="historyModal" onclick="if(event.target===this)closeHistoryModal()">
<div class="modal-content">
<div class="modal-header history">
<h3>🕒 콘티함</h3>
<button class="btn-close" onclick="closeHistoryModal()" aria-label="콘티함 닫기">×</button>
</div>
<div class="modal-search">
<input type="text" id="historySearchInput" placeholder="제목 또는 곡 번호로 검색..." onkeyup="filterHistory()">
</div>
<ul class="modal-body" id="historyListContainer"></ul>
</div>
</div>
<div class="modal-overlay" id="sharePreviewModal">
<div class="share-preview-content">
<div class="share-preview-body" onclick="_showShareUI()">
<img id="sharePreviewImg" src="" alt="콘티 미리보기">
</div>
<div class="share-preview-footer">
<div class="share-deeplink-chip" id="shareDeeplinkChip" style="display:none" onclick="copyDeeplink()">
<span class="share-deeplink-icon">🔗</span>
<span class="share-deeplink-text" id="shareDeeplinkText"></span>
<span class="share-deeplink-copy">탭하여 복사</span>
</div>
<p class="share-save-notice">💾 공유하면 콘티함에도 자동 저장됩니다</p>
<div class="share-footer-row">
<button class="btn-share-close" onclick="closeSharePreview()">닫기 ✕</button>
<button class="btn-share-confirm" onclick="doShareConti()">공유하기 🚀</button>
</div>
</div>
</div>
</div>
<!-- 알림센터 모달 -->
<div class="modal-overlay" id="notifModal" onclick="if(event.target===this)closeNotifModal()">
<div class="modal-content">
<div class="modal-header">
<h3>🔔 알림센터</h3>
<div style="display:flex;gap:8px;align-items:center">
<button class="btn-mark-all-read" id="btn-mark-all-read" onclick="markAllRead()" style="display:none">전체 읽기</button>
<button class="btn-close" onclick="closeNotifModal()">×</button>
</div>
</div>
<ul class="modal-body" id="notifListContainer"></ul>
</div>
</div>
<!-- 설정 모달 -->
<div class="modal-overlay" id="settingsModal" onclick="if(event.target===this)closeSettings()">
<div class="settings-content">
<div class="settings-header">
<h3>⚙️ 설정</h3>
<button class="btn-close" onclick="closeSettings()">×</button>
</div>
<div class="settings-body">
<div class="settings-row">
<div>
<div class="settings-row-label">🔔 푸시 알림</div>
<div class="settings-row-desc">새 콘티 등록 시 알림을 받습니다</div>
</div>
<label class="toggle-switch">
<input type="checkbox" id="toggle-push" onchange="onTogglePush(this.checked)">
<span class="toggle-track"></span>
</label>
</div>
<div class="settings-row" id="push-status-row" style="display:none">
<div style="font-size:12px; color:var(--on-surface-variant)" id="push-status-text"></div>
</div>
<div class="settings-footer">
<div class="settings-footer-row">
<a href="https://github.com/jeiel85/score-fetcher" target="_blank" rel="noopener">
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>
</svg>
GitHub
</a>
<a href="admin.html">👑 관리자</a>
</div>
<div class="settings-footer-row">
<div class="settings-version-info">
<span>Build 2026.04.22</span>
</div>
<span class="app-version-badge">v1.13.5</span>
</div>
</div>
</div>
</div>
</div>
<!-- JS 모듈: 로드 순서 중요 (firebase → utils → 기능별) -->
<script src="js/firebase.js"></script>
<script src="js/utils.js"></script>
<script src="js/history.js"></script>
<script src="js/song-list.js"></script>
<script src="js/sheet-viewer.js"></script>
<script src="js/push.js"></script>
<script src="js/share.js"></script>
<script src="js/notifications.js"></script>
<script>
// 🚀 강제 업데이트 로직 (버전 체크) 🚀
(function forceUpdateCheck() {
const VERSION = '1.13.5';
const savedVersion = localStorage.getItem('app_version');
if (savedVersion !== VERSION) {
console.log(`Update Detect: ${savedVersion} -> ${VERSION}`);
// #85: 새로고침 전 입력 중 데이터 임시 보존
const _t = document.getElementById('setlist-title')?.value;
const _s = document.getElementById('song-input')?.value;
if (_t) sessionStorage.setItem('_pendingTitle', _t);
if (_s) sessionStorage.setItem('_pendingSongs', _s);
// 기존 버전이 있을 때만 업데이트 알림 예약 (첫 설치 제외)
if (savedVersion) {
localStorage.setItem('_pendingUpdateNotif', JSON.stringify({ from: savedVersion, to: VERSION }));
}
localStorage.setItem('app_version', VERSION);
location.reload(true);
}
})();
// ─── PWA 설치 ──────────────────────────────────────────────────────────
let deferredInstallPrompt = null;
(function initInstallBtn() {
const btn = document.getElementById('btn-install');
if (window.matchMedia('(display-mode: standalone)').matches || navigator.standalone) {
btn.style.display = 'none';
} else { btn.style.display = 'inline-block'; }
})();
window.addEventListener('beforeinstallprompt', e => {
e.preventDefault(); deferredInstallPrompt = e;
});
window.addEventListener('appinstalled', () => {
deferredInstallPrompt = null;
document.getElementById('btn-install').style.display = 'none';
});
async function installApp() {
if (!deferredInstallPrompt) {
const ua = navigator.userAgent;
const isIOS = /iphone|ipad|ipod/i.test(ua);
const isSamsungBr = /SamsungBrowser/i.test(ua);
const isFirefox = /Firefox/i.test(ua) && !/Seamonkey/i.test(ua);
const isKakao = /KAKAOTALK/i.test(ua);
if (isKakao) showInstallToast('카카오톡 인앱 브라우저에서는 앱 설치가 불가합니다.<br>우측 상단 메뉴 → <b>기본 브라우저로 열기</b>를 눌러주세요.');
else if (isSamsungBr) showInstallToast('삼성 인터넷은 앱 설치를 지원하지 않습니다.<br><b>Chrome</b>으로 이 페이지를 열어 설치해 주세요.');
else if (isIOS) showInstallToast('iOS는 자동 설치를 지원하지 않습니다.<br>Safari 하단 <b>공유 버튼 → 홈 화면에 추가</b>를 눌러주세요.');
else if (isFirefox) showInstallToast('Firefox는 PWA 설치를 지원하지 않습니다.<br><b>Chrome</b> 또는 <b>Edge</b>로 접속해 설치해 주세요.');
else showInstallToast('브라우저 주소창 우측의 설치 아이콘을 눌러 설치하거나<br>메뉴 → <b>앱 설치 / 홈 화면에 추가</b>를 이용해 주세요.');
return;
}
document.querySelectorAll('.modal-overlay').forEach(el => el.style.display = 'none');
try {
await deferredInstallPrompt.prompt();
const { outcome } = await deferredInstallPrompt.userChoice;
if (outcome === 'accepted') deferredInstallPrompt = null;
} catch (e) { showInstallToast('설치 창을 열 수 없습니다.<br>브라우저 메뉴 → <b>앱 설치 / 홈 화면에 추가</b>를 이용해 주세요.'); }
}
// ─── 최신 콘티 자동 로드 (알림 클릭 시) ───────────────────────────────
async function autoLoadLatestConti() {
try {
const idToken = await getIdToken();
const res = await fetch(`${FIREBASE_CONFIG.databaseURL}/history.json?auth=${idToken}`);
if (!res.ok) return;
const data = await res.json();
if (!data) return;
const entries = Object.values(data).sort((a, b) => b.timestamp - a.timestamp);
const latest = entries[0];
if (!latest) return;
document.getElementById('setlist-title').value = latest.title || '';
document.getElementById('song-input').value = latest.text || '';
startSearch();
} catch (e) { console.warn('autoLoad 실패:', e); }
}
// ─── 오프라인 악보 사전 캐싱 (백그라운드 유휴 시간 활용) ───────────────
async function precacheAllScores() {
if (!('caches' in window) || !navigator.onLine) return;
try {
const cache = await caches.open('scores-v1');
const isFirst = !localStorage.getItem('scoresCachedAt');
// 1. 현재 입력창 곡들 최우선순위로 캐싱
const currentTxt = document.getElementById('song-input').value;
const currentNumbers = [...currentTxt.matchAll(/^(\d+)/gm)].map(m => m[1]);
if (currentNumbers.length > 0) {
await Promise.all(currentNumbers.map(num => prefetchImage(num)));
}
if (isFirst) showToast('📥 악보 저장 중... (백그라운드 유휴시간 활용)');
const resp = await fetch('hymn_list.txt');
const text = await resp.text();
const numbers = [...text.matchAll(/^(\d+)/gm)].map(m => m[1]);
// 2. 전체 목록은 점진적으로 캐싱 (브라우저 부하 최소화)
for (let i = 0; i < numbers.length; i += 20) {
if (!navigator.onLine) break;
await Promise.all(numbers.slice(i, i + 20).map(async (num) => {
// utils.js의 prefetchImage와는 별도로 PWA 캐시 스토리지에 직접 저장
const numPadded = String(num).padStart(3, '0');
for (const ext of EXTENSIONS) {
const url = `images/${numPadded}${ext}`;
if (await cache.match(url)) return;
try {
const res = await fetch(url);
if (res.ok) { await cache.put(url, res); break; }
} catch(e) {}
}
}));
// 약 2초마다 다음 배치 진행 (네트워크 부하 분산)
await new Promise(r => setTimeout(r, 2000));
}
if (isFirst) {
localStorage.setItem('scoresCachedAt', Date.now());
showToast('✅ 악보 최적화 완료! 오프라인에서도 매우 빠르게 작동합니다');
}
} catch(e) {}
}
// ─── 실시간 입력 번호 프리페칭 ─────────────────────────────────────────
let _inputPrefetchTimer = null;
function handleInputPrefetch(val) {
clearTimeout(_inputPrefetchTimer);
_inputPrefetchTimer = setTimeout(() => {
const numbers = [...val.matchAll(/^(\d+)/gm)].map(m => m[1]);
numbers.forEach(num => prefetchImage(num));
}, 500); // 사용자가 입력을 멈춘 뒤 0.5초 후 실행
}
// ─── 카카오 인앱 브라우저 안내 ─────────────────────────────────────────
function checkKakaoBrowser() {
const ua = navigator.userAgent;
if (!/KAKAOTALK/i.test(ua)) return;
const banner = document.getElementById('kakao-banner');
const desc = document.getElementById('kakao-banner-desc');
const btn = document.getElementById('kakao-banner-btn');
const isIOS = /iphone|ipad|ipod/i.test(ua);
if (isIOS) {
desc.textContent = '우측 하단 ••• 메뉴를 열고 "Safari로 열기"를 선택하면 앱을 설치할 수 있습니다.';
btn.textContent = '닫기 (Safari에서 직접 열어주세요)';
btn.onclick = () => banner.style.display = 'none';
} else {
desc.textContent = '아래 버튼을 누르거나, 우측 상단 ··· 메뉴 → "다른 브라우저로 열기"를 선택해 주세요.';
btn.textContent = '크롬으로 열기 🌐';
btn.onclick = () => {
location.href = 'intent://' + location.host + location.pathname + location.search
+ '#Intent;scheme=https;package=com.android.chrome;end';
};
}
banner.style.display = 'block';
}
// ─── 안드로이드 뒤로 가기 처리 ─────────────────────────────────────────
let _backPressedOnce = false, _backTimer = null;
window.addEventListener('popstate', () => {
const viewer = document.getElementById('fullscreenViewer');
if (viewer && viewer.style.display === 'flex') {
closeFullscreen(); history.pushState({ page: 'app' }, ''); return;
}
const openModal = ['sharePreviewModal', 'lyricsModal', 'historyModal', 'songModal', 'notifModal']
.map(id => document.getElementById(id)).find(el => el && el.style.display === 'flex');
if (openModal) {
if (openModal.id === 'sharePreviewModal') closeSharePreview();
else if (openModal.id === 'lyricsModal') closeLyricsModal();
else if (openModal.id === 'notifModal') closeNotifModal();
else openModal.style.display = 'none';
history.pushState({ page: 'app' }, ''); return;
}
if (_backPressedOnce) { clearTimeout(_backTimer); return; }
_backPressedOnce = true;
showToast('뒤로 가기를 한 번 더 누르면 종료됩니다');
history.pushState({ page: 'app' }, '');
_backTimer = setTimeout(() => { _backPressedOnce = false; }, 2000);
});
// ─── 앱 초기화 ─────────────────────────────────────────────────────────
window.addEventListener('load', async () => {
await initFeatureFlags(); // ✅ 기능 플래그 로드 우선
// #85: 강제 새로고침 후 입력 중이던 데이터 복원
const _pt = sessionStorage.getItem('_pendingTitle');
const _ps = sessionStorage.getItem('_pendingSongs');
if (_pt) { document.getElementById('setlist-title').value = _pt; sessionStorage.removeItem('_pendingTitle'); }
if (_ps) { document.getElementById('song-input').value = _ps; sessionStorage.removeItem('_pendingSongs'); }
initSongList();
initLyrics();
initPushNotification();
updateNotifyBtn();
initNotifications();
checkKakaoBrowser();
initVersionDisplay(); // ✅ 버전 표시 영역 생성
setTimeout(precacheAllScores, 3000);
history.pushState({ page: 'app' }, '');
const _params = new URLSearchParams(location.search);
if (_params.get('autoload') === '1') {
history.replaceState({ page: 'app' }, '', '/');
autoLoadLatestConti();
} else if (_params.get('conti')) {
const _contiKey = _params.get('conti');
history.replaceState({ page: 'app' }, '', '/');
loadContiByKey(_contiKey);
}
navigator.serviceWorker?.addEventListener('message', (e) => {
if (e.data?.type === 'AUTOLOAD_LATEST') autoLoadLatestConti();
});
});
</script>
</body>
</html>