명언을 페이지 로드 시 미리 받아 전역 변수로 들고 있던 방식을 버리고, 바구니가 찰 때만 quotes.txt를 fetch해서 그 자리에서 쓰고 버리도록 변경 (지역 변수라 사용 후 참조가 안 남음)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
28
index.html
28
index.html
@@ -137,12 +137,6 @@ const confettiLayer = document.getElementById('confettiLayer');
|
||||
const basketCountEl = document.getElementById('basketCount');
|
||||
const quoteEl = document.getElementById('quoteText');
|
||||
|
||||
let quotes = [];
|
||||
fetch('./quotes.txt')
|
||||
.then(r => (r.ok ? r.text() : ''))
|
||||
.then(text => { quotes = text.split('\n').map(s => s.trim()).filter(Boolean); })
|
||||
.catch(() => {});
|
||||
|
||||
// ---------- renderer / scene / camera ----------
|
||||
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, powerPreference: 'low-power' });
|
||||
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
|
||||
@@ -591,16 +585,24 @@ function catchInBasket(apple){
|
||||
if (basketCount >= BASKET_FULL) celebrate();
|
||||
}
|
||||
|
||||
function celebrate(){
|
||||
// 명언은 축하 화면이 뜰 때만 그 자리에서 불러와 쓰고, 목록을 어디에도 저장해두지
|
||||
// 않는다 — 함수가 끝나면 로컬 변수(list)라 참조가 안 남아 바로 GC 대상이 된다.
|
||||
async function celebrate(){
|
||||
celebrateEl.classList.add('show');
|
||||
if (quotes.length){
|
||||
quoteEl.textContent = quotes[Math.floor(Math.random() * quotes.length)];
|
||||
quoteEl.classList.add('show');
|
||||
} else {
|
||||
quoteEl.classList.remove('show');
|
||||
}
|
||||
quoteEl.classList.remove('show');
|
||||
spawnConfetti();
|
||||
setTimeout(clearBasket, 2800);
|
||||
|
||||
try {
|
||||
const res = await fetch('./quotes.txt');
|
||||
if (!res.ok) return;
|
||||
const text = await res.text();
|
||||
const list = text.split('\n').map(s => s.trim()).filter(Boolean);
|
||||
if (list.length){
|
||||
quoteEl.textContent = list[Math.floor(Math.random() * list.length)];
|
||||
quoteEl.classList.add('show');
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function spawnConfetti(){
|
||||
|
||||
Reference in New Issue
Block a user