File size: 19,091 Bytes
3f9d112 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | <!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>🎮 کنترل زمان تانک استارز</title>
<style>
/* Reset & Base */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Vazir', 'Tahoma', sans-serif;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(145deg, #0b1120 0%, #1a253a 100%);
color: #fff;
padding: 1rem;
}
.container {
max-width: 700px;
width: 100%;
background: rgba(255, 255, 255, 0.06);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 50px;
padding: 2.5rem 2rem;
box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
text-align: center;
transition: all 0.3s ease;
}
/* Header */
.logo {
font-size: 3.5rem;
margin-bottom: 0.2rem;
}
h1 {
font-size: 2.2rem;
font-weight: 800;
background: linear-gradient(135deg, #f6d365, #fda085);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 0.5rem;
}
.sub {
color: #aab4ce;
font-size: 1rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
padding-bottom: 1.2rem;
margin-bottom: 1.8rem;
}
/* Timer Box */
.timer-box {
background: rgba(0, 0, 0, 0.35);
border-radius: 30px;
padding: 1.8rem 1rem;
margin-bottom: 2rem;
border: 1px solid rgba(255, 255, 255, 0.05);
}
.timer-label {
font-size: 0.9rem;
color: #8d99c4;
letter-spacing: 1px;
}
#countdown {
font-size: 4.2rem;
font-weight: 700;
font-family: 'Courier New', monospace;
background: linear-gradient(135deg, #00dbde, #fc00ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
line-height: 1.3;
direction: ltr;
}
.used-time {
color: #8d99c4;
font-size: 0.95rem;
margin-top: 0.2rem;
}
/* Buttons */
.btn {
display: inline-block;
padding: 1rem 2.8rem;
border: none;
border-radius: 60px;
font-size: 1.4rem;
font-weight: 700;
cursor: pointer;
transition: all 0.25s ease;
text-decoration: none;
color: #fff;
background: linear-gradient(135deg, #f093fb, #f5576c);
box-shadow: 0 8px 25px rgba(245, 87, 108, 0.35);
margin: 0.3rem;
}
.btn:hover {
transform: translateY(-3px) scale(1.02);
box-shadow: 0 12px 35px rgba(245, 87, 108, 0.5);
}
.btn:active {
transform: scale(0.96);
}
.btn-secondary {
background: linear-gradient(135deg, #4facfe, #00f2fe);
box-shadow: 0 8px 25px rgba(79, 172, 254, 0.3);
}
.btn-secondary:hover {
box-shadow: 0 12px 35px rgba(79, 172, 254, 0.5);
}
.btn:disabled {
opacity: 0.4;
cursor: not-allowed;
transform: none !important;
box-shadow: none !important;
}
/* Blocked State */
.blocked-icon {
font-size: 5rem;
display: block;
margin-bottom: 0.5rem;
}
.blocked-title {
font-size: 3rem;
font-weight: 800;
color: #fda085;
margin-bottom: 0.2rem;
}
.blocked-msg {
font-size: 1.6rem;
color: #e0e7ff;
}
.blocked-sub {
font-size: 1rem;
color: #8d99c4;
margin-top: 1.5rem;
border-top: 1px solid rgba(255, 255, 255, 0.08);
padding-top: 1.5rem;
}
.hidden {
display: none !important;
}
/* Reset / Danger */
.reset-btn {
margin-top: 2rem;
background: transparent;
border: 1px solid #4a5568;
color: #a0aec0;
padding: 0.5rem 1.5rem;
border-radius: 40px;
font-size: 0.8rem;
cursor: pointer;
transition: 0.2s;
}
.reset-btn:hover {
background: #2d3748;
border-color: #fc8181;
color: #fc8181;
}
/* Responsive */
@media (max-width: 500px) {
.container {
padding: 1.5rem 1rem;
border-radius: 30px;
}
#countdown {
font-size: 3rem;
}
h1 {
font-size: 1.8rem;
}
.btn {
font-size: 1.1rem;
padding: 0.8rem 1.8rem;
}
.blocked-title {
font-size: 2.2rem;
}
}
</style>
</head>
<body>
<div class="container" id="app">
<!-- ========== وضعیت: بازی مجاز است ========== -->
<div id="state-play">
<div class="logo">🎯</div>
<h1>تانک استارز</h1>
<div class="sub">⏳ زمان مجاز روزانه: ۱ ساعت</div>
<div class="timer-box">
<div class="timer-label">⌛ زمان باقیمانده</div>
<div id="countdown">01:00:00</div>
<div class="used-time" id="usedDisplay">استفادهشده: ۰ دقیقه</div>
</div>
<!-- دکمهی باز کردن بازی (در تب جدید) -->
<button class="btn" id="playBtn">🔥 شروع بازی</button>
<br /><br />
<small style="color:#6b7a9f; font-size:0.8rem;">
⚡ با کلیک، بازی در پنجرهی جدید باز میشود. <br />
این صفحه را باز بگذارید تا زمانسنج کار کند!
</small>
<br />
<button class="reset-btn" id="forceResetBtn">🔄 ریست دستی (فقط برای تست)</button>
</div>
<!-- ========== وضعیت: زمان تمام شد ========== -->
<div id="state-blocked" class="hidden">
<span class="blocked-icon">⏰</span>
<div class="blocked-title">بسه بچه جون !😁</div>
<div class="blocked-msg">دیگه زمان بازی تموم شد!</div>
<div class="blocked-msg" style="font-size:1.8rem; margin-top:0.5rem;">برو بعداً بیا !!</div>
<div class="blocked-sub">
⭐ امروز ۱ ساعت کامل بازی کردی. <br />
فردا دوباره خوش اومدی! روز نو، بازی نو.
</div>
<br />
<button class="reset-btn" id="resetBtnAdmin">🔑 ریست اجباری (فقط مدیر)</button>
</div>
</div>
<script>
// ------------------------------------------------
// 🧠 ابر الگوریتم کنترل زمان (به زبان ساده ولی قدرتمند)
// ------------------------------------------------
(function() {
// ---------- ثابتها ----------
const LIMIT_MS = 60 * 60 * 1000; // ۱ ساعت
const STORAGE_KEY = 'tank_stars_data';
const GAME_URL = 'https://www.crazygames.com/game/tank-stars-online';
// ---------- عناصر DOM ----------
const statePlay = document.getElementById('state-play');
const stateBlocked = document.getElementById('state-blocked');
const countdownEl = document.getElementById('countdown');
const usedDisplay = document.getElementById('usedDisplay');
const playBtn = document.getElementById('playBtn');
const resetBtnAdmin = document.getElementById('resetBtnAdmin');
const forceResetBtn = document.getElementById('forceResetBtn');
// ---------- متغیرهای وضعیت ----------
let timerInterval = null;
let currentUsed = 0; // میلیثانیه مصرفشده امروز
let isTimerRunning = false;
// ---------- توابع کمکی ----------
function formatTime(ms) {
if (ms < 0) ms = 0;
const totalSec = Math.floor(ms / 1000);
const h = Math.floor(totalSec / 3600);
const m = Math.floor((totalSec % 3600) / 60);
const s = totalSec % 60;
if (h > 0) {
return String(h).padStart(2, '0') + ':' + String(m).padStart(2, '0') + ':' + String(s).padStart(2, '0');
}
return String(m).padStart(2, '0') + ':' + String(s).padStart(2, '0');
}
function formatMinutes(ms) {
const min = Math.floor(ms / 60000);
return min + ' دقیقه';
}
// ---------- بارگذاری داده از localStorage ----------
function loadData() {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) {
// روز جدید یا اولین بار
return {
date: new Date().toDateString(),
used: 0,
isBlocked: false
};
}
try {
const data = JSON.parse(raw);
const today = new Date().toDateString();
// اگر روز عوض شده، ریست کن
if (data.date !== today) {
return {
date: today,
used: 0,
isBlocked: false
};
}
return data;
} catch (e) {
return {
date: new Date().toDateString(),
used: 0,
isBlocked: false
};
}
}
// ---------- ذخیره داده در localStorage ----------
function saveData(data) {
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
}
// ---------- بروزرسانی UI و چک کردن وضعیت ----------
function updateUI() {
const data = loadData();
currentUsed = data.used || 0;
const remaining = LIMIT_MS - currentUsed;
// نمایش زمان باقیمانده
if (remaining > 0) {
countdownEl.textContent = formatTime(remaining);
usedDisplay.textContent = 'استفادهشده: ' + formatMinutes(currentUsed);
} else {
countdownEl.textContent = '00:00:00';
usedDisplay.textContent = 'استفادهشده: ۱ ساعت (تمام)';
}
// مدیریت وضعیت قفل
if (remaining <= 0) {
// مسدود کن
statePlay.classList.add('hidden');
stateBlocked.classList.remove('hidden');
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
isTimerRunning = false;
}
// ذخیره وضعیت بلاک
const d = loadData();
if (!d.isBlocked) {
d.isBlocked = true;
saveData(d);
}
// غیرفعال کردن دکمهی بازی
playBtn.disabled = true;
} else {
// مجاز
statePlay.classList.remove('hidden');
stateBlocked.classList.add('hidden');
playBtn.disabled = false;
// اگر تایمر اجرا نیست، شروع کن
if (!timerInterval) {
startTimer();
}
}
}
// ---------- تایمر ثانیهای (افزایش زمان مصرفشده) ----------
function startTimer() {
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
}
isTimerRunning = true;
timerInterval = setInterval(() => {
// فقط اگر صفحه قابل مشاهده باشد (اختیاری) ولی برای دقت همیشه بروز کن
const data = loadData();
let newUsed = (data.used || 0) + 1000; // +1 ثانیه
if (newUsed >= LIMIT_MS) {
newUsed = LIMIT_MS;
// ذخیره و توقف
data.used = newUsed;
data.isBlocked = true;
saveData(data);
// بروزرسانی UI و توقف تایمر
updateUI();
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
isTimerRunning = false;
}
return;
}
// بهروزرسانی مقدار
data.used = newUsed;
data.isBlocked = false;
saveData(data);
// بروزرسانی نمایشگر
currentUsed = newUsed;
const remaining = LIMIT_MS - currentUsed;
countdownEl.textContent = formatTime(remaining);
usedDisplay.textContent = 'استفادهشده: ' + formatMinutes(currentUsed);
}, 1000);
}
// ---------- باز کردن بازی ----------
function openGame() {
const data = loadData();
if (data.isBlocked || (data.used || 0) >= LIMIT_MS) {
alert('⛔ وقت بازی تموم شده! صفحه رو رفرش کن تا پیام رو ببینی.');
updateUI();
return;
}
// باز کردن در تب جدید
window.open(GAME_URL, '_blank');
// یک اعلان کوچک
console.log('🎮 بازی باز شد، زمان در حال شمارش است...');
}
// ---------- ریست دستی (فقط برای مدیر) ----------
function forceReset() {
if (confirm('🔥 آیا مطمئنی میخوای زمان رو ریست کنی؟ (فقط برای تست)')) {
const today = new Date().toDateString();
const newData = {
date: today,
used: 0,
isBlocked: false
};
saveData(newData);
// ریست تایمر
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
isTimerRunning = false;
}
updateUI();
startTimer();
alert('✅ زمان ریست شد!');
}
}
// ---------- مقداردهی اولیه ----------
function init() {
// بارگذاری داده و اعتبارسنجی
const data = loadData();
// اگر بلاک شده ولی زمان کمتر از حد مجاز است (احتمالاً باگ)، تصحیح کن
if (data.isBlocked && (data.used || 0) < LIMIT_MS) {
data.isBlocked = false;
saveData(data);
}
// اگر زمان به حد رسیده، بلاک کن
if ((data.used || 0) >= LIMIT_MS) {
data.isBlocked = true;
saveData(data);
}
updateUI();
// اتصال رویدادها
playBtn.addEventListener('click', openGame);
resetBtnAdmin.addEventListener('click', forceReset);
forceResetBtn.addEventListener('click', forceReset);
// اگر صفحه بسته شود، تایمر را پاک کن (اما داده ذخیره میشود)
window.addEventListener('beforeunload', function() {
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
isTimerRunning = false;
}
});
// اگر صفحه دوباره فعال شد، چک کن
document.addEventListener('visibilitychange', function() {
if (!document.hidden) {
// وقتی کاربر به برگه برمیگردد، وضعیت را رفرش کن
updateUI();
// اگر تایمر نیست و هنوز وقت باقی است، شروع کن
if (!timerInterval && !document.getElementById('state-blocked').classList.contains('hidden') ===
false) {
const data2 = loadData();
if ((data2.used || 0) < LIMIT_MS) {
startTimer();
}
}
}
});
console.log('🧠 ابر الگوریتم کنترل زمان با موفقیت بارگذاری شد!');
}
// اجرا
init();
})();
</script>
</body>
</html> |