// ==UserScript==
// @name Nusuk Availability Monitor
// @namespace nusuk-monitor
// @version 1.0.0
// @description مراقبة توفر مواعيد نسك والتنبيه فور ظهورها
// @match https://www.nusuk.sa/*
// @match https://services.nusuk.sa/*
// @match https://umrah.nusuk.sa/*
// @grant GM_notification
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-idle
// ==/UserScript==
(function () {
'use strict';
const CONFIG = {
interval: 5000, // الفحص كل 5 ثوانٍ
sound: true,
notification: true,
autoScroll: true
};
let lastAvailable = false;
let monitoring = GM_getValue('nusuk_monitoring', true);
// =========================
// واجهة المراقبة
// =========================
const panel = document.createElement('div');
panel.innerHTML = `
🕋 مراقب نسك
جاري تشغيل المراقبة...
${monitoring ? '⏸ إيقاف' : '▶ تشغيل'}
🔔 اختبار
آخر فحص: --
`;
document.body.appendChild(panel);
const style = document.createElement('style');
style.textContent = `
#nusuk-monitor-box {
position: fixed;
z-index: 999999999;
left: 15px;
bottom: 15px;
width: 260px;
background: #111;
color: #fff;
padding: 15px;
border-radius: 15px;
box-shadow: 0 5px 30px rgba(0,0,0,.45);
font-family: Arial,sans-serif;
direction: rtl;
}
#nm-title {
font-size: 19px;
font-weight: bold;
margin-bottom: 10px;
}
#nm-status {
background: #222;
padding: 9px;
border-radius: 8px;
margin-bottom: 10px;
font-size: 13px;
}
.nm-row {
display: flex;
gap: 7px;
}
.nm-row button {
flex: 1;
border: 0;
padding: 9px;
border-radius: 8px;
cursor: pointer;
font-weight: bold;
}
#nm-toggle {
background: #eee;
color: #111;
}
#nm-test {
background: #444;
color: #fff;
}
#nm-last {
margin-top: 9px;
font-size: 11px;
color: #aaa;
}
.nusuk-available-alert {
position: fixed;
z-index: 9999999999;
inset: 0;
background: rgba(0,0,0,.82);
display: flex;
align-items: center;
justify-content: center;
direction: rtl;
}
.nusuk-available-card {
background: white;
color: #111;
width: min(90%,420px);
padding: 30px;
border-radius: 20px;
text-align: center;
box-shadow: 0 0 50px rgba(255,255,255,.25);
}
.nusuk-available-card h1 {
margin-top: 0;
}
.nusuk-available-card button {
border: 0;
padding: 13px 25px;
border-radius: 10px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
}
`;
document.head.appendChild(style);
const status = document.getElementById('nm-status');
const last = document.getElementById('nm-last');
const toggle = document.getElementById('nm-toggle');
// =========================
// الأصوات
// =========================
function beep() {
try {
const ctx = new (
window.AudioContext ||
window.webkitAudioContext
)();
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain);
gain.connect(ctx.destination);
osc.frequency.value = 900;
gain.gain.value = 0.2;
osc.start();
setTimeout(() => {
osc.frequency.value = 1300;
}, 180);
setTimeout(() => {
osc.stop();
ctx.close();
}, 500);
} catch (e) {
console.log('Audio error', e);
}
}
// =========================
// إشعار المتصفح
// =========================
function notify() {
if (!CONFIG.notification) return;
try {
GM_notification({
title: '🕋 نسك',
text: 'قد يكون هناك موعد متاح الآن. افتح صفحة الحجز وتحقق.',
timeout: 15000,
onclick: () => window.focus()
});
} catch (e) {
console.log(e);
}
}
// =========================
// شاشة التنبيه
// =========================
function showAlert() {
if (document.querySelector('.nusuk-available-alert'))
return;
const box = document.createElement('div');
box.className = 'nusuk-available-alert';
box.innerHTML = `
🕋 ظهر احتمال توفر موعد!
تحقق من صفحة نسك الآن وأكمل الحجز بالطريقة الرسمية.
فتح الصفحة
`;
document.body.appendChild(box);
box.querySelector('#nm-close').onclick = () => {
box.remove();
window.focus();
};
// صوت متكرر
beep();
setTimeout(beep, 700);
setTimeout(beep, 1400);
notify();
}
// =========================
// اكتشاف توفر الموعد
// =========================
function detectAvailability() {
const text = document.body.innerText
.replace(/\s+/g, ' ')
.toLowerCase();
/*
* كلمات تشير عادة إلى عدم وجود موعد
*/
const unavailableWords = [
'لا يوجد مواعيد',
'لا توجد مواعيد',
'غير متاح',
'لا يوجد توفر',
'fully booked',
'no availability',
'no slots',
'not available'
];
/*
* كلمات تشير إلى وجود موعد/خيار للحجز
*/
const availableWords = [
'متاح',
'حجز',
'احجز',
'book',
'available',
'reservation',
'reserve',
'slots available'
];
const unavailable = unavailableWords.some(word =>
text.includes(word)
);
const available = availableWords.some(word =>
text.includes(word)
);
/*
* لا نعتبر كلمة واحدة كافية إذا كانت الصفحة
* تحتوي فقط على زر عام.
*
* الهدف هنا إعطاء تنبيه يحتاج تحققًا يدويًا.
*/
if (!unavailable && available) {
return true;
}
return false;
}
// =========================
// الفحص
// =========================
function checkPage() {
if (!monitoring)
return;
const now = new Date();
last.textContent =
'آخر فحص: ' +
now.toLocaleTimeString('ar-SA');
status.textContent =
'🔎 جاري فحص الصفحة...';
try {
const found = detectAvailability();
if (found && !lastAvailable) {
lastAvailable = true;
status.textContent =
'🚨 تحقق من الموعد الآن!';
showAlert();
} else if (!found) {
lastAvailable = false;
status.textContent =
'🟢 المراقبة تعمل — لا يوجد تأكيد توفر';
}
} catch (error) {
status.textContent =
'⚠️ حدث خطأ أثناء الفحص';
console.error(error);
}
}
// =========================
// التشغيل / الإيقاف
// =========================
toggle.onclick = () => {
monitoring = !monitoring;
GM_setValue(
'nusuk_monitoring',
monitoring
);
toggle.textContent =
monitoring ? '⏸ إيقاف' : '▶ تشغيل';
status.textContent =
monitoring
? '🟢 المراقبة تعمل'
: '⏸ المراقبة متوقفة';
if (monitoring)
checkPage();
};
// =========================
// اختبار التنبيه
// =========================
document.getElementById('nm-test').onclick = () => {
showAlert();
};
// =========================
// تمرير تلقائي اختياري
// =========================
if (CONFIG.autoScroll) {
let direction = 1;
setInterval(() => {
if (!monitoring)
return;
window.scrollBy({
top: direction * 250,
behavior: 'smooth'
});
if (
window.innerHeight +
window.scrollY >=
document.body.scrollHeight - 100
) {
direction = -1;
}
if (window.scrollY <= 0) {
direction = 1;
}
}, 3000);
}
// =========================
// بدء المراقبة
// =========================
setTimeout(() => {
checkPage();
setInterval(
checkPage,
CONFIG.interval
);
}, 2500);
})();
تعليقات
إرسال تعليق