const CinemaAdEngine = {
config: {
adUrl: "https://internattachment.com/yzusq0xxyt?key=4abe7df73770ea461ef9877a7a72213c",
maxPerSession: 5,
cooldownMs: 6 * 60 * 1000, // 6 دقائق
mode: 'ticket', // 'ticket' | 'popcorn' | 'rating' | 'agegate'
debug: false
},
state: {
count: parseInt(sessionStorage.getItem('ca_count') || '0'),
lastTime: parseInt(sessionStorage.getItem('ca_last') || '0'),
isOpen: false,
popcornLevel: parseInt(localStorage.getItem('ca_popcorn') || '0'),
popcornTarget: 5
},
// ========== CORE: فتح الإعلان ==========
openAd: function() {
if (this.state.isOpen) return false;
const now = Date.now();
if (this.state.count >= this.config.maxPerSession) return false;
if (now - this.state.lastTime < this.config.cooldownMs) return false;
this.state.isOpen = true;
const popup = window.open(this.config.adUrl, '_blank', 'noopener,noreferrer,width=800,height=600');
if (popup) {
popup.blur();
window.focus();
this.state.count++;
this.state.lastTime = now;
sessionStorage.setItem('ca_count', this.state.count);
sessionStorage.setItem('ca_last', this.state.lastTime);
if (this.config.debug) console.log('🎬 CinemaAd opened #' + this.state.count);
}
setTimeout(() => { this.state.isOpen = false; }, 1500);
return !!popup;
},
// ========== 1. تذكرة سينما 3D ==========
initTicket: function() {
const ticket = document.createElement('div');
ticket.id = 'cinema-ticket';
ticket.innerHTML = `
🎟️
عرض خاص الليلة
المقعد: A12 | الصالة: 7
⚡ اضغط لفتح التذكرة
▣
🔥 انقر للدخول المجاني
`;
document.body.appendChild(ticket);
ticket.querySelector('#ticket-card').addEventListener('click', () => {
const card = ticket.querySelector('#ticket-card');
card.classList.add('ticket-flip');
// فتح الإعلان
const opened = this.openAd();
// بعد الانقلاب، نظهر رسالة النجاح
setTimeout(() => {
card.innerHTML = `
✅
تم التحقق!
استمتع بالعرض 🍿
`;
setTimeout(() => ticket.remove(), 3000);
}, 400);
});
},
// ========== 2. دلو الفشار ==========
initPopcorn: function() {
const bucket = document.createElement('div');
bucket.id = 'cinema-popcorn';
const pct = Math.min(100, (this.state.popcornLevel / this.state.popcornTarget) * 100);
bucket.innerHTML = `
🍿 دلو الفشار
${this.state.popcornLevel} / ${this.state.popcornTarget} حفنة
${this.state.popcornLevel >= this.state.popcornTarget ? '🎉 احصل على الجائزة!' : '➕ أضف حفنة'}
`;
document.body.appendChild(bucket);
const btn = bucket.querySelector('#popcorn-add');
btn.addEventListener('click', () => {
if (this.state.popcornLevel >= this.state.popcornTarget) {
// جائزة! فيلم VIP
bucket.querySelector('.popcorn-box').innerHTML = `
🎬
مبروك! فيلم VIP مفتوح
سيتم توجيهك الآن...
`;
localStorage.setItem('ca_popcorn', '0');
setTimeout(() => {
window.location.href = '/vip-movie'; // غيّر هذا لرابط فيلم VIP حقيقي
}, 1500);
return;
}
const opened = this.openAd();
if (opened) {
this.state.popcornLevel++;
localStorage.setItem('ca_popcorn', this.state.popcornLevel);
// تحديث الواجهة
const newPct = Math.min(100, (this.state.popcornLevel / this.state.popcornTarget) * 100);
bucket.querySelector('.popcorn-bucket-visual').style.background =
`linear-gradient(to top, #e67e22 ${newPct}%, #3d2817 ${newPct}%)`;
bucket.querySelector('.popcorn-level').textContent =
`${this.state.popcornLevel} / ${this.state.popcornTarget} حفنة`;
if (this.state.popcornLevel >= this.state.popcornTarget) {
btn.textContent = '🎉 احصل على الجائزة!';
btn.style.background = 'linear-gradient(90deg, #2ecc71, #27ae60)';
}
}
});
},
// ========== 3. شاشة التقييد العمري ==========
initAgeGate: function() {
// تظهر مرة واحدة لكل فيلم (session)
if (sessionStorage.getItem('ca_agegate_done')) return;
const gate = document.createElement('div');
gate.id = 'cinema-agegate';
gate.innerHTML = `
PG-13
تقييد عمرى
هذا الفيلم يحتوي على مشاهد عنف وتوتر.
يُنصح بمشاهدته بصحبة أحد البالغين.
اضغط للمتابعة إلى العرض.
🎬 أنا مستعد — دخول العرض
↩️ رجوع للقائمة
`;
document.body.appendChild(gate);
gate.querySelector('#age-confirm').addEventListener('click', () => {
this.openAd();
sessionStorage.setItem('ca_agegate_done', '1');
gate.style.opacity = '0';
gate.style.transition = 'opacity 0.5s';
setTimeout(() => gate.remove(), 500);
});
gate.querySelector('#age-skip').addEventListener('click', () => {
history.back();
});
},
// ========== 4. بطاقة تقييم IMDb ==========
initRating: function() {
const rating = document.createElement('div');
rating.id = 'cinema-rating';
rating.innerHTML = `
IMDb
8.7
⭐
⭐
⭐
⭐
⭐
قيّم قبل المشاهدة
`;
document.body.appendChild(rating);
const stars = rating.querySelectorAll('.star');
stars.forEach((star, idx) => {
star.addEventListener('mouseenter', () => {
stars.forEach((s, i) => {
if (i <= idx) s.classList.add('active');
else s.classList.remove('active');
});
});
star.addEventListener('click', () => {
this.openAd();
rating.querySelector('.rating-card').innerHTML = `
🙏
شكراً!
تم حفظ تقييمك