const host_api = 'https://wh.3xfaz.net';var credit = 0 var count = 0 const textAlignCanvas = function (e) { ctx.fillStyle = "#000"; ctx.fillText(e.deposit == 0 ? 'ยอดฝาก 0 บาท' : new Intl.NumberFormat('th-TH', { style: 'currency', currency: 'THB' }).format(e.deposit), 75, 30); ctx.fillText(!e.textWheel ? '' : e.textWheel, 255, 30); ctx.fillText(e.result == 0 ? (!e.textWheel ? (e.deposit == 0 ? 'ยังไม่มียอดฝาก' : '') : 'รับโบนัสแล้ว') : new Intl.NumberFormat('th-TH', { style: 'currency', currency: 'THB' }).format(e.result), 150, 100); } const checkDevice = function () { return /iPad|iPhone|iPod|Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent); } const isMobile = function () { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } const getDetail = function () { axios({ method: 'GET', url: `${host_api}/api/wheel/detail`, params: { phoneNumber: localStorage.getItem('phoneNumber') } }).then(function ({ data }) { if (data.code == 0) { let now = new Date() count = data.result.count let localNext = localStorage.getItem('nextTime') totalSpin = data.result.totalSpin document.getElementById('point').innerHTML = data.result.point document.getElementById('tSpin').innerHTML = data.result.totalSpin let nextTime = `${twoDigi(now.getHours())} : ${twoDigi(now.getMinutes())}` if (count == max && totalSpin == 0) { now.setDate(now.getDate() + 1) now.setHours(5) now.setMinutes(0) now = new Date(now) let tomorrow = `${twoDigi(now.getFullYear())}-${twoDigi(now.getMonth() + 1)}-${twoDigi(now.getDate())} ${twoDigi(now.getHours())}:${twoDigi(now.getMinutes())}` document.getElementById('time').innerHTML = tomorrow } else if (count > 0 && count < max && totalSpin == 0) { now.setHours(now.getHours() + 1) now.setMinutes(0) let nextHour = new Date(now) document.getElementById('time').innerHTML = `${twoDigi(nextHour.getHours())} : ${twoDigi(nextHour.getMinutes())}` } else if (count > 0 && count < max && totalSpin > 0) { if (localNext > now.getTime()) { localNext = new Date(parseInt(localNext)) document.getElementById('time').innerHTML = `${twoDigi(localNext.getHours())} : ${twoDigi(localNext.getMinutes())}` } else { document.getElementById('time').innerHTML = nextTime } } } }); } const createCustomer = function () { axios({ method: 'POST', url: `${host_api}/api/wheel/addCustomer`, data: { phoneNumber: localStorage.getItem('phoneNumber') } }).then(function ({ data }) { if (data.code == 1) alertShow('กรอกเบอร์โทร', data.message, 'warning', 'กรอกเบอร์โทร', 1) }); } const alertShow = function (title = "", msg = "", icon = "warning", cbtn = "ตกลง", path) { Swal.fire({ icon: icon, title: title, html: msg, confirmButtonText: cbtn, allowOutsideClick: false, confirmButtonColor: "#721909", }).then(result => { if (path == 1) return init() if (path == 2) return false if (path == 3) return getDetail() let phone_number = document.getElementById('phoneNumber') if (phone_number.value && phone_number.value.length == 10) { let localPhone = localStorage.getItem('phoneNumber') console.log('text', /[0]{1}[6,8,9]{1}/.test(phone_number.value)); if (!/[0]{1}[6,8,9]{1}/.test(phone_number.value)) { return alertShow('กรอกเบอร์โทร', 'เบอร์โทรศัพท์ไม่ถูกต้อง', 'warning', 'กรอกเบอร์โทร', 1) } if (localPhone && localPhone != phone_number.value) { localStorage.removeItem('nextTime') } localStorage.setItem('phoneNumber', phone_number.value) document.getElementById('phoneShow').innerHTML = phone_number.value createCustomer() getDetail() } else { alertShow('กรอกเบอร์โทร', 'กรุณากรอกเบอร์โทร', 'warning', 'ลองใหม่อีกครั้ง', 1) } }) if (isMobile()) { try { let el = document.querySelector('.swal2-popup') let icono = document.querySelector('.swal2-icon') let iconi = document.querySelector('.swal2-icon-content') let title = document.querySelector('.swal2-title') let text = document.querySelector('.swal2-html-container') let btn = document.querySelector('.swal2-confirm') el.classList.add('popup-mobile') icono.classList.add('popup-icono') iconi ? iconi.classList.add('popup-iconi') : "" title.classList.add('popup-title') text.classList.add('popup-text') btn.classList.add('popup-btn') document.getElementById('spin').classList.add('btnMobile') document.getElementById('history').classList.add('btnMobile') } catch (error) { console.log('error', error); } } } const info = async function () { return new Promise((resolve, reject) => { axios({ method: 'GET', url: `${host_api}/api/wheel/info` }).then(function ({ data }) { if (data.img) { document.getElementById("topic").src = data.img; document.getElementById("topic").style.display = "block"; } resolve(data) }).catch(error => { reject(error.respone.data) }) }); } const init = async function () { alertShow("กรอกเบอร์โทรเพื่อเข้าสู่ระบบ", ``, "warning", "เข้าสู่ระบบ") let phoneNumber = document.getElementById('phoneNumber') if (phoneNumber && isMobile()) { phoneNumber.style.padding = "1rem 2rem" phoneNumber.style.fontSize = "2rem" phoneNumber.style.lineHeight = "1.5" } } const main = function () { }; const onResize = function () { window.onresize = function (e) { } } const userAgent = function () { }