// index.php から渡された appMaster (最大3件の広告) を使用 let currentCards = []; let timerStarted = false; let resetCount = 0; // 名前リスト (各グループ48名以上のバリエーション) const namesMaster = { "18_22": ["めい", "結衣", "ユナ", "Sara", "ひまり", "凛", "サナ", "Mei", "あおい", "萌花", "ニコル", "Lia", "りこ", "陽菜", "ミア", "Yuna", "さくら", "美月", "エマ", "Saki", "ここね", "心春", "レイナ", "An", "ねね", "花音", "アリス", "Mio", "ほのか", "澪", "ナナ", "Hina", "ふうか", "詩織", "マノン", "Rina", "ゆあ", "楓", "リリ", "Coco", "いろは", "紬", "モカ", "Nana", "くるみ", "琴音", "ノア", "Yua"], "23_30": ["あやか", "遥", "ナツキ", "Maki", "ゆりか", "真由", "リカ", "Elena", "しおり", "香奈", "アンナ", "Risa", "えみ", "美穂", "サオリ", "Yuki", "ななみ", "彩香", "ミズキ", "Mina", "かなこ", "春香", "クリス", "Emi", "まき", "優子", "アイリ", "Yuka", "ともみ", "沙織", "レナ", "Saki", "あきこ", "絵里", "マユミ", "Chisato", "りえ", "梨沙", "カレン", "Aya", "さやか", "直美", "エリカ", "Kana", "ゆき", "舞", "ミキ", "Maki"], "31_40": ["遥香", "真理", "ユリカ", "Rina", "千尋", "恵子", "サキ", "Mio", "沙耶", "奈緒", "ミホ", "Nana", "美由紀", "佳奈", "アヤ", "Yuki", "明日香", "理恵", "カオリ", "Emi", "智美", "直子", "サユリ", "Maki", "美紀", "清美", "アケミ", "Risa", "祥子", "優香", "マキ", "Yuka", "亜美", "敦子", "エリカ", "Aya", "由美", "陽子", "カナ", "Kana", "里奈", "紀子", "ユキ", "Yuki", "舞子", "博美", "マミ", "Mami"], "41_50": ["幸子", "久美子", "シズエ", "Aki", "よしこ", "雅美", "カズミ", "Reiko", "しのぶ", "裕子", "マリコ", "Jun", "ひろみ", "悦子", "キョウコ", "Mami", "やすこ", "智子", "サチコ", "Yoko", "かずえ", "明美", "ナオミ", "Kyoko", "みどり", "純子", "ルミコ", "Aki", "たかこ", "昌代", "フミコ", "Michiko", "ゆみ", "照代", "エツコ", "Yumi", "和代", "恵美子", "ナツコ", "Natsu", "美江", "典子", "アツコ", "Atsuko", "早苗", "貴子", "ヨシコ", "Yoshiko"], "51_65": ["節子", "和子", "ミツコ", "Setsu", "京子", "恵子", "ヨシコ", "Kei", "百合子", "富子", "タカコ", "Yuri", "道子", "洋子", "フミコ", "Michiko", "文枝", "弘子", "マサコ", "Hiroko", "秀子", "良子", "カズコ", "Hide", "光江", "信子", "キヨコ", "Nobu", "芳江", "多恵子", "シゲコ", "Yoshi", "貞子", "春江", "トシコ", "Sada", "勝代", "千代子", "ハルコ", "Katsu", "美代子", "靖子", "サヨコ", "Yasuko", "登美子", "照子", "ヒサコ", "Tomi"] }; const ageRanges = { "18_22": [18, 22], "23_30": [23, 30], "31_40": [31, 40], "41_50": [41, 50], "51_65": [51, 65] }; // ブラウザバック対策 (function() { window.history.pushState(null, null, window.location.href); window.addEventListener('popstate', function () { showFinalModal(); window.history.pushState(null, null, window.location.href); }); })(); function generateData() { let combinedData = []; targetGroups.forEach(groupKey => { const names = namesMaster[groupKey]; const images = serverImages[groupKey]; const range = ageRanges[groupKey]; if (images.length === 0) images.push('./img/dummy.jpg'); for (let i = 0; i < names.length; i++) { combinedData.push({ img: images[i % images.length], name: names[i], age: (Math.random() > 0.85) ? "非公開" : Math.floor(Math.random() * (range[1] - range[0] + 1) + range[0]), group: groupKey }); } }); return combinedData; } const rawData = generateData(); function shuffleGrid(isFirst = false) { if (resetCount >= 10) { showFinalModal(); return; } if (!isFirst) resetCount++; let nextCards = currentCards.filter(c => c.selected); let source = [...rawData].sort(() => Math.random() - 0.5); if (isFirst) { let firstCard = {...paramUser}; if (!firstCard.img) { let fallbackGroup = targetGroups[0]; let randomImgList = serverImages[fallbackGroup]; firstCard.img = randomImgList[Math.floor(Math.random() * randomImgList.length)]; } nextCards.push(firstCard); } for (let item of source) { if (nextCards.length >= 4) break; if (!nextCards.find(c => c.img === item.img)) { nextCards.push({...item, selected: false}); } } currentCards = nextCards; render(); } function render() { const grid = document.getElementById('user-grid'); if(!grid) return; grid.innerHTML = ''; currentCards.forEach((user, idx) => { const div = document.createElement('div'); div.className = `card ${user.selected ? 'selected' : ''}`; div.onclick = () => toggleSelect(idx); const ageTxt = (user.age === '非公開') ? '非公開' : `${user.age}歳`; div.innerHTML = `
${user.name}${ageTxt}
`; grid.appendChild(div); }); } function toggleSelect(idx) { currentCards[idx].selected = !currentCards[idx].selected; render(); const selectedCount = currentCards.filter(c => c.selected).length; if (selectedCount >= 3) { setTimeout(showFinalModal, 300); } } function showFinalModal() { const modal = document.getElementById('modal'); if (!modal || modal.style.display === 'flex') return; let selectedUsers = currentCards.filter(c => c.selected); const modalTitle = document.getElementById('modal-title'); const modalActions = document.getElementById('individual-ctas'); modalActions.innerHTML = ''; if (selectedUsers.length === 0) { modalTitle.innerText = "特別オファーが届いています"; selectedUsers = currentCards.slice(0, 3); } selectedUsers.forEach((user, i) => { const app = appMaster[i % appMaster.length]; const ageTxt = (user.age === '非公開') ? '' : `${user.age}歳`; const row = document.createElement('div'); row.className = 'match-row'; row.innerHTML = `
${user.name} ${ageTxt}
${app.name}で接続
アプリを開く`; modalActions.appendChild(row); }); modal.style.display = 'flex'; startCountdown(); } function startCountdown() { if (timerStarted) return; timerStarted = true; let timeLeft = 300; const display = document.getElementById('final-timer'); const countdown = setInterval(() => { let min = Math.floor(timeLeft / 60); let sec = timeLeft % 60; if(display) display.innerText = `${String(min).padStart(2, '0')}:${String(sec).padStart(2, '0')}`; if (timeLeft <= 0) clearInterval(countdown); timeLeft--; }, 1000); } // 実行 shuffleGrid(true);