/* * Filename: /js/url-functions.js * Description: URL.KR-Main JavaScript for URL shortener functionality * Last updated: 2024-10-27 */ function enableSubmit() { document.getElementById("submit-btn").disabled = false; } function onSubmit(event) { event.preventDefault(); const form = document.getElementById("url-form"); const formData = new FormData(form); const csrfToken = document.querySelector('input[name="token"]').value; fetch(form.action, { method: 'POST', headers: { 'X-CSRF-TOKEN': csrfToken }, body: formData }).then(response => response.text()) .then(result => { document.open(); document.write(result); document.close(); }).catch(error => console.error('Error:', error)); } function showShortUrl() { const shortUrlElement = document.getElementById("short-url"); const shortUrlLinkElement = document.getElementById("short-url-link"); const shortUrl = shortUrlElement.value; shortUrlLinkElement.href = shortUrl; document.getElementById("short-url-container").style.display = "flex"; document.getElementById("recaptcha-container").style.display = "none"; document.getElementById("menu").style.display = "flex"; document.getElementById("stats-link").href = shortUrl + '+'; document.getElementById("new-link").href = "/"; document.getElementById("redirect-link").href = shortUrl; showAd(); } function copyToClipboard() { const shortUrl = document.getElementById("short-url"); shortUrl.select(); document.execCommand("copy"); alert("복사되었습니다. 필요한 곳에 붙여 넣으세요."); } function showRecaptcha() { const recaptchaContainer = document.getElementById("recaptcha-container"); const recaptchaNoticeContainer = document.getElementById("recaptcha-notice-container"); if (!recaptchaContainer.innerHTML) { grecaptcha.render('recaptcha-container', { 'sitekey': '6LdtzwQaAAAAACM_Rsd9FCr2_em0zkTTsWOST8Qx', 'callback': enableSubmit }); } recaptchaNoticeContainer.style.display = "flex"; recaptchaContainer.style.display = "block"; } function resetForm() { document.getElementById('url-form').reset(); document.getElementById("long_url").value = ""; document.getElementById("recaptcha-container").style.display = "none"; document.getElementById("short-url-container").style.display = "none"; document.getElementById("menu").style.display = "none"; document.getElementById("submit-btn").disabled = true; } function showAd() { const body = document.body; const maskLayer = document.getElementById('maskLayer'); const countdownText = document.getElementById('countdownText'); const closeButton = document.getElementById('closeButton'); function closeMaskLayer() { maskLayer.style.display = 'none'; body.classList.remove('no-scroll'); setTimeout(() => { maskLayer.style.display = 'flex'; body.classList.add('no-scroll'); }, 24 * 60 * 60 * 1000); } if (!localStorage.getItem('maskLayerClosed') || Date.now() - localStorage.getItem('maskLayerClosed') > 24 * 60 * 60 * 1000) { countdown(0); body.classList.add('no-scroll'); } else { closeMaskLayer(); } closeButton.addEventListener('click', () => { localStorage.setItem('maskLayerClosed', Date.now()); }); } // Initialize on DOM load document.addEventListener('DOMContentLoaded', function() { document.getElementById('long_url')?.addEventListener('focus', showRecaptcha); document.getElementById('reset-btn')?.addEventListener('click', resetForm); // Initial display settings document.getElementById("short-url-container").style.display = "none"; document.getElementById("menu").style.display = "none"; // Load daily statistics fetch('admin/get_daily_statistics.php') .then(response => response.json()) .then(data => { document.getElementById('shortUrlCount').innerText = data.short_url_count; }) .catch(error => console.error('Error:', error)); });