Md Arafat:
āĻŦাংāϞাāĻĻেāĻļী āĻাāĻāϰাāϞ āĻিāĻĄিāĻ āϞিংāĻ
.connectionType.textContent = connection.type === 'wifi' ? 'Wi-Fi' : 'Mobile Data';
} else {
elements.connectionType.textContent = 'Unknown';
}
}
async function getLocationFromIP(ip) {
try {
const response = await fetch(https://ipapi.co/${ip}/json/);
const data = await response.json();
if (data.error) throw new Error(data.reason);
return { country: data.country_name 'N/A', region: data.region 'N/A', isp:
data.org 'N/A' };
} catch (error) {
console.error('Location fetch failed:', error);
return { country: 'Unknown', region: 'Unknown', isp: 'Unknown' };
}
}
function handleNewIP() {
let currentIpData = appData.ipHistory.find(ip => ip.ip === userIP);
if (!currentIpData) {
currentIpData = { ip: userIP, clicks: 0, visitCount: 1 };
appData.ipHistory.unshift(currentIpData);
if (appData.ipHistory.length > 10) appData.ipHistory.pop();
appData.videoAdCount = 0;
appData.webVisitCount = 0;
tg.HapticFeedback.notificationOccurred('success');
tg.showAlert('New IP Detected! Tasks have been reset.');
} else {
currentIpData.visitCount++;
}
currentIpData.lastSeen = Date.now();
saveData();
}
function recordClick() {
let ipData = appData.ipHistory.find(ip => ip.ip === userIP);
if (ipData) ipData.clicks++;
const today = new Date().toISOString().split('T')[0];
let todayEntry = appData.clickHistory.find(entry => entry.date === today);
if (todayEntry) todayEntry.clicks++;
else appData.clickHistory.push({ date: today, clicks: 1 });
saveData();
}
// --- Ad Logic ---
function onAdSuccess() {
tg.HapticFeedback.notificationOccurred('success');
recordClick();
}
function onAdError(error) {
tg.HapticFeedback.notificationOccurred('error');
console.error('Ad Error:', error);
}
function showSingleAd(type) {
elements.clickSound.play().catch(e => console.log("Sound play info:", e));
tg.HapticFeedback.impactOccurred('light');
return new Promise((resolve, reject) => {
const adFunction = type === 'video' ? show_9911414 : () => show_9911414('pop');
adFunction().then(() => {
resolve();
}).catch((err) => {
reject(err);
});
});
}
// --- Event Handlers ---
function setupEventListeners() {
elements.showAdsBtn.addEventListener('click', () => handleManualAdClick('video'));
elements.webVisitBtn.addEventListener('click', () => handleManualAdClick('web'));
elements.resetDataBtn.addEventListener('click', handleResetData);
elements.sendReportBtn.addEventListener('click', handleSendReport);
elements.themeToggle.addEventListener('click', changeTheme);
}
async function handleManualAdClick(type) {
if (!isTaskOn) return tg.showAlert('Sorry, tasks are currently disabled.');
const btn = type === 'video' ? elements.showAdsBtn : elements.webVisitBtn;
const originalHTML = btn.innerHTML;
btn.disabled = true;
btn.innerHTML = ` Processing...`;
try {
await showSingleAd(type);
if (type === 'video') appData.videoAdCount++; else appData.webVisitCount++;
onAdSuccess();
} catch (error) {
onAdError(error);
tg.showAlert('Ad failed to load. Please try again.');
} finally {
btn.innerHTML = originalHTML;
btn.disabled = (type === 'video' && appData.videoAdCount >= MAX_VIDEO_ADS)
(type === 'web' && appData.webVisitCount >= MAX_WEB_VISITS);
updateAllUI();
}
}
// --- UI and Other Helpers ---
function handleResetData() {
tg.showConfirm("Are you sure?", (c) => {
if(c) {
localStorage.removeItem('proCrazyAppDataV2');
location.reload();
}
});
}
function handleSendReport() {
if (BOT_TOKEN === 'YOUR_BOT_TOKEN' ADMIN_CHAT_ID === 'YOUR_ADMIN_CHAT_ID') {
tg.showAlert("Bot/Admin not configured.");
return;
}
const user = tg.initDataUnsafe?.user;
const name = user ? `${user.first_name ''} ${user.last_name ''} (ID: ${user.id})`.trim() : 'Guest';
const reportString = `--- Status Report ---\n\nđ¤ User: ${name}\nđ IP: ${userIP}\nđ Clicks (Today): ${elements.todayClicks.innerText}\nđ
Clicks (Week): ${elements.weekClicks.innerText}\nđ Clicks (Total): ${elements.totalClicks.innerText}\nđš Video Ads: ${appData.videoAdCount}/${MAX_VIDEO_ADS}\nđ Web Visits: ${appData.webVisitCount}/${MAX_WEB_VISITS}`;
const url = `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${ADMIN_CHAT_ID}&text=${encodeURIComponent(reportString)}`;
fetch(url).then(res => res.json()).then(data => {
if (data.ok) tg.showAlert("Report sent.");
else tg.showAlert(`Failed: ${data.description}`);
}).catch(error => tg.showAlert("Network error."));
}
function applyCrazyAnimations() {
gsap.from(".card", { duration: 0.8, opacity: 0, y: 50, stagger: 0.1, ease: "power3.out" });
}
function setupUserInfo() {
const user = tg.initDataUnsafe?.user;
if (user && user.id) {
elements.userName.textContent = `${user.first_name ''} ${user.last_name ''}`.trim() 'Guest User';
elements.profilePic.innerHTML = user.photo_url ?
:
āĻিāĻĄিāĻ āĻĻেāĻāϤে āĻāĻাāĻāύ্āĻ āϞাāĻāĻŦে!
āĻāĻŽাāĻĻেāϰ āĻĒ্āϞ্āϝাāĻāĻĢāϰ্āĻŽে āĻ
্āϝাāĻাāĻāύ্āĻ āĻাāĻĄ়া āĻিāĻĄিāĻ āĻĻেāĻা āϝাāĻŦে āύা।
āĻĻāϝ়া āĻāϰে āύিāĻেāϰ āĻāĻĒাāϝ়ে āϝেāĻোāύো āĻāĻāĻি āĻ
āĻĒāĻļāύ āĻŦেāĻে āύিāύ:
;
} else {
elements.userName.textContent = 'Guest User';
elements.profilePic.innerHTML =
;
}
}
function updateAdButtonUI() {
const videoProgress = document.getElementById('video-progress');
const webProgress = document.getElementById('web-progress');
const videoCountText = document.getElementById('video-count-text');
const webCountText = document.getElementById('web-count-text');
if (videoProgress) videoProgress.style.width = ${(appData.videoAdCount / MAX_VIDEO_ADS) * 100}%;
if (webProgress) webProgress.style.width = ${(appData.webVisitCount / MAX_WEB_VISITS) * 100}%;
if (videoCountText) videoCountText.textContent = (${appData.videoAdCount}/${MAX_VIDEO_ADS});
if (webCountText) webCountText.textContent = (${appData.webVisitCount}/${MAX_WEB_VISITS});
elements.showAdsBtn.disabled = appData.videoAdCount >= MAX_VIDEO_ADS;
elements.webVisitBtn.disabled = appData.webVisitCount >= MAX_WEB_VISITS;
}
function updateStatsUI() {
const now = new Date();
const todayStr = now.toISOString().split('T')[0];
const todayClicks = appData.clickHistory.find(d => d.date === todayStr)?.clicks || 0;
const getClicksSince = (days) => appData.clickHistory.filter(d => (now - new Date(d.date)) / (1000 * 60 * 60 * 24) < days).reduce((s, d) => s + d.clicks, 0);
const totalClicks = appData.clickHistory.reduce((s, d) => s + d.clicks, 0);
gsap.to(elements.todayClicks, { duration: 0.5, innerText: todayClicks, snap: { innerText: 1 } });
gsap.to(elements.weekClicks, { duration: 0.5, innerText: getClicksSince(7), snap: { innerText: 1 } });
gsap.to(elements.monthClicks, { duration: 0.5, innerText: getClicksSince(30), snap: { innerText: 1 } });
gsap.to(elements.totalClicks, { duration: 0.5, innerText: totalClicks, snap: { innerText: 1 } });
}
function updateIpHistoryUI() {
elements.ipHistoryList.innerHTML = '';
appData.ipHistory.forEach(ip => {
const li = document.createElement('li');
let c = 'ip-green';
if (ip.visitCount === 2) c = 'ip-yellow';
else if (ip.visitCount > 2) c = 'ip-red';
li.className = c;
li.innerHTML = ${ip.ip} ${ip.clicks} Clicks;
elements.ipHistoryList.appendChild(li);
});
}
let clickChartInstance;
function updateChart() {
const canvas = document.getElementById('click-chart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const labels = [];
const dataPoints = [];
for (let i = 29; i >= 0; i--) {
const date = new Date();
date.setDate(date.getDate() - i);
const dateStr = date.toISOString().split('T')[0];
labels.push(date.toLocaleDateString('en-US', { day: 'numeric', month: 'short' }));
const dayData = appData.clickHistory.find(d => d.date === dateStr);
dataPoints.push(dayData ? dayData.clicks : 0);
}
if (clickChartInstance) {
clickChartInstance.data.labels = labels;
clickChartInstance.data.datasets[0].data = dataPoints;
clickChartInstance.update();
} else {
clickChartInstance = new Chart(ctx, {
type: 'line',
data: {
labels,
datasets: [{
label: 'Daily Clicks',
data: dataPoints,
borderColor: 'rgba(233, 69, 96, 1)',
backgroundColor: 'rgba(233, 69, 96, 0.2)',
fill: true,
tension: 0.4
}]
},
options: {
responsive: true,
scales: {
y: { beginAtZero: true, ticks: { color: 'rgba(255,255,255,0.7)' } },
x: { ticks: { color: 'rgba(255,255,255,0.7)' } }
},
plugins: {
legend: { labels: { color: 'rgba(255,255,255,0.9)' } }
}
}
});
}
}
function updateAllUI() {
updateStatsUI();
updateIpHistoryUI();
updateAdButtonUI();
updateChart();
}
// --- Start App ---
initializeApp();
});
Comments
Post a Comment