const startAmount = 100; const minAmount = 100; const maxAmount = 1000; const stepAmount = 50; const startDay = 30; const minDay = 1; const maxDay = 30; const stepDay = 1; const usdtCourse = 74; const currentLang = ''; let dayInputVal = 30; let amountInputVal = 150; window.addEventListener('DOMContentLoaded', () => { const listToShow = document.querySelectorAll('.calculator-content'), questionsList = document.querySelectorAll('.calculator-toggle'); questionsList.forEach((item, i) => { item.addEventListener('click', () => { questionsList.forEach(item => item.classList.remove('active')); item.classList.add('active'); listToShow.forEach((item, j) => { if (i === j) { listToShow.forEach(item => item.classList.add('hide')); item.classList.remove('hide'); } }) }) }) const creditAmount = document.querySelector('#credit-amount'), dateToReturn = document.querySelector('#date-to-return'), repayment = document.querySelector('#percent'); const swiperAmount = new Swiper('.swiper-amount', { direction: 'vertical', loop: false, slideToClickedSlide: true, slidesPerView: 3, mousewheel: { invert: false, }, centeredSlides: true }); swiperAmount.on('activeIndexChange', function (swiper) { swiper.el.querySelector('#sumInput')?.remove(); const value = minAmount + (swiper.activeIndex ?? 0) * stepAmount; let theDiv = swiper.slides[swiper.activeIndex].querySelector('.amount-option'); let input = document.createElement('input'); input.id = 'sumInput' input.classList.add('calculator__input'); input.value = value; input.name = 'amount' input.maxLength = 4; input.readOnly = true; theDiv.prepend(input) let inputSumMask = IMask( input, { mask: Number, min: 100, max: 1000, thousandsSeparator: '' }); const inputSumrub = document.getElementById('inputSumrub'); input.addEventListener('input', debounce((event) => { creditAmount.textContent = `${event.target.value} USDT`; inputSumrub.textContent = `${Math.ceil(event.target.value * usdtCourse)} RUB`; amountInputVal = event.target.value; getCalculationData(amountInputVal, dayInputVal); })); creditAmount.textContent = `${value} USDT`; inputSumrub.textContent = `${Math.ceil(value * usdtCourse)} RUB`; amountInputVal = value; getCalculationData(amountInputVal, dayInputVal); }); const swiperDay = new Swiper('.swiper-day', { direction: 'vertical', loop: false, slideToClickedSlide: true, slidesPerView: 3, mousewheel: { invert: false, }, centeredSlides: true }); swiperDay.on('activeIndexChange', function (swiper) { swiper.el.querySelector('#dayInput')?.remove(); const value = minDay + (swiper.activeIndex ?? 0) * stepDay let theDiv = swiper.slides[swiper.activeIndex].querySelector('.amount-option'); let input = document.createElement('input'); input.id = 'dayInput' input.classList.add('calculator__input'); input.value = value; input.name = 'day' input.maxLength = 2; input.readOnly = true; theDiv.prepend(input) let inputDateMask = IMask( input, { mask: Number, min: 1, max: 30, thousandsSeparator: '' }); input.addEventListener('input', debounce((event) => { calculateDateToReturn(event.target.value); dayInputVal = event.target.value; getCalculationData(amountInputVal, dayInputVal); })); calculateDateToReturn(value); dayInputVal = value; getCalculationData(amountInputVal, dayInputVal); }); generateAmountItems(swiperAmount); generateDateItems(swiperDay); function setCreditDetails() { calculateDateToReturn(); } function calculateDateToReturn(value) { let currentDate = new Date(); const dayToReturn = new Date(currentDate.setDate(currentDate.getDate() + +value)); const yyyy = dayToReturn.getFullYear(); let mm = dayToReturn.getMonth() + 1; // Months start at 0! let dd = dayToReturn.getDate(); if (dd < 10) dd = '0' + dd; if (mm < 10) mm = '0' + mm; dateToReturn.textContent = dd + '.' + mm + '.' + yyyy; } // input btn let timeoutId; function debounce(func, timeout = 300) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, args); }, timeout); }; } let intervalId; function stopInterval() { clearInterval(intervalId); } }) function generateAmountItems(swiper) { const items = [] for (let i = minAmount; i <= maxAmount; i += stepAmount) { items.push(`
${i} USDT
`); } swiper.appendSlide(items); setTimeout(() => swiper.slideTo(1)) } function generateDateItems(swiper) { const items = [] for (let i = minDay; i <= maxDay; i += stepDay) { items.push(`
${i} дней
`); } swiper.appendSlide(items); setTimeout(()=> swiper.slideTo(startDay - 1)) } function getCalculationData(amount, term, productId = 3) { // Local calculation (no backend/AJAX). // Requirement: for 30 days, 1000 USDT -> 1150 USDT total to repay. // Simple interest: 0.5% per day => total = amount * (1 + 0.005 * term) var a = parseFloat(amount) || 0; var t = parseInt(term, 10) || 0; var dailyRate = 0.005; // 0.5% per day var percent_without_promo = a * dailyRate * t; var totalWithoutPromo = a + percent_without_promo; var percentContainer = document.querySelector('#percent'); var elWithout = percentContainer ? percentContainer.querySelector('.percent-without-promo') : null; var elWith = percentContainer ? percentContainer.querySelector('.percent-with-promo') : null; if (window.CRYPSEE_PROMO && window.CRYPSEE_PROMO.hasPromo && elWithout && elWith) { elWithout.textContent = (Math.round(totalWithoutPromo * 10) / 10) + ' USDT'; var discounted = totalWithoutPromo * (1 - (Number(window.CRYPSEE_PROMO.percent) || 0) / 100); elWith.textContent = (Math.round(discounted * 10) / 10) + ' USDT'; } else if (percentContainer) { percentContainer.textContent = (Math.round(totalWithoutPromo * 10) / 10) + ' USDT'; } } document.addEventListener('click', function(e) { var btn = e.target.closest('#copy-promo'); if (!btn) return; var codeEl = document.getElementById('promo'); if (!codeEl) return; var code = (codeEl.textContent || '').trim(); if (!code) return; if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(code); } else { var tmp = document.createElement('textarea'); tmp.value = code; document.body.appendChild(tmp); tmp.select(); try { document.execCommand('copy'); } catch(e){} document.body.removeChild(tmp); } });